How do I build an AWS SQS queue policy?
In this guide, we will create an AWS SQS queue and attach a policy to it using Pulumi. The policy will grant permissions to specific actions on the queue. Pulumi allows us to define, deploy, and manage cloud resources using familiar programming languages.
Key Points:
- Create an SQS queue using Pulumi.
- Define a policy that grants specific permissions.
- Attach the policy to the SQS queue.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create an SQS queue
const queue = new aws.sqs.Queue("myQueue", {
visibilityTimeoutSeconds: 30,
});
// Define the policy for the SQS queue
const queuePolicy = new aws.sqs.QueuePolicy("myQueuePolicy", {
queueUrl: queue.url,
policy: pulumi.interpolate`{
"Version": "2012-10-17",
"Id": "QueuePolicy",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "sqs:SendMessage",
"Resource": "${queue.arn}",
"Condition": {
"ArnEquals": {
"aws:SourceArn": "arn:aws:sns:us-west-2:123456789012:MyTopic"
}
}
}
]
}`,
});
// Export the queue URL and ARN
export const queueUrl = queue.url;
export const queueArn = queue.arn;
Summary
In this example, we created an SQS queue and defined a policy that allows the sqs:SendMessage
action from a specific SNS topic. The policy was then attached to the queue. With Pulumi, managing cloud resources using code becomes seamless and efficient.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.