Skip to content

Instantly share code, notes, and snippets.

@codeasashu
Created July 22, 2020 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeasashu/1035507cf2fd4bb376bbef8a223cd839 to your computer and use it in GitHub Desktop.
Save codeasashu/1035507cf2fd4bb376bbef8a223cd839 to your computer and use it in GitHub Desktop.

Why

When you want to integrate and send data from SNS to SQS, it wont work straighaway. Some tweaks has to be done

Create SNS

Create SNS just like you usually do (via web console of aws).

Configuring SNS cloudwatch

Once, you do, goto IAM page, search for following roles:

  • SNSSuccessFeedback
  • SNSFailureFeedback

Now, goto SNS topic and edit it. Go to Delivery logging and enter the Success and failure arns from above into the fields.

Verify Policy

The SNS policy should look something like:

{
  "Version": "2008-10-17",
  "Id": "__default_policy_ID",
  "Statement": [
    {
      "Sid": "__default_statement_ID",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": [
        "SNS:GetTopicAttributes",
        "SNS:SetTopicAttributes",
        "SNS:AddPermission",
        "SNS:RemovePermission",
        "SNS:DeleteTopic",
        "SNS:Subscribe",
        "SNS:ListSubscriptionsByTopic",
        "SNS:Publish",
        "SNS:Receive"
      ],
      "Resource": "arn:aws:sns:<region>:<account id>:<topic name>",
      "Condition": {
        "StringEquals": {
          "AWS:SourceOwner": "<account id>"
        }
      }
    }
  ]
}

Create SQS queue

Create SQS queue as you usually do. Goto access policy editor, and modify it so it should look like following:

{
  "Version": "2008-10-17",
  "Id": "__default_policy_ID",
  "Statement": [
    {
      "Sid": "__owner_statement",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::<topic name>:root"
      },
      "Action": "SQS:*",
      "Resource": "arn:aws:sqs:<region>:<topic name>:<queue name>"
    },
    {
      "Sid": "Sid1583234152842",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "SQS:SendMessage",
      "Resource": "arn:aws:sqs:<region>:<topic name>:<queue name>",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "arn:aws:sns:<region>:<topic name>:<topic name>"
        }
      }
    }
  ]
}

Done. Enjoy SNS to SQS message sending

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment