[英]How to output SNS topic ARN created by CloudFormation to command line?
我有一個CloudFormation模板,該模板調用lambda函數來創建SNS主題。
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"AGS": {
"Type": "String",
"AllowedPattern": "[a-zA-Z0-9_]+"
},
"Secret": {
"Type": "String",
"AllowedPattern": "[a-zA-Z0-9_]+",
"NoEcho": true
},
"SDLC": {
"Type": "String",
"AllowedValues": [
"D",
"I",
"J",
"Q",
"S",
"U",
"P",
"C"
]
},
"Component": {
"Type": "String",
"AllowedPattern": "[a-zA-Z0-9_]+"
},
"Topic": {
"Type": "String",
"AllowedPattern": "[a-zA-Z0-9_]+"
},
"TopicLambda": {
"Type": "String",
"AllowedPattern": "[a-zA-Z0-9_-]+"
}
},
"Resources": {
"BRIDGE2ESBTOPIC": {
"Type": "Custom::EnterpriseTopic",
"Version": 1,
"Properties": {
"ServiceToken": {
"Fn::Join": [
":",
[
"arn",
"aws",
"lambda",
{
"Ref": "AWS::Region"
},
{
"Ref": "AWS::AccountId"
},
"function",
{
"Ref": "TopicLambda"
}
]
]
},
"AGS": {
"Ref": "AGS"
},
"Secret": {
"Ref": "Secret"
},
"SDLC": {
"Ref": "SDLC"
},
"Component": {
"Ref": "Component"
},
"ResourceName": {
"Ref": "Topic"
}
}
}
},
//This will only output to CloudFormation console, not to command line.
"Outputs": {
"Topic": {
"Description" : "Topic created by this template",
"Value": {"Ref": "BRIDGE2ESBTOPIC"}
}
}
}
在命令行中運行命令后,我在命令行中得到如下響應:
> aws cloudformation create-stack --stack-name stack3 --template-body file://template.json --parameters file://parameters.json
{
"StackId": "arn:aws:cloudformation:us-east-1:465257512377:stack/stack3/72747670-aa8b-11e6-85de-500c286e1a36"
}
該響應僅告訴我剛剛創建的StackId
。 有什么方法可以將僅由此CloudFormation模板創建的主題ARN輸出到命令行? 謝謝。
創建堆棧后,可以使用aws cloudformation describe-stacks --stack-name stack3
這將顯示輸出部分(在您的情況下為Topic ARN)
aws cloudformation describe-stacks\
--stack-name yourStackIDName\
--query 'Stacks[0].Outputs[0].OutputValue'\
--output text
aws cloudformation describe-stacks\
--stack-name arn:aws:cloudformation:us-east-1:465257512377:stack/stack3/72747670-aa8b-11e6-85de-500c286e1a36\
--query 'Stacks[0].Outputs[0].OutputValue'\
--output text
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.