【问题标题】:AWS stepfunctions - passing and reading variables from lambda functionAWS stepfunctions - 从 lambda 函数传递和读取变量
【发布时间】:2020-12-29 05:47:27
【问题描述】:

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

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

我想返回的是这样的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对象构造成字符串到body的各种方式,例如

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

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

找不到字段“$.bucket”的 JsonPath 参数 输入 '{"statusCode": 200, "body": "{\"version\": \"v0-1\", \"桶\": \"sagemaker-us-west-2-removed\"}"}'"

我应该如何构造 lambda 输出以及相应的阶跃函数变量以使值通过?同样,我希望 lambda 告诉 step 函数使用了哪个桶和版本,然后让 step 函数将这些值插入到 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\\\"}\"}'"
}

【问题讨论】:

  • versionbucket 是什么数据类型?该文件指出If the handler returns objects that can't be serialized by json.dumps, the runtime returns an error.
  • 它们是字符串。使用错误消息进行更新

标签: json amazon-web-services amazon-s3 aws-lambda aws-step-functions


【解决方案1】:

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

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

我可以用 $.bucket, $.version 很好地访问它们

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    • 2022-07-21
    • 2018-07-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多