AWS stepfunctions - 从 lambda 函数传递和读取变量

AWS stepfunctions - passing and reading variables from lambda function

我正在尝试将我的 lambda 函数的输出读取到我的步进函数中的一个变量中。 lambdas 默认输出是

return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

我想要return的是一个像这样的json对象

{
            "version": version,
            "bucket": bucket
        }

从 lambda 传递版本和存储桶名称的位置。在我的 step 函数中,我试图捕获它并将其插入到 s3 url 中,如下所示:

"S3Uri.$": "States.Format('s3://{}/path/to/script/{}/script.py',$.bucket, $.version)"

但是,我正在为从 lambda 获得正确的输出以及如何在步进函数中获取值而苦苦挣扎。我试过了

return {
        'statusCode': 200,
        'body': json.dumps({
        "version": version,
        "bucket": bucket
    })       }

以及将 json 对象构造为正文字符串的各种方式,例如

"{\"version\": \"" + version + "\",\"bucket\": \"" + bucket + "\"}"

但是我找不到合适的组合,工作一直失败。这是一个示例错误消息

The JsonPath argument for the field '$.bucket' could not be found in the input '{"statusCode": 200, "body": "{\"version\": \"v0-1\", \"bucket\": \"sagemaker-us-west-2-removed\"}"}'"

我应该如何构建 lambda 输出,以及相应的阶跃函数变量来传递值?同样,我希望 lambda 告诉步骤函数使用了哪个存储桶和版本,然后让步骤函数将这些值插入到 s3 url 字符串中。

编辑:这是其中一次尝试的完整错误消息

{
  "error": "States.Runtime",
  "cause": "An error occurred while executing the state 'Postproc' (entered at the event id #38). The function 'States.Format('s3://{}/AAPM/AAPM_2207/prod/{}/meta/scripts/preproc/aapm-postproc.py',$.bucket, $.version)' had the following error: The JsonPath argument for the field '$.bucket' could not be found in the input '{\"statusCode\": 200, \"body\": \"{\\"version\\": \\"v0-1\\", \\"bucket\\": \\"sagemaker-us-west-2-removed\\"}\"}'"
}

在这个 answer 中,诀窍就是摆脱 json 转储。

return {
        'statusCode': 200,
        'body': {
        "version": version,
        "bucket": bucket
                 }       
        }

我可以通过 $.bucket, $.version

访问它们