aws-apigateway-lambda - AWS Solutions Constructs

aws-apigateway-lambda

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

Language Package
Python
aws_solutions_constructs.aws_apigateway_lambda
Typescript
@aws-solutions-constructs/aws-apigateway-lambda
Java
software.amazon.awsconstructs.services.apigatewaylambda

Overview

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' } });

Initializer

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

Parameters

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 pattern that enables access logging from the API Gateway REST API to CloudWatch.
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

Architecture

GitHub

To view the code for this pattern, create/view issues and pull requests, and more:
@aws-solutions-constructs/aws-apigateway-lambda