【问题标题】:AWS Step Function - ResultPath not working with AWS lambdaAWS Step Function - ResultPath 不适用于 AWS lambda
【发布时间】:2021-07-27 17:49:57
【问题描述】:

我正在尝试在输入中使用 ResultPath 存储 lambda 函数的输出,以便我可以将其用作步进函数的其他状态的输入,但在添加 ResultPath 后的几秒内步进函数取消。

Lambda 函数:

def lambda_handler(event, context):
    # TODO implement
    import boto3

    s3 = boto3.client('s3')
    data = s3.get_object(Bucket='test1', Key='Testing-sandbox/Test_sql_script.sql')
    contents = data['Body'].read()
    print(contents)
    return contents

Lambda 函数输出:

Response
"/* Step - 1  */ \r\nSELECT * FROM test1 LIMIT 10;\r\n/* Step - 2  */ \r\nSELECT * FROM test2 limit 10;\r\n"

阶梯函数:

{
  "StartAt": "CallFunction",
  "States": {
    "CallFunction": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-west-2:12345678:function:readFile",
      "ResultPath": "$.query",
      "End": true
    }
  }
}

我对 AWS 比较陌生,无法调试问题。有人可以解释这个/指导我找到正确的文档吗?

非常感谢任何帮助/链接。

【问题讨论】:

    标签: python python-3.x amazon-web-services aws-lambda aws-step-functions


    【解决方案1】:

    我发现了问题。这是由于数据类型不匹配。返回对象“内容”不是 json 格式,因此当 step 函数尝试将其输出存储在 ResultPath 中时它会失败。 下面的代码对我有用:

    
       s3 = boto3.resource('s3')
    
        content_object = s3.Object('test1', 'Testing-sandbox/Test_sql_script.sql')
        file_content = content_object.get()['Body'].read().decode('utf-8')
        print(file_content)
        file_content2 = str(file_content).replace('\n', ' ').replace('\r', ' ')
        print(file_content2)
        print(type(file_content2))
        qr = json.dumps(file_content2)
        print(qr)
    
        return qr
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-18
      • 2019-08-11
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多