Issue
Can !Ref and !Sub be used interchangeably in any use case? I need to substitute Parameter1 in environment variable LOCATION_UPDATE_SNS_TOPIC, So that this variable can be used programatically using python code inside the ec2. The Userdata property below for an ec2 instance is below.
UserData:
Fn::Base64:
!Sub |
#!/bin/bash
export LOCATION_UPDATE_SNS_TOPIC=!Sub Parameter1
or
UserData:
Fn::Base64:
!Sub |
#!/bin/bash
export LOCATION_UPDATE_SNS_TOPIC=!Ref Parameter1
Solution
In this case you neither use !Sub
nor !Ref
. You already declared with the first !Sub |
that the following contains parameter. The correct solution would be:
UserData:
Fn::Base64:
!Sub |
#!/bin/bash
export LOCATION_UPDATE_SNS_TOPIC=${Parameter1}
You can find some examples here.
Answered By - Robert Kossendey Answer Checked By - Dawn Plyler (WPSolving Volunteer)