我有zookeeper连接为ip1:port1,ip2:port2,ip3:port3我想在我的userdata中使用它我该怎么办?
"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",
我想在userdata中使用ZooKeeperConnect值
答案 0 :(得分:2)
您可以在userdata部分中引用ZooKeeperConnect
参数或任何其他参数:
"UserData" : {
"Fn::Base64" : {
"Fn::Join" : [ ",", [
{ "Ref" : "MyValue" },
{ "Ref" : "MyName" },
"Hello World" ] ]
}
}
以上代码段取自http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-general.html。
答案 1 :(得分:0)
基本上,您不能直接 引用参数,也不能在UserData中内置诸如AWS::StackName
之类的类型。相反,您可以生成将Parameter和内置类型连接在一起的UserData脚本。参见第$HowDoIGetTheStackNameOrAParameter?
行
之前
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>
之后
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>"
这就是获取内建类型的方法,而获取参数几乎是同一件事:
{ "Ref" : "ParameterName" }