I Have a function which should publish to an AWS SNS topic.
The SNS topic is created from the resources section of the serverless.yml file. However the output, CloudFormation doesn’t make the function depend on the SNS Topic.
I need the function to receive the SNS topic ARN.I’m trying to do this with “Fn:GetAtt” but that causes dependency problems as the functions is created before the SNS topic.
Can DependsOn be specified in function sections of serverless.yml?
Is there a reason you’re manually setting up the SNS topic in the resource section? Normally you would just do this and let Serverless handle the rest.
I dont intend to subscribe to this SNS topic from this service. It will be exported from the cloud formation stack to be used in another serverless micro-service so events is not suitable.
Your Fn::Join solution is interesting but quite long and unwieldy. If i manually edit the outputted cloudformation i can fix this with a simple depends on.
DependsOn only impacts the order of creation so it won’t help you find the Arn for the SNS topic. Even if the stack is created in the right order you still can’t use Fn::GetAtt to find the Arn because CloudFormation doesn’t support that. The only attribute you can retrieve is the TopicName. At least that’s what the doc’s say - http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html
As far as I’m aware the only way to get the Arn is to build it using Fn::Join or Fn::Sub.
Ahh, that seems problematic. In the JS SDK i can only publish to a topic via ARN.
Ok thank you for the full explanation, i’ll use the join for now :).
I’ll also see what resources in the AWS space are available to help out here, from an outside perspective i would assume GetAtt should be able to get an Arn if the resource has one.