“ errorType”:“ AttributeError”,“ errorMessage”:“'ec2.instancesCollection'对象没有属性'startup'”

时间:2019-10-09 09:31:41

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

我收到以下错误:

"errorType": "AttributeError", "errorMessage": "'ec2.instancesCollection' object has no attribute 'startup'"

我不知道为什么,我知道我肯定会拿起过滤器。

代码对我来说似乎正确。我有完全相同的代码,但是用于启动实例,它运行良好。

我当时想这可能是由于脚本的“启动”部分引起的,但我不确定。

代码:

#define connection
ec2 = boto3.resource('ec2')

def lambda_handler(event, context):
    # Use the filter() method of the instances collection to retrieve
    # all shutdown EC2 instances.
    filters = [{
            'Name': 'tag:NightlyShutdown',
            'Values': ['True']
        },
        {
            'Name': 'instance-state-name', 
            'Values': ['stopped']
        }
    ]

    #filter the instances
    instances = ec2.instances.filter(Filters=filters)

    #locate all running instances
    DownInstances = [instance.id for instance in instances]

    #print the instances for logging purposes
    #print DownInstances 

    #make sure there are actually instances to start. 
    if len(DownInstances) > 0:
        #perform the shutdown
        startingUp = ec2.instances.filter(InstanceIds=DownInstances).startup()
        print StartingUp
    else:
        print "Nothing to see here"

0 个答案:

没有答案