This guide explains how to deploy an API using AWS API Gateway integrated with AWS Lambda. This setup is ideal for serverless applications with low latency and scalability.
Use the createApiLambdaStack method to define your Lambda function and API Gateway integration. Specify runtime,
handler, and configurations.
Example:
const lambdaExportProps: ApiLambdaStackProps = {
env: { account: "425287461358", region: "eu-west-1" },
name: "ApiLambda",
githubRepo: "cdk-intro-workshop",
stackName: "cdk-intro-workshop-ApiLambda",
pathDockerFile: "./workshop/src/apps/Minimal.Api/",
dockerFile: "Dockerfile",
envName: "Production",
functionName: "cdk-intro-workshop-api-production",
timeoutSeconds: 29,
memorySizeMbs: 1024,
vpc: { vpcId: "vpc-ee04cd97" },
vpcSubnets: {
subnetType: "PRIVATE_WITH_EGRESS",
},
};
new ApiLambdaStack(this.props.scope, lambdaExportProps);
}Use the createApiGateway method to integrate the Lambda function with API Gateway.
Example:
const apiProps: ApiGatewayStackProps = {
env: { account: "425287461358", region: "eu-west-1" },
name: "ApiGateway",
githubRepo: "cdk-intro-workshop",
stackName: "cdk-intro-workshop-ApiGateway",
envName: "Production",
lambdaFunction: lambdaFunction,
certificateArn: `arn:aws:acm:us-east-1:425287461358:certificate/be63062d-5316-47af-9f94-819c1dc02853`,
subdomain: "api",
domain: "m47.io",
};
return new ApiGatewayStack(this.props.scope, apiProps);
}Use the AWS CDK CLI to deploy the stack.
Command:
cdk deploy cdk-intro-workshop-ApiGatewayBelow is a flowchart visualizing the stack:
flowchart TD
A[API Gateway] --> B[Lambda Function]
B --> C[Docker Image]
C --> D[Runtime Environment]
D --> E[Execution in AWS Lambda]
Before deploying APIs, ensure you understand Lambda Runtime Support (LRS).