问题
"aws ec2 create-tags --resources xxxxxx --tags Key=Team,Value=everybody --region { \"Ref\" : \"region\" } --out text\n"
The above line/command I am using in my Cloudformation userData, It is not getting executed , I am getting the following error when I debugged :
aws: error: argument --region: Invalid choice, valid choices are:
ap-southeast-1 | us-gov-west-1
ap-northeast-1 | eu-west-1
fips-us-gov-west-1 | us-west-1
us-west-2 | us-east-1
cn-north-1 | ap-southeast-2
sa-east-1
My region name is taken as input parameter for Cloudformation script. Thats why I used ref
in --region
option.
Is this wrong ?
Is it possible to use ref
with awscli commands in Cloudformation ?
Thanks
回答1:
The UserData
is a string in your Cloud Formation template, and therefore the {"Ref": "region"}
is not expanded so the literal {"Ref": "region"}
is being passed to the --region
argument.
you could try
{"Fn::Join": [" ", ["aws ec2 create-tags --resources xxxxxx --tags Key=Team,Value=everybody --region", {"Ref": "region"}, "--out text\n"]]}
The docs provide information on the Fn::Join
function http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html
Also this example template shows UserData
including a Ref
for the region parameter
https://s3.amazonaws.com/cloudformation-templates-us-east-1/vpc_single_instance_in_subnet.template
来源:https://stackoverflow.com/questions/39314105/using-cloudformation-ref-with-awscli-in-userdata