python-3.x - Get KeyValue from Cloudformation Output with Python Boto3
问题描述
I am trying to use Boto3 to print out the instance private IP address from a Cloudformation stack Output. It should be a fairly straightforward process. However my code just refuse to work.
The Outputs section of the describe_stacks response is below:
{'OutputKey': 'EC2IP', 'OutputValue': '192.168.10.10', 'Description': 'Web Server IP Address'},
{'OutputKey': 'ImageID', 'OutputValue': 'ami-0888888888888', 'Description': 'Web Server Image ID'}
I have tested my code below. It prints out nothing.
import boto3
cf_client = boto3.client('cloudformation')
stackname = 'test-instance-stack'
response = cf_client.describe_stacks(StackName=stackname)
outputs = response["Stacks"][0]["Outputs"]
for output in outputs:
keyName = output["OutputKey"]
if keyName is "EC2IP":
print(output["OutputValue"])
Though if I try
print(keyName)
It does printout EC2IP
and ImageID
So keyName in this case should match EC2IP and then print out the IP. But somehow I get nothing...
解决方案
代替:
if keyName is "EC2IP":
利用:
if keyName == "EC2IP":
推荐阅读
- ruby-on-rails - 用于用户登录的 GraphQL API 单元测试
- sql-server - 报告处理过程中发生错误
- javascript - 如何在 ReactJS 中将数据传递给 Material UI 'Table' 组件
- java - EventBus.localConsumer 是否需要 MessageConsumer.completionHandler?
- sycl - 读取缓冲区拥有的访问内存
- caching - 无法将 LazyCache 与 Suave 的 WebPart 一起使用
- azureservicebus - 如何查看转发到特定队列的所有 Azure 服务总线订阅
- swift - 在 Swift 中初始化类的属性
- sql - Oracle 12.1 JSON SQL 命令
- java - 管理员和员工不能在同一域但不同的 URL 上同时登录