I am getting this error when trying to use !Sub with variables in UserData in CloudFormation:
Template error: One or more Fn::Sub intrinsic functions don't specify expected arguments. Specify a string as first argument, and an optional second argument to specify a mapping of values to replace in the string
Why do I get this error?
This is my code:
LinuxEC2Instance:
Type: AWS::EC2::Instance
Properties:
UserData:
Fn::Base64: !Sub
- arn_id: !If [TestEnvironment, 'id1', 'id2']
- key: !If [TestEnvironment, 'key1', 'key2']
- |
ARN_ID=${arn_id}
KEY=${key}
echo $ARN_ID
echo $KEY