【发布时间】:2023-01-23 00:49:01
【问题描述】:
我正在尝试使用 Python3.9 创建 lambda 脚本,它将返回 AWS 帐户中的总 ec2 服务器、它们的状态和详细信息。我的一些代码 sn-p 是 -
def lambda_handler(event, context):
client = boto3.client("ec2")
#s3 = boto3.client("s3")
# fetch information about all the instances
status = client.describe_instances()
for i in status["Reservations"]:
instance_details = i["Instances"][0]
if instance_details["State"]["Name"].lower() in ["shutting-down","stopped","stopping","terminated",]:
print("AvailabilityZone: ", instance_details['AvailabilityZone'])
print("\nInstanceId: ", instance_details["InstanceId"])
print("\nInstanceType: ",instance_details['InstanceType'])
如果我注释 AZ 详细信息,代码工作正常。如果我创建一个新函数,其中只有 AZ 参数,则返回所有 AZ。不明白为什么它在上述代码中失败。
【问题讨论】:
标签: amazon-web-services aws-lambda boto3