question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support all intrinsic functions for SNS definition

See original GitHub issue

This is a Bug Report

Description

The docs state, that you can use cloudformation intrinsic functions while defining the sns source for a function, however, when I take this example:

functions:
  dispatcher:
    handler: dispatcher.dispatch
    events:
      - sns:
          arn:
            Fn::Join:
              - ""
              - - "arn:aws:sns:"
                - Ref: "AWS::Region"
                - ":"
                - Ref: "AWS::AccountId"
                - ":MyCustomTopic"
          topicName: MyCustomTopic

and adjust it to ours needs

functions:
  dispatcher:
    handler: dispatcher.dispatch
    events:
      - sns:
          arn:
            Fn::Join:
              - ""
              - - "arn:aws:sns:"
                - Ref: "AWS::Region"
                - ":"
                - Ref: "AWS::AccountId"
                - ":"
                - { Fn::GetAtt: [ Infrastructure, Outputs.SNSTopic ] }
          topicName: { Fn::GetAtt: [ Infrastructure, Outputs.SNSTopic ] }

it returns the following error:

  Stack Trace --------------------------------------------

TypeError: event.sns.arn.indexOf is not a function
    at functionObj.events.forEach.event (/Users/tim/npm-global/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/sns/index.js:36:44)
    at Array.forEach (native)
    at serverless.service.getAllFunctions.forEach (/Users/tim/npm-global/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/sns/index.js:22:28)
    at Array.forEach (native)
    at AwsCompileSNSEvents.compileSNSEvents (/Users/tim/npm-global/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/sns/index.js:18:47)
    at BbPromise.reduce (/Users/tim/npm-global/lib/node_modules/serverless/lib/classes/PluginManager.js:254:55)
From previous event:
    at PluginManager.invoke (/Users/tim/npm-global/lib/node_modules/serverless/lib/classes/PluginManager.js:254:22)
    at PluginManager.spawn (/Users/tim/npm-global/lib/node_modules/serverless/lib/classes/PluginManager.js:266:17)
    at Deploy.BbPromise.bind.then (/Users/tim/npm-global/lib/node_modules/serverless/lib/plugins/deploy/deploy.js:88:48)
From previous event:
    at Object.before:deploy:deploy [as hook] (/Users/tim/npm-global/lib/node_modules/serverless/lib/plugins/deploy/deploy.js:86:8)
    at BbPromise.reduce (/Users/tim/npm-global/lib/node_modules/serverless/lib/classes/PluginManager.js:254:55)
From previous event:
    at PluginManager.invoke (/Users/tim/npm-global/lib/node_modules/serverless/lib/classes/PluginManager.js:254:22)
    at PluginManager.run (/Users/tim/npm-global/lib/node_modules/serverless/lib/classes/PluginManager.js:273:17)
    at variables.populateService.then (/Users/tim/npm-global/lib/node_modules/serverless/lib/Serverless.js:105:33)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)
From previous event:
    at Serverless.run (/Users/tim/npm-global/lib/node_modules/serverless/lib/Serverless.js:92:74)
    at serverless.init.then (/Users/tim/npm-global/lib/node_modules/serverless/bin/serverless:30:50)

The example how it is in the docs works without problems, but adding the Fn::GetAtt makes it fail.

Related PR

Additional Data

Your Environment Information

  • OS: darwin
  • Node Version: 7.9.0
  • Serverless Version: 1.15.3

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:16
  • Comments:28 (9 by maintainers)

github_iconTop GitHub Comments

22reactions
chensjlvcommented, Nov 7, 2018

Just figured out, by reading https://github.com/serverless/serverless/blob/master/lib/plugins/aws/package/compile/events/sns/index.js#L32

topicName has to be a string for this to work.

functions:
  ***:
    handler: ***/***
    events:
      - sns:
          arn:
            Ref: SnsTopic
          topicName: ${self:custom.snsTopic}

If topicName is from something like Fn::GetAtt, topicName will become an object and trigger https://github.com/serverless/serverless/blob/master/lib/plugins/aws/package/compile/events/sns/index.js#L35, which looks like a bug for me, because why cannot we have both arn and topic name to be object.

5reactions
crysislinuxcommented, Jun 4, 2018

any updates? I have to hardcode those arn related things for now. Feels not flexible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intrinsic function reference - AWS CloudFormation
You can use intrinsic functions only in specific parts of a template. Currently, you can use intrinsic functions in resource properties, outputs, metadata ......
Read more >
AWS Lambda Functions - Serverless Framework
All of the Lambda functions in your serverless service can be found in serverless.yml under the functions property.
Read more >
AWS CDK Step Functions SNS Task - input path parameter ...
Step Functions have a States.Format intrinsic function to interpolate strings. But because intrinsic functions aren't accepted in all fields ( ...
Read more >
serverless-step-functions - npm
yml. You can use CloudFormation intrinsic functions such as Ref and Fn::GetAtt to reference Lambda functions, SNS topics, SQS queues and ...
Read more >
Why AWS Step Functions and SDK integrations
Intrinsic functions are functions available in Amazon States Language (ASL) which are focused on making integrations with different Tasks easier ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found