[英]AWS Lambda with Python 2.7 Error
I'm using AWS Lambda to turn on\\off EC2 instances at a specified intervals vai CloudWatch. 我正在使用AWS Lambda以指定的间隔通过CloudWatch打开/关闭EC2实例。 I write AWS Lambda code using Python 2.7 runtime and put the code: 我使用Python 2.7运行时编写AWS Lambda代码,并将代码放入:
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: 但是我想通过手动触发lambda函数来测试EC2实例的停止,在执行日志中我收到以下错误:
{
"errorMessage": "Handler 'handler' missing on module 'index'"
}
Anyone help would be appreciated. 任何人的帮助将不胜感激。
You need to rename lambda_handler
to handler
in your python script. 您需要将lambda_handler
重命名为python脚本中的handler
。 OR tell Lambda to look for the handler of lambda_handler
instead of the default handler
. 或者告诉Lambda查找lambda_handler
的处理程序,而不是默认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. 另外,您应该在函数底部添加一个return
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.