【发布时间】:2020-12-09 05:04:15
【问题描述】:
我正在修改我的第一步功能,作为一个新手,我正在努力使这项工作正确。 AWS 上的文档很有帮助,但缺少我试图理解的示例。我在这里的网站上发现了几个类似的问题,但它们也没有真正回答我的问题。
我有一个工作非常简单的测试 Step Function。我有一个小的 Lambda 函数,它从 DynamoDB 中的请求中踢出带有“计数”的单行 JSON:
def lambda_handler(event, context):
"""lambda_handler
Keyword arguments:
event -- dict -- A dict of parameters to be validated.
context --
Return:
json object with the hubID from DynamoDB of the new hub.
Exceptions:
None
"""
# Prep the Boto3 resources needed
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('TransitHubs')
# By default we assume there are no new hubs
newhub = { 'Count' : 0 }
# Query the DynamoDB to see if the name exists or not:
response = table.query(
IndexName='Status-index',
KeyConditionExpression=Key('Status').eq("NEW"),
Limit=1
)
if response['Count']:
newhub['Count'] = response['Count']
return json.dumps(newhub)
正常的输出是:
{ "计数": 1 }
然后我创建了这个 Step Function:
{
"StartAt": "Task",
"States": {
"Task": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-west-2:OMGSUPERSECRET:function:LaunchNode-get_new_hubs",
"TimeoutSeconds": 60,
"Next": "Choice"
},
"Choice": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.Count",
"NumericEquals": 0,
"Next": "Failed"
},
{
"Variable": "$.Count",
"NumericEquals": 1,
"Next": "Succeed"
}
]
},
"Succeed": {
"Type": "Succeed"
},
"Failed": {
"Type": "Fail"
}
}
}
所以我启动了状态函数,我得到了这个输出:
TaskStateExited
{
"name": "Task",
"output": {
"Count": 1
}
}
ChoiceStateEntered
{
"name": "Choice",
"input": {
"Count": 1
}
}
执行失败
{
"error": "States.Runtime",
"cause": "An error occurred while executing the state 'Choice' (entered at the event id #7). Invalid path '$.Count': The choice state's condition path references an invalid value."
}
所以我的问题是:我不明白为什么这个错误消息会失败。 Choice 不应该只从 JSON 中获取该值吗?默认的“$”输入不是“输入”路径吗?
【问题讨论】:
-
在执行失败的步骤函数控制台中,当您单击
TaskLambda,然后单击“输出”选项卡时,将显示 Lambda 的实际输出。这是否显示了您期望的结构? -
谢谢,这部分是导致我弄清楚这一点的原因。我在下面记录了我的问题的答案。
标签: aws-lambda aws-step-functions