Can't assign a function to multiple AWS SNS topics

I’ve been trying to subscribe a function to multiple SNS topics but no luck. So far I’ve tried following:


handler: handler.indexDocument
     events:
       - sns:
           topicName: centre-${env:API_STAGE}-CentreRecordWritten
           displayName: Index document when centre record is written
       - sns:
           topicName: organisation-${env:API_STAGE}-OrganisationRecordWritten
           displayName: Index document when organisation record is written

handler: handler.indexDocument
    events:
      - sns:
          arn:
            - arn:aws:sns:${env:AWS_REGION}:${env:AWS_ACCOUNT}:centre-${env:API_STAGE}-CentreRecordWritten
            - arn:aws:sns:${env:AWS_REGION}:${env:AWS_ACCOUNT}:organisation-${env:API_STAGE}-OrganisationRecordWritten

 handler: handler.indexDocument
    events:
      - sns:
        - arn: arn:aws:sns:${env:AWS_REGION}:${env:AWS_ACCOUNT}:centre-${env:API_STAGE}-CentreRecordWritten
        - arn: arn:aws:sns:${env:AWS_REGION}:${env:AWS_ACCOUNT}:organisation-${env:API_STAGE}-OrganisationRecordWritten

@iamatharkhan Can you give more detail on what is not working? Is it throwing an error? Is it deploying the function without hooking up the triggers?

The first syntax should work. I just deployed a sample project with it and confirmed there are two subscription triggers. Perhaps it’s a YML indentation issue?

FWIW, here is my full serverless.yml with two subscriptions to one topic:

service: sns-test

provider:
  name: aws
  runtime: python3.6

functions:
  hello:
    handler: handler.hello
    events:
      - sns:
          topicName: centre-CentreRecordWritten
          displayName: Index document when centre record is written
      - sns:
          topicName: organisation-OrganisationRecordWritten
          displayName: Index document when organisation record is written

Hi @alexdebrie1 thanks for looking into it. The first syntax was incorrect because I am using pre-existing topics. So the new syntaxs I’ve tried are following:

events:
      - sns:
          arn: arn:aws:sns:${env:AWS_REGION}:${env:AWS_ACCOUNT}:APITrainingProvider-${env:API_STAGE}-TPRecordWritten
      - sns:
          arn: arn:aws:sns:${env:AWS_REGION}:${env:AWS_ACCOUNT}:APIOrganisation-${env:API_STAGE}-OrganisationRecordWritten

events:
      - sns:
          arn: arn:aws:sns:${env:AWS_REGION}:${env:AWS_ACCOUNT}:APITrainingProvider-${env:API_STAGE}-TPRecordWritten
          topicName: APITrainingProvider-${env:API_STAGE}-TPRecordWritten
      - sns:
          arn: arn:aws:sns:${env:AWS_REGION}:${env:AWS_ACCOUNT}:APIOrganisation-${env:API_STAGE}-OrganisationRecordWritten
          topicName: APIOrganisation-${env:API_STAGE}-OrganisationRecordWritten

i am getting following error:

Serverless Error ---------------------------------------

 Missing or invalid "displayName" property for sns event
 in function indexDocument The correct syntax is: sns:
 topic-name-or-arn OR an object with "topicName" AND
 "displayName" strings. Please check the docs for more
 info.

Hmm, that first one should work. What if you tried putting the ARN on the same line as the sns declaration:

events:
      - sns: arn:aws:sns:${env:AWS_REGION}:${env:AWS_ACCOUNT}:APITrainingProvider-${env:API_STAGE}-TPRecordWritten
      - sns: arn:aws:sns:${env:AWS_REGION}:${env:AWS_ACCOUNT}:APIOrganisation-${env:API_STAGE}-OrganisationRecordWritten