1. Packages
  2. AWS
  3. API Docs
  4. sqs
  5. QueuePolicy
AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi

aws.sqs.QueuePolicy

Explore with Pulumi AI

aws logo
AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi

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

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const q = new aws.sqs.Queue("q", {name: "examplequeue"});
    const test = q.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: [example.arn],
            }],
        }],
    }));
    const testQueuePolicy = new aws.sqs.QueuePolicy("test", {
        queueUrl: q.id,
        policy: test.apply(test => test.json),
    });
    
    import pulumi
    import pulumi_aws as aws
    
    q = aws.sqs.Queue("q", name="examplequeue")
    test = q.arn.apply(lambda arn: aws.iam.get_policy_document_output(statements=[{
        "sid": "First",
        "effect": "Allow",
        "principals": [{
            "type": "*",
            "identifiers": ["*"],
        }],
        "actions": ["sqs:SendMessage"],
        "resources": [arn],
        "conditions": [{
            "test": "ArnEquals",
            "variable": "aws:SourceArn",
            "values": [example["arn"]],
        }],
    }]))
    test_queue_policy = aws.sqs.QueuePolicy("test",
        queue_url=q.id,
        policy=test.json)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/sqs"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
    q, err := sqs.NewQueue(ctx, "q", &sqs.QueueArgs{
    Name: pulumi.String("examplequeue"),
    })
    if err != nil {
    return err
    }
    test := q.Arn.ApplyT(func(arn string) (iam.GetPolicyDocumentResult, error) {
    return iam.GetPolicyDocumentResult(interface{}(iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
    Statements: []iam.GetPolicyDocumentStatement{
    {
    Sid: "First",
    Effect: "Allow",
    Principals: []iam.GetPolicyDocumentStatementPrincipal{
    {
    Type: "*",
    Identifiers: []string{
    "*",
    },
    },
    },
    Actions: []string{
    "sqs:SendMessage",
    },
    Resources: []string{
    arn,
    },
    Conditions: []iam.GetPolicyDocumentStatementCondition{
    {
    Test: "ArnEquals",
    Variable: "aws:SourceArn",
    Values: interface{}{
    example.Arn,
    },
    },
    },
    },
    },
    }, nil))), nil
    }).(iam.GetPolicyDocumentResultOutput)
    _, err = sqs.NewQueuePolicy(ctx, "test", &sqs.QueuePolicyArgs{
    QueueUrl: q.ID(),
    Policy: pulumi.String(test.ApplyT(func(test iam.GetPolicyDocumentResult) (*string, error) {
    return &test.Json, nil
    }).(pulumi.StringPtrOutput)),
    })
    if err != nil {
    return err
    }
    return nil
    })
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var q = new Aws.Sqs.Queue("q", new()
        {
            Name = "examplequeue",
        });
    
        var test = 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[]
                    {
                        q.Arn,
                    },
                    Conditions = new[]
                    {
                        new Aws.Iam.Inputs.GetPolicyDocumentStatementConditionInputArgs
                        {
                            Test = "ArnEquals",
                            Variable = "aws:SourceArn",
                            Values = new[]
                            {
                                example.Arn,
                            },
                        },
                    },
                },
            },
        });
    
        var testQueuePolicy = new Aws.Sqs.QueuePolicy("test", new()
        {
            QueueUrl = q.Id,
            Policy = test.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
        });
    
    });
    
    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.sqs.QueueArgs;
    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 q = new Queue("q", QueueArgs.builder()
                .name("examplequeue")
                .build());
    
            final var test = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
                .statements(GetPolicyDocumentStatementArgs.builder()
                    .sid("First")
                    .effect("Allow")
                    .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                        .type("*")
                        .identifiers("*")
                        .build())
                    .actions("sqs:SendMessage")
                    .resources(q.arn())
                    .conditions(GetPolicyDocumentStatementConditionArgs.builder()
                        .test("ArnEquals")
                        .variable("aws:SourceArn")
                        .values(example.arn())
                        .build())
                    .build())
                .build());
    
            var testQueuePolicy = new QueuePolicy("testQueuePolicy", QueuePolicyArgs.builder()
                .queueUrl(q.id())
                .policy(test.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult).applyValue(test -> test.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.json())))
                .build());
    
        }
    }
    
    resources:
      q:
        type: aws:sqs:Queue
        properties:
          name: examplequeue
      testQueuePolicy:
        type: aws:sqs:QueuePolicy
        name: test
        properties:
          queueUrl: ${q.id}
          policy: ${test.json}
    variables:
      test:
        fn::invoke:
          Function: aws:iam:getPolicyDocument
          Arguments:
            statements:
              - sid: First
                effect: Allow
                principals:
                  - type: '*'
                    identifiers:
                      - '*'
                actions:
                  - sqs:SendMessage
                resources:
                  - ${q.arn}
                conditions:
                  - test: ArnEquals
                    variable: aws:SourceArn
                    values:
                      - ${example.arn}
    

    Create QueuePolicy Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new QueuePolicy(name: string, args: QueuePolicyArgs, opts?: CustomResourceOptions);
    @overload
    def QueuePolicy(resource_name: str,
                    args: QueuePolicyArgs,
                    opts: Optional[ResourceOptions] = None)
    
    @overload
    def QueuePolicy(resource_name: str,
                    opts: Optional[ResourceOptions] = None,
                    policy: Optional[str] = None,
                    queue_url: Optional[str] = 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.
    
    

    Parameters

    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.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var queuePolicyResource = new Aws.Sqs.QueuePolicy("queuePolicyResource", new()
    {
        Policy = "string",
        QueueUrl = "string",
    });
    
    example, err := sqs.NewQueuePolicy(ctx, "queuePolicyResource", &sqs.QueuePolicyArgs{
    	Policy:   pulumi.Any("string"),
    	QueueUrl: pulumi.String("string"),
    })
    
    var queuePolicyResource = new QueuePolicy("queuePolicyResource", QueuePolicyArgs.builder()
        .policy("string")
        .queueUrl("string")
        .build());
    
    queue_policy_resource = aws.sqs.QueuePolicy("queuePolicyResource",
        policy="string",
        queue_url="string")
    
    const queuePolicyResource = new aws.sqs.QueuePolicy("queuePolicyResource", {
        policy: "string",
        queueUrl: "string",
    });
    
    type: aws:sqs:QueuePolicy
    properties:
        policy: string
        queueUrl: string
    

    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

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    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

    Using pulumi import, import SQS Queue Policies using the queue URL. For example:

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

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo
    AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi