CDK construct that provisions (1) an AWS Lambda function that is configured to send messages to a queue; (2) an Amazon SQS queue; and (3) an AWS Lambda function configured to consume messages from the queue.
Project description
aws-lambda-sqs-lambda module
---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.
Reference Documentation: | https://docs.aws.amazon.com/solutions/latest/constructs/ |
---|
Language | Package |
---|---|
Python | aws_solutions_constructs.aws_lambda_sqs_lambda |
Typescript | @aws-solutions-constructs/aws-lambda-sqs-lambda |
Java | software.amazon.awsconstructs.services.lambdasqslambda |
This AWS Solutions Construct implements (1) an AWS Lambda function that is configured to send messages to a queue; (2) an Amazon SQS queue; and (3) an AWS Lambda function configured to consume messages from the queue.
Here is a minimal deployable pattern definition:
Typescript
import { Construct } from 'constructs';
import { Stack, StackProps } from 'aws-cdk-lib';
import { LambdaToSqsToLambda, LambdaToSqsToLambdaProps } from "@aws-solutions-constructs/aws-lambda-sqs-lambda";
import * as lambda from 'aws-cdk-lib/aws-lambda';
new LambdaToSqsToLambda(this, 'LambdaToSqsToLambdaPattern', {
producerLambdaFunctionProps: {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(`producer-lambda`)
},
consumerLambdaFunctionProps: {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(`consumer-lambda`)
}
});
Python
from aws_solutions_constructs.aws_lambda_sqs_lambda import LambdaToSqsToLambda
from aws_cdk import (
aws_lambda as _lambda,
Stack
)
from constructs import Construct
LambdaToSqsToLambda(
self, 'LambdaToSqsToLambdaPattern',
producer_lambda_function_props=_lambda.FunctionProps(
code=_lambda.Code.from_asset('producer_lambda'),
runtime=_lambda.Runtime.PYTHON_3_9,
handler='index.handler'
),
consumer_lambda_function_props=_lambda.FunctionProps(
code=_lambda.Code.from_asset('consumer_lambda'),
runtime=_lambda.Runtime.PYTHON_3_9,
handler='index.handler'
)
)
Java
import software.constructs.Construct;
import software.amazon.awscdk.Stack;
import software.amazon.awscdk.StackProps;
import software.amazon.awscdk.services.lambda.*;
import software.amazon.awscdk.services.lambda.Runtime;
import software.amazon.awsconstructs.services.lambdasqslambda.*;
new LambdaToSqsToLambda(this, "LambdaToSqsToLambdaPattern", new LambdaToSqsToLambdaProps.Builder()
.producerLambdaFunctionProps(new FunctionProps.Builder()
.runtime(Runtime.NODEJS_14_X)
.code(Code.fromAsset("producer-lambda"))
.handler("index.handler")
.build())
.consumerLambdaFunctionProps(new FunctionProps.Builder()
.runtime(Runtime.NODEJS_14_X)
.code(Code.fromAsset("consumer-lambda"))
.handler("index.handler")
.build())
.build());
Pattern Construct Props
Name | Type | Description |
---|---|---|
existingProducerLambdaObj? | lambda.Function |
An optional, existing Lambda function to be used instead of the default function for sending messages to the queue. Providing both this and producerLambdaFunctionProps will cause an error. |
producerLambdaFunctionProps? | lambda.FunctionProps |
Optional user-provided properties to override the default properties for the producer Lambda function. |
existingQueueObj? | sqs.Queue |
An optional, existing SQS queue to be used instead of the default queue. Providing both this and queueProps will cause an error. |
queueProps? | sqs.QueueProps |
Optional user-provided properties to override the default properties for the SQS queue. Providing both this and existingQueueObj will cause an error. |
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 . |
existingConsumerLambdaObj? | lambda.Function |
An optional, existing Lambda function to be used instead of the default function for receiving/consuming messages from the queue. Providing both this and consumerLambdaFunctionProps will cause an error. |
consumerLambdaFunctionProps? | lambda.FunctionProps |
Optional user-provided properties to override the default properties for the consumer Lambda function. |
queueEnvironmentVariableName? | string |
Optional Name for the SQS queue URL environment variable set for the producer Lambda function. |
sqsEventSourceProps? | SqsEventSourceProps |
Optional user provided properties for the queue event source. |
existingVpc? | ec2.IVpc |
An optional, existing VPC into which this pattern should be deployed. When deployed in 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 . This uses ec2.IVpc to allow clients to supply VPCs that exist outside the stack using the ec2.Vpc.fromLookup() method. |
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 overrriden. If deployVpc is not true then this property will be ignored. |
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:
true then existingVpc cannot be specified. Defaults to false . |
Pattern Properties
Name | Type | Description |
---|---|---|
producerLambdaFunction | lambda.Function |
Returns an instance of the producer Lambda function created by the pattern. |
sqsQueue | sqs.Queue |
Returns an instance of the SQS queue created by the pattern. |
deadLetterQueue? | sqs.Queue | undefined |
Returns an instance of the dead letter queue created by the pattern, if one is deployed. |
consumerLambdaFunction | lambda.Function |
Returns an instance of the consumer Lambda function created by the pattern. |
vpc? | ec2.IVpc |
Returns an interface on the VPC used by the pattern (if any). This may be a VPC created by the pattern or the VPC supplied to the pattern constructor. |
Default Settings
Out-of-the-box implementation of this Construct (without any overridden properties) will adhere to the following defaults:
AWS Lambda Functions
-
Configure limited privilege access IAM role for Lambda functions.
-
Enable reusing connections with Keep-Alive for NodeJs Lambda functions.
-
Enable X-Ray Tracing
-
Set Environment Variables
- AWS_NODEJS_CONNECTION_REUSE_ENABLED (for Node 10.x and higher functions)
Amazon SQS Queue
- Deploy a dead letter queue for the primary queue.
- Enable server-side encryption for the primary queue using an AWS Managed KMS Key.
- Enforce encryption of data in transit
Architecture
© Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aws-solutions-constructs.aws-lambda-sqs-lambda-1.152.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8e7efa99913b190ce750cd88d4bc270af3e7a7c658769622fb3888560892ee5 |
|
MD5 | e2411b4424434a9fe127c463810f51ee |
|
BLAKE2b-256 | 1d387b28e2854f82fb914c7962600e51042b3986f1438b62d10b38b715f6ed90 |
Hashes for aws_solutions_constructs.aws_lambda_sqs_lambda-1.152.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d15f1017479eb93c6802909718418f03ac2f62a7fa13f5fbfcc6a971effb35aa |
|
MD5 | a204f866ba4cb6abf33ffd59280bc36b |
|
BLAKE2b-256 | 1b80588b7c32f1629e656352e655aff16ed5317c8579b03f64962e5df2d84bbd |