AWS Amazon SQS Queue Policy

This page shows how to write Terraform and CloudFormation for Amazon SQS Queue Policy and write them securely.

aws_sqs_queue_policy (Terraform)

The Queue Policy in Amazon SQS can be configured in Terraform with the resource name aws_sqs_queue_policy. The following sections describe 3 examples of how to use the resource and its parameters.

Example Usage from GitHub

sqs_restricted_principal.tf#L10
resource "aws_sqs_queue_policy" "valid_sqs_policy_condition" {
  queue_url = "SampleQueue"

  policy = <<EOF
{
  "Version": "2012-10-17",
policies.tf#L1
resource "aws_sqs_queue_policy" "mo" {
  queue_url = aws_sqs_queue.mo.id
  policy    = data.aws_iam_policy_document.mo.json
}

data "aws_iam_policy_document" "mo" {
sqs_queue_policy_wildcard_principal.tf#L9
resource "aws_sqs_queue_policy" "sqs_policy_allow_no_wildcard" {
  queue_url = "https://queue.amazonaws.com/0123456789012/myqueue"
  policy    = <<EOF
{
    "Version": "2012-10-17",
    "Statement": [

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

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

AWS::SQS::QueuePolicy (CloudFormation)

The QueuePolicy in SQS can be configured in CloudFormation with the resource name AWS::SQS::QueuePolicy. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

eu-mws-notif-queues%2Btopic.yml#L6
  Type: AWS::SQS::QueuePolicy
  Properties:
    Queues:
      - !Ref MwsReportSubDE
    PolicyDocument:
      Version: "2012-10-17"
cf.yml#L59
        Type: AWS::SQS::QueuePolicy
        Properties:
            PolicyDocument:
                Statement:
                    -
                        Effect: Allow
policies.yml#L3
        Type: AWS::SQS::QueuePolicy
        Properties:
            PolicyDocument:
                Version: "2012-10-17"
                Statement:
                    - Sid: allow-sns-messages
needs-sqs.yml#L27
    Type: AWS::SQS::QueuePolicy
    Properties:
      PolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Sid: "allow-sns-messages"
dl-sqs-public-access-check-unit-test.yml#L23
        Type: AWS::SQS::QueuePolicy
  expectations:
    rules:
      delta_sqs_public_access: FAIL
- name: MyTest4
  input:
clouformation%20step01.json#L200
      "Type": "AWS::SQS::QueuePolicy",
      "Properties": {
        "Queues": [
          {
            "Ref": "INVCLOSECASHIER"
          }
sqs_queue_with_wildcards.json#L11
      "Type" : "AWS::SQS::QueuePolicy",
      "Properties" : {
        "PolicyDocument" : {
          "Id" : "MyQueuePolicy",
          "Version" : "2012-10-17",
          "Statement" : [ {
sqs_queue_with_wildcards.json#L11
      "Type" : "AWS::SQS::QueuePolicy",
      "Properties" : {
        "PolicyDocument" : {
          "Id" : "MyQueuePolicy",
          "Version" : "2012-10-17",
          "Statement" : [ {
sqs_queue_with_wildcards.json#L11
      "Type" : "AWS::SQS::QueuePolicy",
      "Properties" : {
        "PolicyDocument" : {
          "Id" : "MyQueuePolicy",
          "Version" : "2012-10-17",
          "Statement" : [ {
sqs_queue_with_wildcards.json#L10
      "Type": "AWS::SQS::QueuePolicy",
      "Properties": {
        "PolicyDocument": {
          "Id": "MyQueuePolicy",
          "Version": "2012-10-17",
          "Statement": [

Parameters

Explanation in CloudFormation Registry

The AWS::SQS::QueuePolicy type applies a policy to Amazon SQS queues. For an example snippet, see Declaring an Amazon SQS policy in the AWS CloudFormation User Guide.

Frequently asked questions

What is AWS Amazon SQS Queue Policy?

AWS Amazon SQS Queue Policy is a resource for Amazon SQS of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon SQS Queue Policy?

For Terraform, the Cigna/confectionery, rock7/cloudloop-sqs-terraform-module and ffsclyh/config-lint source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the kaskadi/amz-reports-hooks, PhonyLou/hello_sqs_sns and WojciechMatuszewski/golang-upload-fanout source code examples are useful. See the CloudFormation Example section for further details.