我想写使用运行时我的第一拉姆达功能“的Python 3.6”。 下面是选择在创建功能: 角色 - 选择自定义角色。 现有角色 - 拉姆达基本执行 Python代码如下:AWS LAMBDA处理程序错误 - 模块“索引”语法错误:
import json
def index_handler(event, context):
data = '{"Type": "SubscriptionConfirmation2","MessageId":
"123","SubscribeURL": "https://www.google.com"}'
data1 = json.loads(data)
print (data1['Type'])
if data1['Type'] == "SubscriptionConfirmation":
var=data1['SubscribeURL']
elif data1['Type'] == "Notification" and data1['SubscribeURL'] == var and
var != "":
var=data1['SomeOtherProperty']
else:
return "Invalid JSON input"
return var
在执行这个,我,得到如下错误:
{
"errorMessage": "Bad handler 'index_handler'"
}
日志输出:
START RequestId: 3b263d82-b58c-11e7-aa6f-37f006380a9a Version: $LATEST
Bad handler 'index_handler': not enough values to unpack (expected 2, got 1)
END RequestId: 3b263d82-b58c-11e7-aa6f-37f006380a9a
REPORT RequestId: 3b263d82-b58c-11e7-aa6f-37f006380a9a Duration: 0.58 ms
Billed Duration: 100 ms Memory Size: 1280 MB Max Memory Used: 22 MB
请让我知道如何解决这个错误,并成功运行我的第一个lambda函数?执行此之后,我的代码的目的就是让HTTPRequests的,然后读取它的JSON值(目前我已经存储在一个变量)
这是否看起来像Python语法给你?我建议你阅读官方的[Python教程](https://docs.python.org/3/tutorial/)。读一读,你会发现Python不会像这样使用'{}',也不会使用';'并且缩进是相关的! –
较早的Python代码在网上蟒蛇反编译https://repl.it/Mwpx 测试成功,但现在我已经编辑的代码按由Unglückspilz提供解决方案的主要问题。 –