Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@aws-cdk/aws-sqs
Advanced tools
@aws-cdk/aws-sqs is an AWS Cloud Development Kit (CDK) library that allows you to define Amazon Simple Queue Service (SQS) queues in your AWS infrastructure as code. It provides a high-level, object-oriented abstraction to create and manage SQS queues, configure their properties, and integrate them with other AWS services.
Create an SQS Queue
This code sample demonstrates how to create a basic SQS queue with a visibility timeout of 300 seconds using the AWS CDK.
const cdk = require('@aws-cdk/core');
const sqs = require('@aws-cdk/aws-sqs');
class MyStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const queue = new sqs.Queue(this, 'MyQueue', {
visibilityTimeout: cdk.Duration.seconds(300)
});
}
}
const app = new cdk.App();
new MyStack(app, 'MyStack');
Configure Dead-Letter Queue
This code sample shows how to configure a dead-letter queue for an SQS queue. Messages that are not successfully processed after 5 attempts will be moved to the dead-letter queue.
const cdk = require('@aws-cdk/core');
const sqs = require('@aws-cdk/aws-sqs');
class MyStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const deadLetterQueue = new sqs.Queue(this, 'DeadLetterQueue');
const queue = new sqs.Queue(this, 'MyQueue', {
deadLetterQueue: {
queue: deadLetterQueue,
maxReceiveCount: 5
}
});
}
}
const app = new cdk.App();
new MyStack(app, 'MyStack');
Integrate SQS with Lambda
This code sample demonstrates how to integrate an SQS queue with an AWS Lambda function. The Lambda function will be triggered whenever a new message is added to the SQS queue.
const cdk = require('@aws-cdk/core');
const sqs = require('@aws-cdk/aws-sqs');
const lambda = require('@aws-cdk/aws-lambda');
const lambdaEventSources = require('@aws-cdk/aws-lambda-event-sources');
class MyStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const queue = new sqs.Queue(this, 'MyQueue');
const myFunction = new lambda.Function(this, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.Code.fromAsset('lambda')
});
myFunction.addEventSource(new lambdaEventSources.SqsEventSource(queue));
}
}
const app = new cdk.App();
new MyStack(app, 'MyStack');
The aws-sdk package is the official AWS SDK for JavaScript. It provides low-level APIs for interacting with all AWS services, including SQS. Unlike @aws-cdk/aws-sqs, which is used for defining infrastructure as code, aws-sdk is used for making API calls to AWS services from your application code.
The serverless framework is a popular open-source framework for building and deploying serverless applications. It supports AWS SQS as an event source for AWS Lambda functions. While @aws-cdk/aws-sqs focuses on infrastructure as code, serverless provides a higher-level abstraction for deploying serverless applications, including SQS integration.
Pulumi is an infrastructure as code tool that supports multiple cloud providers, including AWS. It allows you to define and manage AWS SQS queues using familiar programming languages. Pulumi is similar to AWS CDK in that it provides a high-level, object-oriented abstraction for defining cloud infrastructure.
Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications. SQS eliminates the complexity and overhead associated with managing and operating message oriented middleware, and empowers developers to focus on differentiating work. Using SQS, you can send, store, and receive messages between software components at any volume, without losing messages or requiring other services to be available.
Import to your project:
import * as sqs from '@aws-cdk/aws-sqs';
Here's how to add a basic queue to your application:
new sqs.Queue(this, 'Queue');
If you want to encrypt the queue contents, set the encryption
property. You can have
the messages encrypted with a key that SQS manages for you, or a key that you
can manage yourself.
// Use managed key
new sqs.Queue(this, 'Queue', {
encryption: sqs.QueueEncryption.KMS_MANAGED,
});
// Use custom key
const myKey = new kms.Key(this, 'Key');
new sqs.Queue(this, 'Queue', {
encryption: sqs.QueueEncryption.KMS,
encryptionMasterKey: myKey,
});
FIFO queues give guarantees on the order in which messages are dequeued, and have additional features in order to help guarantee exactly-once processing. For more information, see the SQS manual. Note that FIFO queues are not available in all AWS regions.
A queue can be made a FIFO queue by either setting fifo: true
, giving it a name which ends
in ".fifo"
, or by enabling a FIFO specific feature such as: content-based deduplication,
deduplication scope or fifo throughput limit.
1.150.0 (2022-03-26)
StepFunctionsIntegration
does not create required role and responses (#19486) (d59bee9).gitignore
(#19482) (5ce0983)Invoke
with Qualifier
authorization strategy (#19318) (d06b27f), closes #19273FAQs
The CDK Construct Library for AWS::SQS
The npm package @aws-cdk/aws-sqs receives a total of 77,139 weekly downloads. As such, @aws-cdk/aws-sqs popularity was classified as popular.
We found that @aws-cdk/aws-sqs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.