Cj Medina
Cj Medina

Reputation: 509

How to fix "Syntax error in module lambda_function"

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

Upvotes: 2

Views: 13909

Answers (1)

Paul Rooney
Paul Rooney

Reputation: 21609

I'm guessing it's because your are running on python3 and print is no longer a keyword. It's a function. You have to call it.

e.g.

print('stopped your instances: ' + str(instances))

If you use it like this it will work on both versions of python.

Upvotes: 2

Related Questions