Reputation: 323
I'm using AWS Lambda to turn on\off EC2 instances at a specified intervals vai CloudWatch. I write AWS Lambda code using Python 2.7 runtime and put the code:
import boto3
region = 'xxxxxx'
instances = ['i-xxxxxxxxxx']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.stop_instances(InstanceIds=instances)
print 'stopped your instances: ' + str(instances)
As the inline code. But I want to test the stopping of EC2 instance by manually trigger the lambda function where I get the following error in the execution log:
{
"errorMessage": "Handler 'handler' missing on module 'index'"
}
Anyone help would be appreciated.
Upvotes: 1
Views: 366
Reputation: 1086
You need to rename lambda_handler
to handler
in your python script. OR tell Lambda to look for the handler of lambda_handler
instead of the default handler
. It is trying to execute a handler that does exist in your script and that’s why it’s erroring.
Also, you should add a return
to the bottom of your function.
Upvotes: 3