我试着看了看互联网,但没有一个解决方案似乎适合我在python。基本上我想在阶跃函数中把一些参数从一个函数传递到下一个函数。我有点惊讶,找到一个简单的例子来做到这一点是多么困难?
所以我的第一个lambda函数的输出是:
return {"user_name" : user_name, "region" : region, "instance_id" : instance_id}
第二个lambda函数试图导入:
user_name = event["user_name"]
region = event["region"]
instance_id = event["instance_id"]
我的阶跃函数看起来像:
{
"StartAt": "CreateEC2Instance",
"States": {
"CreateEC2Instance": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "MY_ARN_1",
"Payload": {
"region": "eu-central-1",
"user_name": "MY_USERNAME"
}},
"Next": "AttachEFStoEC2"
},
"AttachEFStoEC2": {
"Type": "Task",
"Resource":"MY_ARN_2",
"End": true
}
错误是:
{
"error": "KeyError",
"cause": {
"errorMessage": "'user_name'",
"errorType": "KeyError",
"stackTrace": [
" File "/var/task/lambda_function.py", line 7, in lambda_handlern user_name = event["user_name"]n"
]
}
}
{
"StartAt": "CreateEC2Instance",
"States": {
"CreateEC2Instance": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"ResultPath": "$.randomstring",
"Parameters": {
"FunctionName": "MY_ARN_1",
"Payload": {
"region": "eu-central-1",
"user_name": "MY_USERNAME"
}},
"Next": "AttachEFStoEC2"
},
"AttachEFStoEC2": {
"Type": "Task",
"Resource":"MY_ARN_2",
"Parameters": {
"outputfromearlierfunction.$": "$.randomstring.Payload"
},
"End": true
}
,然后尝试在函数内访问,如
receivedinput = event.get('outputfromearlierfunction')
user_name = receivedinput["user_name"]
region = receivedinput["region"]
instance_id = receivedinput["instance_id"]