如何将CloudFormation创建的SNS主题ARN输出到命令行?
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
这将显示输出部分(在您的情况下是主题 ARN)
Describe Stacks with the query option,将是最直接的路径。
示例
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
我有一个 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
这将显示输出部分(在您的情况下是主题 ARN)
Describe Stacks with the query option,将是最直接的路径。
示例
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