[英]Use cloudformation parameter in userdata
I have zookeeper connect as ip1:port1,ip2:port2,ip3:port3 and I want to use this in my userdata How can i do it?我有 zookeeper 连接为 ip1:port1,ip2:port2,ip3:port3,我想在我的用户数据中使用它我该怎么做?
"ZooKeeperConnect": {
"Type": "String",
"Description": "list of IP or CNAME's for the associated zookeeper ensemble",
"AllowedPattern": "([1-9][0-9]?|[1-2][0-9]{2})(\\.([1-9][0-9]?|[1-2][0-9]{2})){3}(:[1-9][0-9]{1,4})?(,([1-9][0-9]?|[1-2][0-9]{2})(\\.([1-9][0-9]?|[1-2][0-9]{2})){3}(:[1-9][0-9]{1,4})?)*"
}
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash \n",
"echo Cache proxy vars... \n",
I want to use ZooKeeperConnect values in my userdata我想在我的用户数据中使用 ZooKeeperConnect 值
You can reference the ZooKeeperConnect
parameter or any other parameter in your userdata section:您可以在 userdata 部分中引用
ZooKeeperConnect
参数或任何其他参数:
"UserData" : {
"Fn::Base64" : {
"Fn::Join" : [ ",", [
{ "Ref" : "MyValue" },
{ "Ref" : "MyName" },
"Hello World" ] ]
}
}
The above snippet was taken from http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-general.html .上面的片段取自http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-general.html 。
Basically you can't directly reference Parameters or built in types such as AWS::StackName
inside the UserData.基本上,您不能在 UserData 中直接引用参数或内置类型,例如
AWS::StackName
。 Instead you generate the UserData script concatenating the Parameter and built-in types.相反,您生成连接 Parameter 和内置类型的 UserData 脚本。 See the line
$HowDoIGetTheStackNameOrAParameter?
请参阅行
$HowDoIGetTheStackNameOrAParameter?
BEFORE之前
UserData:
!Base64 |
<powershell>
#setup an install folder
$path = "C:\temp\"
If(!(test-path $path))
{
New-Item -ItemType Directory -Force -Path $path
}
cd $path
# missing variables and assignment
# This code downloads a PS script from S3 and executes it
Copy-S3Object -BucketName $S3BucketName -key $bootstrap -LocalFile ($path + $bootstrap)
& $script -S3Name $S3BucketName -StackName $HowDoIGetTheStackNameOrAParameter?
</powershell>
AFTER之后
UserData : { "Fn::Base64" : { "Fn::Join" : ["", [
"<powershell>\n",
"$path = \"C:/temp/\"\n",
"If(!(test-path $path)) {\n",
" New-Item -ItemType Directory -Force -Path $path\n",
"}\n",
"cd $path\n",
# missing variables and assignment
# This code downloads a PS script from S3 and executes it
"Copy-S3Object -BucketName $S3BucketName -key $bootstrap -LocalFile ($path + $bootstrap)\n",
"& $script -S3Name $S3BucketName -StackName ", { "Ref" : "AWS::StackName" }, "\n",
"</powershell>\n",
"<persist>true</persist>\n",
"<runAsLocalSystem>true</runAsLocalSystem>"
That's how to get inbuilt types and its practically the same thing to get Parameters:这就是获取内置类型的方法,它实际上与获取参数相同:
{ "Ref" : "ParameterName" }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.