How to connect an API Gateway to Lambda in CloudFormation
To connect an API Gateway to a Lambda function using CloudFormation, you can follow these steps:
Define your API Gateway and Lambda function resources in your CloudFormation template. Here’s an example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Resources: MyLambdaFunction: Type: AWS::Lambda::Function Properties: FunctionName: MyLambdaFunction Runtime: python3.8 Handler: index.handler Code: S3Bucket: my-lambda-code-bucket S3Key: lambda-code.zip MyApiGateway: Type: AWS::ApiGateway::RestApi Properties: Name: MyApiGateway Create a resource of type AWS::ApiGateway::Resource to define the resource path for your API Gateway: 1 2 3 4 5 6 MyApiGatewayResource: Type: AWS::ApiGateway::Resource Properties: RestApiId: !