检索网关资源的元数据时遇到问题。我似乎找不到合适的属性来检索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)
一旦我找回metadata:NatGatewayID,我应该可以通过lambda删除这些资源
从问题中的boto文件中:
响应是
dict
,包含NatGateways
列表。由于响应是dict
,因此不使用object.property
表示法访问响应的属性;而是object['property']
这个循环应该工作:
相关问题 更多 >
编程相关推荐