QueuePolicy

Allows you to set a policy of an SQS Queue while referencing ARN of the queue within the policy.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var queue = new Aws.Sqs.Queue("queue", new Aws.Sqs.QueueArgs
        {
        });
        var test = new Aws.Sqs.QueuePolicy("test", new Aws.Sqs.QueuePolicyArgs
        {
            QueueUrl = queue.Id,
            Policy = queue.Arn.Apply(arn => @$"{{
  ""Version"": ""2012-10-17"",
  ""Id"": ""sqspolicy"",
  ""Statement"": [
    {{
      ""Sid"": ""First"",
      ""Effect"": ""Allow"",
      ""Principal"": ""*"",
      ""Action"": ""sqs:SendMessage"",
      ""Resource"": ""{arn}"",
      ""Condition"": {{
        ""ArnEquals"": {{
          ""aws:SourceArn"": ""{aws_sns_topic.Example.Arn}""
        }}
      }}
    }}
  ]
}}
"),
        });
    }

}
package main

import (
	"fmt"

	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/sqs"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		queue, err := sqs.NewQueue(ctx, "queue", nil)
		if err != nil {
			return err
		}
		_, err = sqs.NewQueuePolicy(ctx, "test", &sqs.QueuePolicyArgs{
			QueueUrl: queue.ID(),
			Policy: queue.Arn.ApplyT(func(arn string) (string, error) {
				return fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", "  \"Version\": \"2012-10-17\",\n", "  \"Id\": \"sqspolicy\",\n", "  \"Statement\": [\n", "    {\n", "      \"Sid\": \"First\",\n", "      \"Effect\": \"Allow\",\n", "      \"Principal\": \"*\",\n", "      \"Action\": \"sqs:SendMessage\",\n", "      \"Resource\": \"", arn, "\",\n", "      \"Condition\": {\n", "        \"ArnEquals\": {\n", "          \"aws:SourceArn\": \"", aws_sns_topic.Example.Arn, "\"\n", "        }\n", "      }\n", "    }\n", "  ]\n", "}\n"), nil
			}).(pulumi.StringOutput),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

queue = aws.sqs.Queue("queue")
test = aws.sqs.QueuePolicy("test",
    queue_url=queue.id,
    policy=queue.arn.apply(lambda arn: f"""{{
  "Version": "2012-10-17",
  "Id": "sqspolicy",
  "Statement": [
    {{
      "Sid": "First",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "sqs:SendMessage",
      "Resource": "{arn}",
      "Condition": {{
        "ArnEquals": {{
          "aws:SourceArn": "{aws_sns_topic["example"]["arn"]}"
        }}
      }}
    }}
  ]
}}
"""))
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const queue = new aws.sqs.Queue("queue", {});
const test = new aws.sqs.QueuePolicy("test", {
    queueUrl: queue.id,
    policy: pulumi.interpolate`{
  "Version": "2012-10-17",
  "Id": "sqspolicy",
  "Statement": [
    {
      "Sid": "First",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "sqs:SendMessage",
      "Resource": "${queue.arn}",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "${aws_sns_topic.example.arn}"
        }
      }
    }
  ]
}
`,
});

Create a QueuePolicy Resource

new QueuePolicy(name: string, args: QueuePolicyArgs, opts?: CustomResourceOptions);
@overload
def QueuePolicy(resource_name: str,
                opts: Optional[ResourceOptions] = None,
                policy: Optional[str] = None,
                queue_url: Optional[str] = None)
@overload
def QueuePolicy(resource_name: str,
                args: QueuePolicyArgs,
                opts: Optional[ResourceOptions] = None)
func NewQueuePolicy(ctx *Context, name string, args QueuePolicyArgs, opts ...ResourceOption) (*QueuePolicy, error)
public QueuePolicy(string name, QueuePolicyArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args QueuePolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args QueuePolicyArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args QueuePolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args QueuePolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

QueuePolicy Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.

Inputs

The QueuePolicy resource accepts the following input properties:

Policy string | string
The JSON policy for the SQS queue.
QueueUrl string
The URL of the SQS Queue to which to attach the policy
Policy string | string
The JSON policy for the SQS queue.
QueueUrl string
The URL of the SQS Queue to which to attach the policy
policy string | PolicyDocument
The JSON policy for the SQS queue.
queueUrl string
The URL of the SQS Queue to which to attach the policy
policy str | str
The JSON policy for the SQS queue.
queue_url str
The URL of the SQS Queue to which to attach the policy

Outputs

All input properties are implicitly available as output properties. Additionally, the QueuePolicy resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.

Look up an Existing QueuePolicy Resource

Get an existing QueuePolicy resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: QueuePolicyState, opts?: CustomResourceOptions): QueuePolicy
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        policy: Optional[str] = None,
        queue_url: Optional[str] = None) -> QueuePolicy
func GetQueuePolicy(ctx *Context, name string, id IDInput, state *QueuePolicyState, opts ...ResourceOption) (*QueuePolicy, error)
public static QueuePolicy Get(string name, Input<string> id, QueuePolicyState? state, CustomResourceOptions? opts = null)
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.

The following state arguments are supported:

Policy string | string
The JSON policy for the SQS queue.
QueueUrl string
The URL of the SQS Queue to which to attach the policy
Policy string | string
The JSON policy for the SQS queue.
QueueUrl string
The URL of the SQS Queue to which to attach the policy
policy string | PolicyDocument
The JSON policy for the SQS queue.
queueUrl string
The URL of the SQS Queue to which to attach the policy
policy str | str
The JSON policy for the SQS queue.
queue_url str
The URL of the SQS Queue to which to attach the policy

Import

SQS Queue Policies can be imported using the queue URL, e.g.

 $ pulumi import aws:sqs/queuePolicy:QueuePolicy test https://queue.amazonaws.com/0123456789012/myqueue

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.