Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AvinashDalvi89/6a72a378c8709e0773a688f00c6927c4 to your computer and use it in GitHub Desktop.
Save AvinashDalvi89/6a72a378c8709e0773a688f00c6927c4 to your computer and use it in GitHub Desktop.
This is for creating AWS API gateway using multiple stages along with lambda integration
AWSTemplateFormatVersion: '2010-09-09'
Resources:
LambdaApiGatewayRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
ApiKeySourceType: HEADER
Description: An API Gateway with a Lambda Integration
EndpointConfiguration:
Types:
- EDGE
Name: lambda-api
LambdaApiGatewayResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId: !GetAtt LambdaApiGatewayRestApi.RootResourceId
PathPart: 'lambda'
RestApiId: !Ref LambdaApiGatewayRestApi
LambdaApiGatewayMethod:
Type: AWS::ApiGateway::Method
Properties:
ApiKeyRequired: false
AuthorizationType: NONE
HttpMethod: POST
Integration:
ConnectionType: INTERNET
Credentials: !GetAtt LambdaApiGatewayIamRole.Arn
IntegrationHttpMethod: POST
PassthroughBehavior: WHEN_NO_MATCH
TimeoutInMillis: 29000
Type: AWS_PROXY
Uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:{ACCOUNT_ID}:function:list_s3_files/invocations'
OperationName: 'lambda'
ResourceId: !Ref LambdaApiGatewayResource
RestApiId: !Ref LambdaApiGatewayRestApi
LambdaApiGatewayModel:
Type: AWS::ApiGateway::Model
Properties:
ContentType: 'application/json'
RestApiId: !Ref LambdaApiGatewayRestApi
Schema: {}
LambdaApiGatewayStage:
Type: AWS::ApiGateway::Stage
Properties:
DeploymentId: !Ref LambdaApiGatewayDeployment
Description: Lambda API Stage Stage
RestApiId: !Ref LambdaApiGatewayRestApi
StageName: 'Stage'
LambdaApiGatewayProd:
Type: AWS::ApiGateway::Stage
Properties:
DeploymentId: !Ref LambdaApiGatewayDeployment
Description: Lambda API Stage Prod
RestApiId: !Ref LambdaApiGatewayRestApi
StageName: 'Prod'
LambdaApiGatewayDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn: LambdaApiGatewayMethod
Properties:
Description: Lambda API Deployment
RestApiId: !Ref LambdaApiGatewayRestApi
LambdaApiGatewayIamRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: ''
Effect: 'Allow'
Principal:
Service:
- 'apigateway.amazonaws.com'
Action:
- 'sts:AssumeRole'
Path: '/'
Policies:
- PolicyName: LambdaAccess
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Action: 'lambda:*'
Resource: 'arn:aws:lambda:us-east-1:{ACCOUNT_ID}:function:list_s3_files'
#{ACCOUNT_ID} - you can replace with your account id of aws account
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment