![](/img/trans.png)
[英]How to use AWS CLI to deploy lambda function to specific alias or version?
[英]How do you add spaces for aws cli cloudformation deploy?
我正在嘗試將空格放入 aws cli 的 tags 參數中,如果我對其進行硬編碼,它會起作用,但如果我使用 bash 變量則不起作用。 這是怎么回事,我該如何解決?
這適用於空格:
aws cloudformation deploy \
--template-file /path_to_template/template.json \
--stack-name my-new-stack \
--tags Key1=Value1 Key2=Value2
這適用於空格但使用變量:
tags="Key1=Value1 Key2=Value2"
aws cloudformation deploy \
--template-file /path_to_template/template.json \
--stack-name my-new-stack \
--tags $tags
這適用於空格:
aws cloudformation deploy \
--template-file /path_to_template/template.json \
--stack-name my-new-stack \
--tags 'Key1=Value1' 'Key Two=Value2'
這不起作用,空格和變量:
tags="'Key1=Value1' 'Key Two=Value2'"
aws cloudformation deploy \
--template-file /path_to_template/template.json \
--stack-name my-new-stack \
--tags $tags
嘗試修復 bash 擴展,也不起作用,空格和變量:
tags="'Key1=Value1' 'Key Two=Value2'"
aws cloudformation deploy \
--template-file /path_to_template/template.json \
--stack-name my-new-stack \
--tags "$tags"
嘗試修復 bash 擴展,也不起作用,空格和變量:
tags="'Key1=Value1' 'Key Two=Value2'"
aws cloudformation deploy \
--template-file /path_to_template/template.json \
--stack-name my-new-stack \
--tags "$(printf '%q' $tags)"
錯誤:
無效參數:標簽原因:給定標簽包含無效字符(服務:AmazonSNS;狀態代碼:400;錯誤代碼:InvalidParameter;請求 ID
嘗試這個 :
tags="'Key1=Value1' 'Key Two=Value2'"
aws cloudformation deploy \
--template-file /path_to_template/template.json \
--stack-name my-new-stack \
--tags "$tags"
# ^ ^
# double quotes
學習如何在 shell 中正確引用,這非常重要:
“雙引號”包含空格/元字符和每個擴展的每個文字:
"$var"
、"$(command "$var")"
、"${array[@]}"
、"a & b"
。 對代碼或文字$'s: 'Costs $5 US'
使用'single quotes'
$'s: 'Costs $5 US'
,ssh host 'echo "$HOSTNAME"'
。 看
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/Arguments
http://wiki.bash-hackers.org/syntax/words
請你試試:
tags=('Key1=Value1' 'Key Two=Value2')
aws cloudformation deploy \
--template-file /path_to_template/template.json \
--stack-name my-new-stack \
--tags "${tags[@]}"
從https://github.com/aws/aws-cli/issues/3274竊取一些想法我能夠通過執行以下操作來使其工作
deploy=(aws cloudformation deploy
...
--tags $(cat tags.json | jq '.[] | (.Key + "=" + .Value)'))
eval $(echo ${deploy[@]})
帶有tags.json文件結構
[
{
"Key": "Name With Spaces",
"Value": "Value With Spaces"
},
{
"Key": "Foo",
"Value": "Bar"
}
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.