Skip to content

Latest commit

 

History

History
60 lines (41 loc) · 1.54 KB

File metadata and controls

60 lines (41 loc) · 1.54 KB

Lambda: Process SQS messages

Create a Lambda function that processes messages from an Amazon SQS queue, with event source mapping for automatic invocation.

Source

https://docs.aws.amazon.com/lambda/latest/dg/with-sqs-example.html

Use case

  • ID: lambda/sqs-trigger
  • Phase: create
  • Complexity: beginner
  • Core actions: lambda:CreateFunction, lambda:CreateEventSourceMapping, sqs:SendMessage

What it does

  1. Creates an IAM execution role with SQS permissions
  2. Creates a Node.js Lambda function that logs message bodies
  3. Tests the function with a sample SQS event
  4. Creates an SQS queue
  5. Creates an event source mapping (queue → function)
  6. Sends test messages to the queue
  7. Verifies processing via CloudWatch Logs
  8. Cleans up all resources

Running

bash lambda-sqs.sh

To auto-run with cleanup:

echo 'y' | bash lambda-sqs.sh

Resources created

  • IAM role (with AWSLambdaSQSQueueExecutionRole policy)
  • Lambda function (Node.js 22)
  • SQS queue
  • Event source mapping
  • CloudWatch log group (created automatically by Lambda)

Estimated time

  • Run: ~45 seconds
  • Cleanup: ~10 seconds

Cost

Free tier eligible. No charges expected for a few messages.

Related docs