我收到以下错误:
"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"