微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AWS StepFunctions-从Lambda函数传递和读取变量

如何解决AWS StepFunctions-从Lambda函数传递和读取变量

我正在尝试将lambda函数输出读取到step函数的变量中。 Lambda的输出

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对象构造为正文的字符串,例如

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

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

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

我应该如何构造lambda输出以及相应的step函数变量以使值通过?同样,我希望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',$.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

访问它们

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。