AWS CDK SQS

1.204.0 · active · verified Thu Apr 16

The `aws-cdk-aws-sqs` library provides AWS Cloud Development Kit (CDK) constructs for defining Amazon SQS (Simple Queue Service) resources in your AWS infrastructure as code. As part of the AWS CDK v1 ecosystem, it allows developers to programmatically create and configure SQS queues, dead-letter queues, and related settings using familiar programming languages. The AWS CDK project releases frequently, often with minor version updates every few weeks for both v1 and v2 lines.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a basic Amazon SQS queue using the `aws-cdk-aws-sqs` library. It creates an `App` and a `Stack`, then instantiates an `sqs.Queue` with a specified visibility timeout and outputs its URL. Ensure your AWS credentials are configured in your environment or `~/.aws/credentials` for successful deployment (`cdk deploy`).

import aws_cdk as cdk
import aws_cdk.aws_sqs as sqs
import os

class MySqsStack(cdk.Stack):
    def __init__(self, scope: cdk.App, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Define an SQS Queue
        queue = sqs.Queue(
            self, "MySimpleQueue",
            visibility_timeout=cdk.Duration.seconds(300),
            queue_name="MyApplicationQueue" # Optional: give it a specific name
        )

        # Output the queue URL
        cdk.CfnOutput(
            self, "QueueUrl",
            value=queue.queue_url,
            description="The URL of the SQS queue",
        )

# For authentication, CDK usually relies on AWS CLI configuration 
# or environment variables (e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION).
# No explicit auth needed in code for basic synth.
app = cdk.App()
MySqsStack(app, "MySqsQueueStack",
            env=cdk.Environment(
                account=os.environ.get("CDK_DEFAULT_ACCOUNT"),
                region=os.environ.get("CDK_DEFAULT_REGION")
            )
        )
app.synth()

view raw JSON →