如何使用 Python boto3 检索 VPC ID 和子网 ID?
How to Retrieve VPC ID and Subnet ID Using Python boto3?
我希望看到一个 python 脚本,它可以在部署堆栈后获取 VPC ID 和子网 ID。
要获取的信息:
我试过使用 boto3,但它似乎不起作用。
非常感谢任何帮助。
如 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
)
我希望看到一个 python 脚本,它可以在部署堆栈后获取 VPC ID 和子网 ID。
要获取的信息:
我试过使用 boto3,但它似乎不起作用。 非常感谢任何帮助。
如 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
)