aws logo
AWS Classic v5.32.0, Mar 17 23

aws.sqs.QueuePolicy

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

Example Usage

using System.Collections.Generic;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var queue = new Aws.Sqs.Queue("queue");

    var testPolicyDocument = Aws.Iam.GetPolicyDocument.Invoke(new()
    {
        Statements = new[]
        {
            new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
            {
                Sid = "First",
                Effect = "Allow",
                Principals = new[]
                {
                    new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
                    {
                        Type = "*",
                        Identifiers = new[]
                        {
                            "*",
                        },
                    },
                },
                Actions = new[]
                {
                    "sqs:SendMessage",
                },
                Resources = new[]
                {
                    queue.Arn,
                },
                Conditions = new[]
                {
                    new Aws.Iam.Inputs.GetPolicyDocumentStatementConditionInputArgs
                    {
                        Test = "ArnEquals",
                        Variable = "aws:SourceArn",
                        Values = new[]
                        {
                            aws_sns_topic.Example.Arn,
                        },
                    },
                },
            },
        },
    });

    var testQueuePolicy = new Aws.Sqs.QueuePolicy("testQueuePolicy", new()
    {
        QueueUrl = queue.Id,
        Policy = testPolicyDocument.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
    });

});

Coming soon!

package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.sqs.Queue;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
import com.pulumi.aws.sqs.QueuePolicy;
import com.pulumi.aws.sqs.QueuePolicyArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var queue = new Queue("queue");

        final var testPolicyDocument = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
            .statements(GetPolicyDocumentStatementArgs.builder()
                .sid("First")
                .effect("Allow")
                .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                    .type("*")
                    .identifiers("*")
                    .build())
                .actions("sqs:SendMessage")
                .resources(queue.arn())
                .conditions(GetPolicyDocumentStatementConditionArgs.builder()
                    .test("ArnEquals")
                    .variable("aws:SourceArn")
                    .values(aws_sns_topic.example().arn())
                    .build())
                .build())
            .build());

        var testQueuePolicy = new QueuePolicy("testQueuePolicy", QueuePolicyArgs.builder()        
            .queueUrl(queue.id())
            .policy(testPolicyDocument.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult).applyValue(testPolicyDocument -> testPolicyDocument.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.json())))
            .build());

    }
}
import pulumi
import pulumi_aws as aws

queue = aws.sqs.Queue("queue")
test_policy_document = queue.arn.apply(lambda arn: aws.iam.get_policy_document_output(statements=[aws.iam.GetPolicyDocumentStatementArgs(
    sid="First",
    effect="Allow",
    principals=[aws.iam.GetPolicyDocumentStatementPrincipalArgs(
        type="*",
        identifiers=["*"],
    )],
    actions=["sqs:SendMessage"],
    resources=[arn],
    conditions=[aws.iam.GetPolicyDocumentStatementConditionArgs(
        test="ArnEquals",
        variable="aws:SourceArn",
        values=[aws_sns_topic["example"]["arn"]],
    )],
)]))
test_queue_policy = aws.sqs.QueuePolicy("testQueuePolicy",
    queue_url=queue.id,
    policy=test_policy_document.json)
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const queue = new aws.sqs.Queue("queue", {});
const testPolicyDocument = queue.arn.apply(arn => aws.iam.getPolicyDocumentOutput({
    statements: [{
        sid: "First",
        effect: "Allow",
        principals: [{
            type: "*",
            identifiers: ["*"],
        }],
        actions: ["sqs:SendMessage"],
        resources: [arn],
        conditions: [{
            test: "ArnEquals",
            variable: "aws:SourceArn",
            values: [aws_sns_topic.example.arn],
        }],
    }],
}));
const testQueuePolicy = new aws.sqs.QueuePolicy("testQueuePolicy", {
    queueUrl: queue.id,
    policy: testPolicyDocument.apply(testPolicyDocument => testPolicyDocument.json),
});
resources:
  queue:
    type: aws:sqs:Queue
  testQueuePolicy:
    type: aws:sqs:QueuePolicy
    properties:
      queueUrl: ${queue.id}
      policy: ${testPolicyDocument.json}
variables:
  testPolicyDocument:
    fn::invoke:
      Function: aws:iam:getPolicyDocument
      Arguments:
        statements:
          - sid: First
            effect: Allow
            principals:
              - type: '*'
                identifiers:
                  - '*'
            actions:
              - sqs:SendMessage
            resources:
              - ${queue.arn}
            conditions:
              - test: ArnEquals
                variable: aws:SourceArn
                values:
                  - ${aws_sns_topic.example.arn}

Create 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)
public QueuePolicy(String name, QueuePolicyArgs args)
public QueuePolicy(String name, QueuePolicyArgs args, CustomResourceOptions options)
type: aws:sqs:QueuePolicy
properties: # The arguments to resource properties.
options: # 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.
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.
name String
The unique name of the resource.
args QueuePolicyArgs
The arguments to resource properties.
options 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 Architecture and Concepts 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 | 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

policy String |

The JSON policy for the SQS queue.

queueUrl String

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 string

The provider-assigned unique ID for this managed resource.

id str

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

Look up 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)
public static QueuePolicy get(String name, Output<String> id, QueuePolicyState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
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.
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 | 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

policy String |

The JSON policy for the SQS queue.

queueUrl String

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
AWS Classic pulumi/pulumi-aws
License
Apache-2.0
Notes

This Pulumi package is based on the aws Terraform Provider.