SQS-triggered Function

A Lambda function that is triggered by incoming messages from SQS queue.
The example below illustrates the deployment of an event-driven solution using SQS and Lambda function. Each time a new message is added to the queue, the Lambda function is invoked automatically to process it.
To simplify the deployment, this guide uses BYM's Terraform modules setup terraform-byks-module which provision the necessary IAM roles and permissions while handling the majority of the underlying configuration with predefined defaults.
components:
- SQS queue
- Lambda function
- SNS subscription (optional)
├──application-name/
├── byks_application_name.tf
lambda_functions {}
sqs_queue {}
└── locals.tf
Step 1: The Lambda Function
Add the following lambda_functions section to the byks_kattehotell.tf file.
locals.tf file inside kattehotell_add_visitor_environment_variables section.
Step 2: The SQS Queue
Update the byks_kattehotell.tf file by adding sqs_queuessection.
| byks_kattehotell.tf | |
|---|---|
Step 3: The SQS trigger inside the Lambda function
Add sqs_triggers block inside the lambda_functions section in the byks_kattehotell.tf file.
| byks_kattehotell.tf | |
|---|---|
Step 4: SNS Subscription (Optional)
Update the byks_kattehotell.tf file by adding sns_topicssection.
| byks_kattehotell.tf | |
|---|---|
Result:
Incoming message to the test-kattehotell-new-visitor SQS queue triggeres kattehotell-add-visitor-test Lambda function for a new deployment.