aws-apigateway-lambda - AWS Solutions Constructs


Note: To ensure proper functionality, the AWS Solutions Constructs packages and AWS CDK packages in your project must be the same version.

Language Package


This AWS Solutions Construct implements an Amazon API Gateway REST API connected to an AWS Lambda function.

Here is a minimal deployable pattern definition in TypeScript:

import { ApiGatewayToLambda } from '@aws-solutions-constructs/aws-apigateway-lambda'; new ApiGatewayToLambda(this, 'ApiGatewayToLambdaPattern', { lambdaFunctionProps: { runtime: lambda.Runtime.NODEJS_14_X, // This assumes a handler function in lib/lambda/index.js code: lambda.Code.fromAsset(`${__dirname}/lambda`), handler: 'index.handler' } });


new ApiGatewayToLambda(scope: Construct, id: string, props: ApiGatewayToLambdaProps);


Pattern Construct Props

Name Type Description
existingLambdaObj? lambda.Function Existing instance of Lambda Function object, providing both this and lambdaFunctionProps will cause an error.
lambdaFunctionProps? lambda.FunctionProps Optional user-provided properties to override the default properties for the Lambda function. Ignored if an existingLambdaObj is provided.
apiGatewayProps? api.LambdaRestApiProps Optional user-provided props to override the default props for the API.
logGroupProps? logs.LogGroupProps Optional user-provided props to override the default props for the CloudWatch Logs log group.

Pattern Properties

Name Type Description
apiGatewayCloudWatchRole? iam.Role Returns an instance of the iam.Role created by the construct for API Gateway for CloudWatch access.
apiGatewayLogGroup logs.LogGroup Returns an instance of the log group created by the pattern that API Gateway REST API access logs are sent to.
lambdaFunction lambda.Function Returns an instance of the Lambda function created by the pattern.
apiGateway api.LambdaRestApi Returns an instance of the API Gateway REST API created by the pattern.

Default settings

Out-of-the-box implementation of this pattern without any overrides will set the following defaults:

Amazon API Gateway

  • Deploy an edge-optimized API endpoint

  • Enable CloudWatch logging for API Gateway

  • Configure least privilege access IAM role for API Gateway

  • Set the default authorizationType for all API methods to IAM

  • Enable X-Ray tracing

  • Set environment variables:

    • AWS_NODEJS_CONNECTION_REUSE_ENABLED (for Node 10.x and higher functions)

AWS Lambda Function

  • Configure limited privilege access IAM role for Lambda function

  • Enable reusing connections with Keep-Alive for NodeJs Lambda function

  • Enable X-Ray tracing



To view the code for this pattern, create/view issues and pull requests, and more: