【问题标题】:using Cloudformation ref with awscli in userData在 userData 中使用 Cloudformation ref 和 awscli
【发布时间】:2017-01-11 20:25:43
【问题描述】:
"aws ec2 create-tags --resources xxxxxx --tags Key=Team,Value=everybody --region { \"Ref\" : \"region\" } --out text\n"

我在 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 命令一起使用?

谢谢

【问题讨论】:

    标签: aws-cli amazon-cloudformation


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 2020-11-26
      • 2020-02-25
      • 1970-01-01
      • 2018-12-25
      • 1970-01-01
      • 2017-12-02
      • 1970-01-01
      • 1970-01-01
      • 2015-02-14
      相关资源
      最近更新 更多