3.2.5 Test Event-Driven Applications

Test Event-Driven Applications

Generate Test Events

# SAM generate events
sam local generate-event s3 put --bucket my-bucket --key test.json
sam local generate-event sqs receive-message
sam local generate-event sns notification
sam local generate-event dynamodb update
sam local generate-event eventbridge put-events

Test SQS-triggered Lambda

# Send test message to SQS
aws sqs send-message \
  --queue-url https://sqs.region.amazonaws.com/123/my-queue \
  --message-body '{"orderId": "test-123"}'

# Check DLQ for failures
aws sqs receive-message --queue-url https://sqs.region.amazonaws.com/123/my-dlq

Test EventBridge Rules

# Put test event
aws events put-events --entries '[{
  "Source": "my-app",
  "DetailType": "OrderCreated",
  "Detail": "{\"orderId\": \"test-123\"}",
  "EventBusName": "default"
}]'

Test SNS → SQS Fan-out

# Publish to topic
aws sns publish \
  --topic-arn arn:aws:sns:region:123:my-topic \
  --message '{"test": true}' \
  --message-attributes '{"eventType":{"DataType":"String","StringValue":"test"}}'

Step Functions Testing

  • Console: Start execution with test input
  • CLI: aws stepfunctions start-execution --input '{}'
  • Local testing: Step Functions Local (Docker)

Exam Tip: sam local generate-event for all event types. Test SQS by sending messages directly. Test EventBridge with put-events. Check DLQ for failed messages.