在 userData 中将 Cloudformation ref 与 awscli 结合使用
using Cloudformation ref with awscli in userData
"aws ec2 create-tags --resources xxxxxx --tags Key=Team,Value=everybody --region { \"Ref\" : \"region\" } --out text\n"
以上 line/command 我在我的 Cloudformation userData 中使用,它没有被执行,我在调试时遇到以下错误:
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
我的区域名称被用作 Cloudformation 脚本的输入参数。这就是为什么我在 --region
选项中使用 ref
。
这是错误的吗?
是否可以在 Cloudformation 中将 ref
与 awscli 命令一起使用?
谢谢
UserData
是 Cloud Formation 模板中的一个字符串,因此 {"Ref": "region"}
未展开,因此文字 {"Ref": "region"}
被传递给 --region
参数.
你可以试试
{"Fn::Join": [" ", ["aws ec2 create-tags --resources xxxxxx --tags Key=Team,Value=everybody --region", {"Ref": "region"}, "--out text\n"]]}
文档提供了有关 Fn::Join
函数的信息 http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html
此示例模板还显示了 UserData
,包括区域参数 Ref
https://s3.amazonaws.com/cloudformation-templates-us-east-1/vpc_single_instance_in_subnet.template
"aws ec2 create-tags --resources xxxxxx --tags Key=Team,Value=everybody --region { \"Ref\" : \"region\" } --out text\n"
以上 line/command 我在我的 Cloudformation userData 中使用,它没有被执行,我在调试时遇到以下错误:
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
我的区域名称被用作 Cloudformation 脚本的输入参数。这就是为什么我在 --region
选项中使用 ref
。
这是错误的吗?
是否可以在 Cloudformation 中将 ref
与 awscli 命令一起使用?
谢谢
UserData
是 Cloud Formation 模板中的一个字符串,因此 {"Ref": "region"}
未展开,因此文字 {"Ref": "region"}
被传递给 --region
参数.
你可以试试
{"Fn::Join": [" ", ["aws ec2 create-tags --resources xxxxxx --tags Key=Team,Value=everybody --region", {"Ref": "region"}, "--out text\n"]]}
文档提供了有关 Fn::Join
函数的信息 http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html
此示例模板还显示了 UserData
,包括区域参数 Ref
https://s3.amazonaws.com/cloudformation-templates-us-east-1/vpc_single_instance_in_subnet.template