aws-lambda-sqs - AWS Solutions Constructs


All classes are under active development and subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.

Language Package

This AWS Solutions Construct implements an AWS Lambda function connected to an Amazon SQS queue.

Here is a minimal deployable pattern definition in TypeScript:

import { LambdaToSqs, LambdaToSqsProps } from "@aws-solutions-constructs/aws-lambda-sqs"; new LambdaToSqs(this, 'LambdaToSqsPattern', { lambdaFunctionProps: { runtime: lambda.Runtime.NODEJS_12_X, handler: 'index.handler', code: lambda.Code.fromAsset(`${__dirname}/lambda`) } });


new LambdaToSqs(scope: Construct, id: string, props: LambdaToSqsProps);


Pattern Construct Props

Name Type Description
existingLambdaObj? lambda.Function An optional, existing Lambda function to be used instead of the default function. If an existing function is provided, the lambdaFunctionProps property will be ignored.
lambdaFunctionProps? lambda.FunctionProps Optional user-provided properties to override the default properties for the Lambda function. Ignored if an existingLambdaObj is provided.
existingQueueObj? sqs.Queue An optional, existing SQS queue to be used instead of the default queue. If an existing queue is provided, the queueProps property will be ignored.
queueProps? sqs.QueueProps Optional user-provided properties to override the default properties for the SQS queue. Ignored if an existingQueueObj is provided.
enableQueuePurging? boolean Whether to grant additional permissions to the Lambda function enabling it to purge the SQS queue. Defaults to false.
deployDeadLetterQueue? boolean Whether to create a secondary queue to be used as a dead letter queue. Defaults to true.
deadLetterQueueProps? sqs.QueueProps Optional user-provided props to override the default props for the dead letter queue. Only used if the deployDeadLetterQueue property is set to true.
maxReceiveCount? number The number of times a message can be unsuccessfully dequeued before being moved to the dead letter queue. Defaults to 15.
existingVpc? ec2.IVpc An optional, existing VPC into which this pattern should be deployed. When deployed into a VPC, the Lambda function will use ENIs in the VPC to access network resources and an Interface Endpoint will be created in the VPC for Amazon SQS. If an existing VPC is provided, the deployVpc property cannot be true. An ec2.IVpc is used to allow clients to supply VPCs that exist outside the stack using the ec2.Vpc.fromLookup() method.
deployVpc? boolean Whether to create a new VPC based on vpcProps into which to deploy this pattern. Setting this to true will deploy the minimal, most private VPC to run the pattern:
  • One isolated subnet in each Availability Zone used by the CDK program

  • enableDnsHostnames and enableDnsSupport will both be set to true

If this property is true, then existingVpc cannot be specified. Defaults to false.
vpcProps? ec2.VpcProps Optional user-provided properties to override the default properties for the new VPC. enableDnsHostnames, enableDnsSupport, natGateways, and subnetConfiguration are set by the pattern, so any values for those properties supplied here will be overridden. If deployVpc is not true, then this property will be ignored.

Pattern Properties

Name Type Description
deadLetterQueue? sqs.Queue Returns an instance of the dead letter queue created by the pattern, if one is deployed.
lambdaFunction lambda.Function Returns an instance of the Lambda function created by the pattern.
sqsQueue sqs.Queue Returns an instance of the SQS queue created by the pattern.
vpc? ec2.IVpc Returns an instance of the VPC created or used by the pattern (if any). This may be a VPC created by the pattern or a VPC supplied to the pattern constructor.

Default settings

Out of the box implementation of the Construct without any override will set the following defaults:

AWS Lambda Function

  • Configure limited privilege access IAM role for Lambda function.

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

  • Allow the function to only send messages to the queue (purging can be enabled using the enableQueuePurge property).

  • Enable X-Ray tracing

  • Set environment variables:


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

Amazon SQS Queue

  • Deploy SQS dead-letter queue for the source SQS Queue.

  • Enable server-side encryption for source SQS Queue using AWS Managed KMS Key.

  • Enforce encryption of data in transit.



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