1
votes

I have SNS topic SNS1 in region eu-west-1 and all other services SQS1 and are in eu-central-1 What I want is to subscribe my SQS to SNS topic trough a Serverless framework

My current serverless definition is

Resources:
  SNS1:
    Type: AWS::SNS::Topic
    Properties:
      TopicName: "SNS1"
  SQS1:
    Type: "AWS::SQS::Queue"
    Properties:
      QueueName: "SQS1"
  snsSubscription:
    Type: "AWS::SNS::Subscription"
    Properties:
      TopicArn: !Ref SNS1
      Endpoint: !GetAtt
        - SQS2
        - Arn
      Protocol: sqs
      RawMessageDelivery: "true"

But this creates a new SNS topic in eu-central-1 (my default region) and I don't want that, is there some parameter to directly specify the SNS ARN? or specifying the region to the SNS?

I already try this configuration but it does not work

Resources:
  SQS1:
    Type: "AWS::SQS::Queue"
    Properties:
      QueueName: "SQS1"
  snsSubscription:
    Type: "AWS::SNS::Subscription"
    Properties:
      TopicArn: "arn:aws:sqs:eu-west-1:776751225653:SNS1"
      Endpoint: !GetAtt
        - SQS2
        - Arn
      Protocol: sqs
      RawMessageDelivery: "true"

I get the error:

An error occurred: snsSubscription - Invalid parameter: TopicArn (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter; Request ID: 9494047a-f933-5ece-9af8-5cfbf94a78a4; Proxy: null).

Note that the names are made-up I don't have numbers in the names of my resources

1

1 Answers

0
votes

Create two stacks:

  1. In region 1, create the SNS topic and all other region 1 resources.
  2. In region 2, create the SQS queue, SNS subscription, and other region 2 resources. Pass the region 1 SNS topic ARN as an input parameter to this stack (or you could use CloudFormation outputs from the region 1 stack).