This AWS sample demonstrates how the maximum concurrency configuration for SQS as an event source helps control the Lambda function concurrency. This SAM template defines two Lambda functions and two SQS queues - one with maximum concurrency set to 5, another with reserved concurrency set to 5. By sending the same traffic to the SQS queue, users can observe the difference in how Lambda processes the SQS messages through the provided CloudWatch dashboards. You can read more about this feature in AWS documentation and or in this blog
Running this demo requires the AWS CLI and the AWS SAM CLI. After installing both CLIs, clone this GitHub repository and navigate to the root of the directory.
git clone https://github.com/aws-samples/aws-lambda-amazon-sqs-max-concurrency
cd aws-lambda-amazon-sqs-max-concurrency
First build your SAM template with the build command to prepare for deployment in your AWS environment.
sam build
Then use the deploy command to deploy the resources in your account.
sam deploy --guided
After walking through the deploy command, you can track the progress through the CLI or by navigating to the AWS CloudFormation page in your AWS console. It will take a few minutes to complete the provisioning of resources.
The deployed Lambda function code simply sleeps for 10 seconds before returning a 200 response. This allows for reaching a high Lambda function concurrency number with only a small number of messages. You can add 25 messages to a queue using the following command.
for i in {1..25}; do aws sqs send-message --queue-url <queue URL> --message-body testing; done
You will need to include your queue URL in the above command. The URLs are available in the Outputs tab in the console, or you can navigate to the SQS console to find the queue URLs.
After sending messages to both queues, click on the dashboard URL available in the Outputs tab to navigate to the CloudWatch dashboard.
Both Lambda functions should have the same number of invocations, and the same concurrent invocations fixed at 5. However, you can see that the ReservedConcurrencyFunction experienced throttling, and messages were sent to the corresponding DLQ, whereas MaxConcurrencyFunction did not.
To remove all the resources created while following this demo, use the delete command and follow the prompts.
sam delete
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.