0

I'm trying to store the output of lambda function using ResultPath in input so that I can use that as a input in other states of step function but the step function cancelled within in few sec after adding ResultPath.

Lambda Function :

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 function output :

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

Step Function :

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

I'm relatively new to AWS and unable debug the issue. Can someone explain this/direct me to the right documentation?

Any help/links are highly appreciated.

1 Answer 1

1

I found the issue. It was due to the data type mismatch. The return object 'contents' is not in json format due to which it fails when step function tries to store it's output in ResultPath. Below code works for me:


   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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.