Set up SQS queue producer and consumer
✓Works with OpenClaudeYou are an AWS cloud engineer. The user wants to set up a complete SQS queue producer and consumer using AWS SDK for JavaScript.
What to check first
- Ensure AWS SDK v3 (
@aws-sdk/client-sqs) is installed:npm list @aws-sdk/client-sqs - Verify AWS credentials are configured:
aws sts get-caller-identity - Check that the IAM user has
sqs:SendMessage,sqs:ReceiveMessage,sqs:DeleteMessagepermissions
Steps
- Install the AWS SDK v3 SQS client:
npm install @aws-sdk/client-sqs - Create an SQS queue via AWS Console or CLI, note the Queue URL (format:
https://sqs.region.amazonaws.com/account-id/queue-name) - Initialize the
SQSClientwith your region in both producer and consumer files - For the producer, use
SendMessageCommandwith the queue URL and message body as a string - For the consumer, use
ReceiveMessageCommandwithMaxNumberOfMessages: 1andWaitTimeSeconds: 20for long polling - After processing, delete the message using
DeleteMessageCommandwith theReceiptHandlefrom the received message - Implement error handling for network timeouts and invalid queue URLs
- Set up a polling loop in the consumer to continuously check for messages or use event-driven architecture
Code
// producer.js
const { SQSClient, SendMessageCommand } = require('@aws-sdk/client-sqs');
const sqsClient = new SQSClient({ region: 'us-east-1' });
const QUEUE_URL = 'https://sqs.us-east-1.amazonaws.com/123456789012/my-queue';
async function sendMessage(messageBody) {
try {
const command = new SendMessageCommand({
QueueUrl: QUEUE_URL,
MessageBody: JSON.stringify(messageBody),
DelaySeconds: 0, // Send immediately
});
const response = await sqsClient.send(command);
console.log('Message sent:', response.MessageId);
return response.MessageId;
} catch (error) {
console.error('Error sending message:', error);
throw error;
}
}
// consumer.js
const { SQSClient, ReceiveMessageCommand, DeleteMessageCommand } = require('@aws-sdk/client-sqs');
const sqsClient = new SQSClient({ region: 'us-east-1' });
const QUEUE_URL = 'https://sqs.us-east-1.amazonaws.com/123456789012/my-queue';
async function processMessages() {
try {
const command = new ReceiveMessageCommand({
QueueUrl: QUEUE_URL,
MaxNumberOfMessages: 1,
WaitTimeSeconds
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Cloud (AWS/GCP/Azure) Skills
Other Claude Code skills in the same category — free to download.
Lambda Function
Create AWS Lambda function with handler
S3 Operations
Set up S3 bucket operations (upload, download, presigned URLs)
DynamoDB CRUD
Create DynamoDB CRUD operations
SNS Notifications
Configure SNS for push notifications
CloudFront Setup
Set up CloudFront CDN distribution
Cognito Auth
Implement AWS Cognito authentication
RDS Setup
Configure RDS database connection
ECS Task Definition
Create ECS task definitions
Want a Cloud (AWS/GCP/Azure) skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.