[英]AWS Lambda function handler missing
我创建了以下 lambda function ,它给了我以下错误。 我是 Python 的新手,我认为 function 中没有任何遗漏。 有人可以帮助使这个 function 工作吗? 谢谢
import logging
import json
import boto3
client = boto3.client('workspaces')
def handler(event, context):
response = create_workspace()
return event
def create_workspace():
response = client.create_workspaces(
Workspaces=[
{
'DirectoryId': 'd-9767328a34',
'UserName': 'Ken',
'BundleId': 'wsb-6cdbk8901',
'WorkspaceProperties': {
'RunningMode': 'AUTO_STOP'
},
'Tags': [
{
'Key': 'Name',
'Value': 'CallCentreProvisioned'
},
]
},
]
)
执行结果
{
"errorMessage": "Handler 'lambda_handler' missing on module 'lambda_function'",
"errorType": "Runtime.HandlerNotFound",
"requestId": "a09fd219-b262-4226-a04b-4d26c1b7281f",
"stackTrace": []
}
很简单。 将handler
重命名为lambda_handler
,或更改您的 lambda 配置以使用名为handler
而不是lambda_handler
的处理程序。 有评论提到了这一点,但没有给出简单的答案。
正如另一个答案似乎暗示的那样,没有充分的理由嵌套 function 。
你应该有这样的语法:
def handler_name(event, context):
// paste your code here
return some_value
我觉得你应该是这样的。 并查看命名段落。:
import logging
import json
import boto3
def lambda_handler(event, context):
client = boto3.client('workspaces')
response = create_workspace()
return event
def create_workspace():
response = client.create_workspaces(
Workspaces=[
{
'DirectoryId': 'd-9767328a34',
'UserName': 'Ken',
'BundleId': 'wsb-6cdbk8901',
'WorkspaceProperties': {
'RunningMode': 'AUTO_STOP'
},
'Tags': [
{
'Key': 'Name',
'Value': 'CallCentreProvisioned'
},
]
},
]
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.