--- AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Parameters: StageName: Type: String Default: Prod Description: AWS SAM template with API defined in an external Swagger file along with Lambda integrations and CORS configurations Resources: ApiGatewayApi: Type: AWS::Serverless::Api Properties: StageName: !Ref StageName Variables: LambdaFunctionName: !Ref LambdaFunction DefinitionBody: swagger: "2.0" basePath: /Prod info: title: !Ref AWS::StackName version: "1.0" schemes: - https paths: /: x-amazon-apigateway-any-method: produces: - application/json responses: '200': description: 200 response schema: $ref: "#/definitions/Empty" x-amazon-apigateway-integration: responses: default: statusCode: 200 uri: !Join - '' - - 'arn:aws:apigateway:' - !Ref AWS::Region - ':lambda:path/2015-03-31/functions/arn:aws:lambda:' - !Ref AWS::Region - ':' - !Ref AWS::AccountId - ':' - 'function:' - !Ref LambdaFunction - '/invocations' passthroughBehavior: when_no_match httpMethod: POST type: aws_proxy options: consumes: - application/json produces: - application/json responses: '200': description: 200 response schema: $ref: "#/definitions/Empty" headers: Access-Control-Allow-Origin: type: string Access-Control-Allow-Methods: type: string Access-Control-Allow-Headers: type: string x-amazon-apigateway-integration: responses: default: statusCode: 200 responseParameters: method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'" method.response.header.Access-Control-Allow-Origin: "'*'" passthroughBehavior: when_no_match requestTemplates: application/json: "{\"statusCode\": 200}" type: mock /{proxy+}: x-amazon-apigateway-any-method: produces: - application/json parameters: - name: proxy in: path required: true type: string responses: {} x-amazon-apigateway-integration: uri: !Join - '' - - 'arn:aws:apigateway:' - !Ref AWS::Region - ':lambda:path/2015-03-31/functions/arn:aws:lambda:' - !Ref AWS::Region - ':' - !Ref AWS::AccountId - ':' - 'function:' - !Ref LambdaFunction - '/invocations' httpMethod: POST type: aws_proxy options: consumes: - application/json produces: - application/json responses: '200': description: 200 response schema: $ref: "#/definitions/Empty" headers: Access-Control-Allow-Origin: type: string Access-Control-Allow-Methods: type: string Access-Control-Allow-Headers: type: string x-amazon-apigateway-integration: responses: default: statusCode: 200 responseParameters: method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'" method.response.header.Access-Control-Allow-Origin: "'*'" passthroughBehavior: when_no_match requestTemplates: application/json: "{\"statusCode\": 200}" type: mock definitions: Empty: type: object title: Empty Schema LambdaFunction: Type: AWS::Serverless::Function Properties: CodeUri: . Handler: index.handler Runtime: nodejs6.10 Events: ProxyApiRoot: Type: Api Properties: RestApiId: !Ref ApiGatewayApi Path: / Method: ANY ProxyApiGreedy: Type: Api Properties: RestApiId: !Ref ApiGatewayApi Path: /{proxy+} Method: ANY Outputs: ApiUrl: Description: URL of your API endpoint Value: !Join - '' - - https:// - !Ref ApiGatewayApi - '.execute-api.' - !Ref 'AWS::Region' - '.amazonaws.com/Prod'