I'm trying to run a lambda function to stop EC2 instances. But instead I'm having errors.
tried to add return{print 'stopped your instances: ' + str(instances)} and other stuff. But it doesn't work.
Appreciate your help in pointing out the problem. Thank you
import boto3
# Region your instances are in, e.g. 'us-east-1'
region = 'ap-southeast-1'
# Instances ID: ex. ['X-XXXXXXXX', 'X-XXXXXXXX']
instances = 'i-02dc8a50ad60d1ab0'
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.stop_instances(InstanceIds=instances)
print 'stopped your instances: ' + str(instances)
Upon save and running test, it should run successfully and terminate my EC2 instance
print( 'stopped your instances: ' + str(instances))