【问题标题】:Find running ec2 instances in all regions using python使用 python 在所有区域中查找正在运行的 ec2 实例
【发布时间】:2019-11-30 06:56:42
【问题描述】:

我想查找所有区域中所有正在运行的 Ec2 机器实例。

我已尝试执行以下代码。

导入boto3

def lambda_handler(event,context):
    regions=['us-east-1','ap-south-1']
    for j in regions:    
        ec2client = boto3.client('ec2',region_name=j)
        response = ec2client.describe_instances()
        for reservation in response["Reservations"]:
            for instance in reservation["Instances"]:
                if instance['State']['Name'] == 'running':
                    print(instance["InstanceId"])

代码仅针对列表“us-east-1”中的第一个区域执行并返回正在运行的实例,但为下一个区域提供以下错误。

"errorMessage:" 任务在 3.00 秒后超时

【问题讨论】:

    标签: python amazon-web-services aws-lambda boto3


    【解决方案1】:

    您似乎在 Lambda 函数中运行此代码。默认超时时间为 3 秒,因此您只需在 AWS 控制台中或以编程方式增加此值:

    aws lambda update-function-configuration --function-name my-function --timeout <seconds>
    

    更多信息https://docs.aws.amazon.com/lambda/latest/dg/resource-model.html

    【讨论】:

      猜你喜欢
      • 2017-06-24
      • 1970-01-01
      • 2011-05-14
      • 1970-01-01
      • 2021-08-13
      • 2013-08-02
      • 2021-11-07
      • 1970-01-01
      • 2014-11-05
      相关资源
      最近更新 更多