问题
I am writing SAM templates and I want to create an API Gateway with the path as follows:-
http:///userFlights/airlines/static/images/{airlineName}.
This should be able to download the file from S3 bucket. The {airlineName} may have value like IndiGo.jpg.
I am able to create this manually. Nevertheless, the problem is I am not able to find the appropriate Documentation for SAM templates. I need to automate my API Gateway with SAM.
The values are as follows:- Integration type - AWS Service
AWS Region- eu-west-3
AWS Service - Simple Storage Service (S3
Http Method - GET
Path override- airlines/static/images/{airlineName}
回答1:
You have to make use of an OpenAPI definition using DefinitionBody in your SAM template that defines the API configuration. Check out the S3 proxy example here. I have built an API with the simplest and minimum Swagger definition and deployed via SAM.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS SAM template with a S3 integration
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
DefinitionBody: {
"swagger": "2.0",
"info": {
"version": "1.0"
},
"paths": {
"/airlines/static/images/{airlineName}": {
"get": {
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "200 response"
}
},
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200"
}
},
"credentials": "arn:aws:iam::{account-id}:role/{role-name}",
"uri": "arn:aws:apigateway:{aws-region}:s3:path/{bucket-name}",
"passthroughBehavior": "when_no_match",
"httpMethod": "GET",
"type": "aws"
}
}
}
}
}
来源:https://stackoverflow.com/questions/60488172/sam-template-for-aws-api-gateway-integration-with-s3-as-aws-service