首页 文章

AWS Lambda与Python 2.7错误

提问于
浏览
1

我正在使用AWS Lambda以指定的时间间隔关闭EC2实例vai CloudWatch . 我使用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)

作为内联代码 . 但我想通过手动触发lambda函数来测试EC2实例的停止,我在执行日志中遇到以下错误:

{
  "errorMessage": "Handler 'handler' missing on module 'index'"
}

任何帮助将不胜感激 .

1 回答

  • 2

    您需要在python脚本中将 lambda_handler 重命名为 handler . 或者告诉Lambda查找 lambda_handler 的处理程序而不是默认的 handler . 它试图执行脚本中存在的处理程序,这就是它出错的原因 .

    此外,您应该在函数的底部添加 return .

相关问题