[英]cloudformation- how to use Ref in sources of AWS::CloudFormation::Init section?
I'm trying to write sources inside AWS::CloudFormation::Init
to take a parameter like below:我正在尝试在AWS::CloudFormation::Init
中编写源代码以获取如下参数:
"Parameters" : {
"Environment" : {
"Description" : "The Environment",
"Type" : "String",
"AllowedValues" : [
"DEV",
"QA",
"UAT",
"PROD"
]
}
}
Below is my Metadata section:下面是我的元数据部分:
"LaunchTemplate": {
"Type": "AWS::EC2::LaunchTemplate",
"Metadata": {
"Comment" : "Install application",
"AWS::CloudFormation::Init" : {
"configSets" : {
"full_install" : [ "prepare", "app-deployment" ]
},
"app-deployment" : {
"sources": {
"Fn::Join":["",["/app/",{"Ref": "Environment"},"/appname"]] : "https://xyz.s3.amazonaws.com/appname.tar"
},
"files": {
"Fn::Join":["",["/opt/",{"Ref": "Environment"},"/index.html"]] : {
"content" : "<html><title>HelloTitle</title><body><h1>header H1</h1></body></html>"
}
This is not working.这是行不通的。 Can I user Ref
function to use parameter this way inside sources
and files
section??我可以使用Ref
function 在sources
和files
部分中以这种方式使用参数吗?
I don't think you can do this.我不认为你能做到这一点。
However, the workaround would be to use to use commands section.但是,解决方法是使用 to use commands部分。
I can demonstrate the idea behind the workaround using yaml
(its what I personal use) including multiline files:我可以使用yaml
(我个人使用的)演示解决方法背后的想法,包括多行文件:
commands:
04_setup_index_html:
command: !Sub |
mkdir -p /opt/${Environment}
echo "<html><title>HelloTitle</title><body><h1>header H1</h1></body></html>" \
> /opt/${Environment}/index.html
05_setup_index2_html_multiline:
command: !Sub |
mkdir -p /opt/${Environment}
cat >/opt/${Environment}/index2.html << EOL
<html>
<title>HelloTitle</title>
<body>
<h1>header H1</h1>
</body>
</html>
EOL
This way you can create your files and folders dynamically based on the template Parameters
.这样您就可以根据模板Parameters
动态创建文件和文件夹。
Same of course would be possible in json
, but I don't have a tested working example right now.当然json
也可以,但我现在没有经过测试的工作示例。 The snipped in yaml
provided works for sure. yaml
中的片段肯定可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.