Cloudgls Cloudgls - 1 year ago 72
Python Question

AWS Lambda function stops all instances even the filter is configured

By running this code, I want to stop only insances with the tag Class:ClassB.
After testing the function, it shuts down all instances:

import boto3

ec2 = boto3.resource('ec2')

def lambda_handler(event, context):
filters = [{'Name': 'tag:Class', 'Values':['ClassB']},{'Name': 'instance-state-name', 'Values': ['running']}]
for instance in instances:
print 'stop your instances: ' + str(instances)

Where the problem is?

Answer Source

It should be:


Your code is incorrect:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download