Table of Contents
ToggleIntroduction.
In today’s cloud-native environments, building scalable, event-driven architectures is not just a trend—it’s a necessity. Amazon Web Services (AWS) offers a robust suite of services that help developers create highly decoupled systems, and at the heart of this ecosystem are services like Amazon Simple Queue Service (SQS), AWS Lambda, and Amazon CloudWatch. Together, they provide a powerful combination for handling asynchronous communication, automated processing, and centralized logging.
Whether you’re building a microservices application, processing background jobs, or handling workloads that require resilience and fault tolerance, SQS plays a critical role in decoupling components and ensuring messages are not lost even during service disruptions. But SQS by itself is just the messaging layer—it doesn’t perform any actions on the messages it receives. That’s where AWS Lambda comes into play.
Lambda allows you to execute code in response to events without managing servers. By connecting SQS to Lambda, you can automatically trigger business logic as soon as a message arrives in the queue. But automation and processing are only part of the story—monitoring is just as important. That’s where Amazon CloudWatch Logs becomes essential. Logging SQS messages or their processing status helps in debugging, monitoring, and auditing your applications.
In this tutorial, we’ll walk through how to create a complete pipeline that connects SQS to Lambda and logs every incoming message to CloudWatch. This setup is crucial for real-world applications where traceability and visibility into asynchronous workflows are vital. We’ll not only set up each component, but also show you how to verify everything is working correctly with sample messages and log output.
No prior experience with these services? No problem. We’ll break down each step clearly, explain key concepts along the way, and make sure you understand what’s happening under the hood. Whether you’re a developer trying this setup for the first time or a DevOps engineer looking to automate logging in a distributed system, this guide will help you connect the dots.
By the end, you’ll have a functioning Lambda function that listens to your SQS queue, processes each message, and logs it in CloudWatch—automatically and reliably. You’ll also gain insights into best practices for permissions, message formats, and error handling.
So, let’s get started on building a lightweight yet powerful event-driven pipeline using AWS SQS, Lambda, and CloudWatch Logs.
Step 1: Create an SQS Queue
- Go to the AWS Management Console → Amazon SQS.
- Click Create queue.
- Choose either Standard or FIFO, then click Configure queue.
- Set your queue name (e.g.,
MySQSQueue
). - Leave other settings as default or customize as needed.
- Click Create Queue.







Step 2: Create a Lambda Function
- Go to AWS Lambda in the Console.
- Click Create function.
- Choose:
- Author from scratch
- Function name:
SQSMessageLogger
- Runtime: Python 3.x, Node.js, etc.
- Click Create Function.



Step 3: Add SQS as a Trigger to the Lambda
- On the Lambda function page, scroll to Function overview.
- Click + Add trigger.
- Choose SQS.
- Select the queue you created (
MySQSQueue
). - Click Add.
- IAM permissions: Lambda will automatically attach an IAM policy allowing it to poll the queue.
Step 4: Add Code to Log Messages to CloudWatch
Example (Python):
import json
def lambda_handler(event, context):
for record in event['Records']:
print("Received message:")
print(json.dumps(record))
return {"statusCode": 200}
Step 5: Test the Setup
- Go to the SQS Queue.
- Click Send and receive messages.
- Send a test message (e.g., body:
{"key":"value"}
). - Go to CloudWatch Logs → Log groups.
- Look for
/aws/lambda/SQSMessageLogger
. - Open the latest log stream and confirm the message appears.
Conclusion.
In conclusion, integrating Amazon SQS with AWS Lambda and logging events to Amazon CloudWatch Logs is a powerful way to build scalable, observable, and serverless applications. This setup allows you to decouple components, automate message processing, and maintain full visibility into the flow and behavior of your system—all without provisioning or managing servers. By simply connecting your queue to a Lambda function and using built-in logging, you gain real-time insights into how your messages are handled, making it easier to debug issues, monitor performance, and ensure reliability. Whether you’re processing user signups, order confirmations, IoT sensor data, or background tasks, this architecture lays a solid foundation for building event-driven workflows in the cloud. With just a few steps, you’ve enabled your application to listen, respond, and report—all with minimal infrastructure overhead. Now that you’ve completed this integration, you’re ready to scale your solution further, implement alerting, or even extend the pipeline with more sophisticated workflows.