在userData中将Cloudformation ref与awscli一起使用 [英] using Cloudformation ref with awscli in userData

查看:63
本文介绍了在userData中将Cloudformation ref与awscli一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"aws ec2 create-tags --resources xxxxxx --tags Key=Team,Value=everybody --region { \"Ref\" : \"region\" } --out text\n"

我在Cloudformation中使用的上述行/命令userData,未执行,调试时出现以下错误:

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

我的区域名称被用作输入Cloudformation脚本的参数。这就是为什么我在-region 选项中使用 ref 的原因。

My region name is taken as input parameter for Cloudformation script. Thats why I used ref in --region option.

这是错的吗?
是否可以在Cloudformation中的awscli命令中使用 ref

谢谢

推荐答案

UserData 是云形成模板中的字符串,因此 { Ref: region} 没有展开,因此传递了文字 { Ref: region} -region 参数。

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.

您可以尝试

{"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

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

这篇关于在userData中将Cloudformation ref与awscli一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆