Cloud formation template to create a Lambda proxy integration via ApiGateway. Lambda ARN should be provided, permission to invoke Lambda by ApiGateway is done in the template
Parameters:
VPCId:
Type: String
Default: vpc-2785cc5d
VPCEndpointId:
Type: String
Default: vpce-0c10a3cb8a0379f5f
LambdaArn:
Type: String
Default: arn:aws:lambda:us-east-1:597487947530:function:rest
Resources:
RestApi:
Type: AWS::ApiGateway::RestApi
Properties:
EndpointConfiguration:
Types:
- REGIONAL
Name: testApi
Policy: !Sub |
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "execute-api:/*"
}
]
}
MockMethod:
Type: AWS::ApiGateway::Method
Properties:
RestApiId: !Ref RestApi
ResourceId: !GetAtt RestApi.RootResourceId
HttpMethod: POST
AuthorizationType: NONE
Integration:
Type: AWS_PROXY
IntegrationHttpMethod: POST
Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaArn}/invocations
IntegrationResponses:
- StatusCode: 200
PassthroughBehavior: WHEN_NO_MATCH
Deployment:
Type: AWS::ApiGateway::Deployment
DependsOn: MockMethod
Properties:
RestApiId: !Ref RestApi
Description: VPC endpoint test
StageName: test
InvokePermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref LambdaArn
Principal: "apigateway.amazonaws.com"
SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/POST/"