【发布时间】:2019-12-04 02:09:39
【问题描述】:
我在检索我的 AWS NATGateway 资源的元数据时遇到问题。我似乎找不到合适的属性来检索 ID。
尝试了各种属性,例如 NAT.id,我仍在检查此处的文档 [1] [2] [3] 以希望解决问题。
[1]https://boto3.amazonaws.com/v1/documentation/api/latest/guide/migration.html
[3]https://aws.amazon.com/premiumsupport/knowledge-center/start-stop-lambda-cloudwatch/
import boto3
# Region your instances are in, e.g. 'us-east-1'
region = 'ap-southeast-1'
#instantiate
client = boto3.client('ec2',region)
ids = []
def lambda_handler(event, context):
#lists all the metadata of NAT resources having a TagKey:Schedule
#Value:OfficeHours
NATs = client.describe_nat_gateways(
Filter=[
{
'Name': 'tag:Schedule',
'Values': [
'OfficeHours',
],
},
],
)
for NAT in NATs:
print('deleted NAT gateways: ' + NAT.NatGatewayId)
# ids.append(NAT.NatGatewayId)
# client.delete_nat_gateway(NatGatewayId=ids)
一旦我检索到元数据:NatGatewayID,我应该能够通过 lambda 删除这些资源。
【问题讨论】:
-
只是补充一下,我确实在顶部包含了 import boto3
标签: python amazon-web-services aws-lambda