json - AWS stepfunctions - 从 lambda 函数传递和读取变量
问题描述
我正在尝试将我的 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 对象构造为正文的字符串的各种方法,例如
"{\"version\": \"" + version + "\",\"bucket\": \"" + bucket + "\"}"
但是我找不到合适的组合,而且工作一直失败。这是一个示例错误消息
字段 '$.bucket' 的 JsonPath 参数在输入 '{"statusCode": 200, "body": "{\"version\": \"v0-1\", \"bucket\ ": \"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\\\"}\"}'"
}
解决方案
在这个答案中,诀窍就是摆脱 json 转储。
return {
'statusCode': 200,
'body': {
"version": version,
"bucket": bucket
}
}
我可以用 $.bucket, $.version 很好地访问它们
推荐阅读
- kotlin - 如何将自动生成的 id 添加到云 Firestore 数据库中
- php - SQLSTATE[23000]:外键
- python-3.x - 无法理解 ray 中的并行代码输出
- java - 如何修复我的 Web 应用程序中不需要的注销?
- python - DCGAN 调试。得到只是垃圾
- hadoop - SQOOP - 将 hive 中的 ORC 格式表导出到 DB2 数据库
- java - 在我调用我的 IO 方法后没有生成文件
- ruby-on-rails - 如何通过本地网络为 Rails 开发环境资产提供服务?
- google-apps-script - 为什么突然出现 500 内部服务器错误
- asp.net - 如何从路由检索参数到过滤器?