DEV Community

Joey The Dev
Joey The Dev

Posted on

Using aws-specific variables instead of 'Fn::Join'

As promised, I am starting with the documentation of my journey through AWS and the serverless framework so I can reference these things in the future and also help someone else along the way :)

So these posts will be super short and to the point. What I want to show today is configuring arns using the AWS variables in the serverless framework. Now a common way to configure the arn for a SNS topic inside the serverless yml/ts file using Fn::Join would be something like the below:

NB: NOTICE_ARN would be like an environment variable here

NOTICE_ARN: { 'Fn::Join': [ ':', [ 'arn:aws:sns', { Ref: 'AWS::Region' }, { Ref: 'AWS::AccountId' }, 'user-notice-${self:provider.stage}' ] ] } 
Enter fullscreen mode Exit fullscreen mode

But you can avoid the Fn::Join by simply putting everything into one string like so:

NOTICE_ARN: 'arn:aws:sns:${aws:region}:${aws:accountId}:user-notice-${self:provider.stage}' 
Enter fullscreen mode Exit fullscreen mode

And thats it! Nicer, cleaner and it works offline with serverless offline too :) Previoulsy, in the environment variable, the value would be [Object Object] but now you would have a nice string with those aws values filled in.

Top comments (0)