【问题标题】:How to Retrieve VPC ID and Subnet ID Using Python boto3?如何使用 Python boto3 检索 VPC ID 和子网 ID?
【发布时间】:2021-03-31 11:09:10
【问题描述】:

我希望看到一个可以在堆栈部署后获取 VPC id 和子网 ID 的 python 脚本。

要获取的信息:

我尝试过使用 boto3,但它似乎不起作用。 非常感谢任何帮助。

【问题讨论】:

  • describe_stacks() 应包含此信息。你试过什么没用?
  • 你能上传你的代码吗?
  • 嘿,阿里巴巴。欢迎来到 Stackoverflow。请分享您对我们不起作用的代码。共享您的代码至关重要。 Stackoverflow 不存在为您编写代码,我们在这里帮助您修复您的代码。见How do I ask a good question?

标签: python amazon-web-services amazon-cloudformation boto3 amazon-eks


【解决方案1】:

正如 jordanm 提到的,您可以使用 describe_stacks() 来获取该堆栈创建的所有资源

import boto3

def lambda_handler(event, context):
    client = boto3.client('cloudformation')
    
    response = client.describe_stacks(
        StackName="eks-sample-vpc"
    )
    return print(response)

或者你可以使用describe_stack_resource()

response = client.describe_stack_resource(
    StackName="eks-sample-vpc",
    LogicalResourceId="Subnet01" #Logical ID in you template
)

【讨论】:

    猜你喜欢
    • 2017-12-03
    • 1970-01-01
    • 1970-01-01
    • 2017-03-12
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    相关资源
    最近更新 更多