Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Step Functions - States.StringToJson error when used in ResultSelector for S3 getObject action #10787

Open
1 task done
bilki opened this issue May 7, 2024 · 3 comments
Assignees
Labels
aws:stepfunctions AWS Step Functions status: backlog Triaged but not yet being worked on type: bug Bug report

Comments

@bilki
Copy link

bilki commented May 7, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Whenever I use the StringToJson intrinsic function (https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-intrinsic-functions.html#asl-intrsc-func-json-manipulate) in the ResultSelector of a task calling the S3 getObject action (see steps to reproduce for the definition), the step function fails to execute that function with the messages:

2024-05-07T12:41:51.176 ERROR --- [ad-77 (eval)] l.s.s.a.c.eval_component   : Exception=AttributeError, Details=["'StreamingBody' object has no attribute 'strip'"] at '(StringToJson| {'name': (StatesFunctionName| {'name': 'tringToJso', 'function_type': <StatesFunctionNameType.StringToJson: 12>}, 'arg_list': (FunctionArgumentList| {'arg_list': [(FunctionArgumentJsonPath| {'_value': <botocore.response.StreamingBody object at 0xffff23890730>, '_json_path': '$.Body'}], 'size': 1}}'
2024-05-07T12:41:51.176 ERROR --- [ad-77 (eval)] l.s.s.a.c.eval_component   : Exception=AttributeError, Details=["'StreamingBody' object has no attribute 'strip'"] at '(PayloadBindingIntrinsicFunc| {'field': 'latest', 'src': 'States.StringToJson($.Body)', 'function': (StringToJson| {'name': (StatesFunctionName| {'name': 'tringToJso', 'function_type': <StatesFunctionNameType.StringToJson: 12>}, 'arg_list': (FunctionArgumentList| {'arg_list': [(FunctionArgumentJsonPath| {'_value': <botocore.response.StreamingBody object at 0xffff23890730>, '_json_path': '$.Body'}], 'size': 1}}}'
2024-05-07T12:41:51.176 ERROR --- [ad-77 (eval)] l.s.s.a.c.eval_component   : Exception=AttributeError, Details=["'StreamingBody' object has no attribute 'strip'"] at '(PayloadTmpl| {'payload_bindings': [(PayloadBindingIntrinsicFunc| {'field': 'latest', 'src': 'States.StringToJson($.Body)', 'function': (StringToJson| {'name': (StatesFunctionName| {'name': 'tringToJso', 'function_type': <StatesFunctionNameType.StringToJson: 12>}, 'arg_list': (FunctionArgumentList| {'arg_list': [(FunctionArgumentJsonPath| {'_value': <botocore.response.StreamingBody object at 0xffff23890730>, '_json_path': '$.Body'}], 'size': 1}}}]}'
2024-05-07T12:41:51.176 ERROR --- [ad-77 (eval)] l.s.s.a.c.eval_component   : Exception=AttributeError, Details=["'StreamingBody' object has no attribute 'strip'"] at '(ResultSelector| {'payload_tmpl': (PayloadTmpl| {'payload_bindings': [(PayloadBindingIntrinsicFunc| {'field': 'latest', 'src': 'States.StringToJson($.Body)', 'function': (StringToJson| {'name': (StatesFunctionName| {'name': 'tringToJso', 'function_type': <StatesFunctionNameType.StringToJson: 12>}, 'arg_list': (FunctionArgumentList| {'arg_list': [(FunctionArgumentJsonPath| {'_value': <botocore.response.StreamingBody object at 0xffff23890730>, '_json_path': '$.Body'}], 'size': 1}}}]}}'
2024-05-07T12:41:51.176  WARN --- [ad-77 (eval)] l.s.s.a.c.s.s.execute_stat : State Task encountered an unhandled exception that lead to a State.Runtime error.
2024-05-07T12:41:51.176 ERROR --- [ad-77 (eval)] l.s.s.a.c.eval_component   : Exception=FailureEventException, Error=States.Runtime, Details={"taskFailedEventDetails": {"error": "States.Runtime", "cause": "'StreamingBody' object has no attribute 'strip'"}} at '(StateTaskServiceAwsSdk| {'comment': None, 'input_path': (InputPath| {'input_path_src': '$'}, 'output_path': (OutputPath| {'output_path': '$.s3result.latest'}, 'state_entered_event_type': 'TaskStateEntered', 'state_exited_event_type': 'TaskStateExited', 'result_path': (ResultPath| {'result_path_src': '$.s3result'}, 'result_selector': (ResultSelector| {'payload_tmpl': (PayloadTmpl| {'payload_bindings': [(PayloadBindingIntrinsicFunc| {'field': 'latest', 'src': 'States.StringToJson($.Body)', 'function': (StringToJson| {'name': (StatesFunctionName| {'name': 'tringToJso', 'function_type': <StatesFunctionNameType.StringToJson: 12>}, 'arg_list': (FunctionArgumentList| {'arg_list': [(FunctionArgumentJsonPath| {'_value': <botocore.response.StreamingBody object at 0xffff23890730>, '_json_path': '$.Body'}], 'size': 1}}}]}}, 'retry': None, 'catch': None, 'timeout': (TimeoutSeconds| {'timeout_seconds': 99999999, 'is_default': None}, 'heartbeat': None, 'parameters': (Parameters| {'payload_tmpl': (PayloadTmpl| {'payload_bindings': [(PayloadBindingValue| {'field': 'Bucket', 'value': (PayloadValueStr| {'val': 'mybucket'}}, (PayloadBindingValue| {'field': 'Key', 'value': (PayloadValueStr| {'val': 'latest.json'}}]}}, 'name': 'Read latest.json from S3', 'state_type': <StateType.Task: 16>, 'continue_with': <localstack.services.stepfunctions.asl.component.state.state_continue_with.ContinueWithNext object at 0xffff799e7690>, 'resource': (ServiceResource| {'_region': '', '_account': '', 'resource_arn': 'arn:aws:states:::aws-sdk:s3:getObject', 'partition': 'aws', 'service_name': 'aws-sdk', 'api_name': 's3', 'api_action': 'getObject', 'condition': None}}'

Expected Behavior

This task step should return the getObject action response Body field string value converted into a JSON in the step result latest field.

How are you starting LocalStack?

Custom (please describe below)

Steps To Reproduce

How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)

Testcontainers (https://github.com/testcontainers/testcontainers-scala) with 3.4.0 image

Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)

Simply create a step function with the following definition, upload a file latest.json to an S3 bucket (change bucket and file key accordingly), then execute it.

{
  "Comment": "States.StringToJson error",
  "StartAt": "Read latest.json from S3",
  "States": {
    "Read latest.json from S3": {
      "Type": "Task",
      "End": true,
      "OutputPath": "$.s3result.latest",
      "ResultPath": "$.s3result",
      "ResultSelector": {
        "latest.$": "States.StringToJson($.Body)"
      },
      "Resource": "arn:states:::aws-sdk:s3:getObject",
      "Parameters": {
        "Bucket": "bucket",
        "Key": "filekey"
      }
    }
  }
}

Environment

- OS: MacOS
- LocalStack: 3.4.0

Anything else?

No response

@bilki bilki added status: triage needed Requires evaluation by maintainers type: bug Bug report labels May 7, 2024
@localstack-bot
Copy link
Collaborator

Welcome to LocalStack! Thanks for reporting your first issue and our team will be working towards fixing the issue for you or reach out for more background information. We recommend joining our Slack Community for real-time help and drop a message to LocalStack Pro Support if you are a Pro user! If you are willing to contribute towards fixing this issue, please have a look at our contributing guidelines and our contributing guide.

@MEPalma MEPalma self-assigned this May 8, 2024
@Anze1508 Anze1508 added aws:s3 Amazon Simple Storage Service status: backlog Triaged but not yet being worked on and removed status: triage needed Requires evaluation by maintainers labels May 10, 2024
@MEPalma MEPalma added aws:stepfunctions AWS Step Functions and removed aws:s3 Amazon Simple Storage Service labels May 17, 2024
@MEPalma
Copy link
Contributor

MEPalma commented May 26, 2024

@bilki Thank you for taking the time to compile this report. We recently merged some changes that aim to address this issue. I would be grateful if you could test the new build at your earliest convenience and provide feedback on whether it resolves the problem you encountered. Thank you once again for bringing this issue forward!

@MEPalma MEPalma added status: response required Waiting for a response from the reporter and removed status: backlog Triaged but not yet being worked on labels May 26, 2024
@gerson24
Copy link

Hi @MEPalma,
I've been testing the latest version and it seems the issues with reading from S3 are resolved. However, it looks like there's a similar problem when writing to S3.

Here's the step I'm trying to execute:

{
  "StartAt": "Write manifest file",
  "States": {
    "Write manifest file": {
      "Type": "Task",
      "OutputPath": null,
      "ResultPath": null,
      "Resource": "arn:aws:states:::aws-sdk:s3:putObject",
      "Parameters": {
        "Bucket": "bucket",
        "Key.$": "States.Format('backfills/v1/{}/manifest.json', $.backfill.id)",
        "ContentType": "application/json",
        "Body": {
          "backupDateTime.$": "$.backfill.backupDateTime"
        }
      }
    }
  }
}

And the error I'm getting is:

[-1695 (eval)] l.s.s.a.c.eval_component : Exception=FailureEventException, Error=States.Runtime, Details={"taskFailedEventDetails": {"error": "States.Runtime", "cause": "'dict' object has no attribute 'tell'"}}

I'm using AWS CDK with TypeScript. Interestingly, if I build the Body with the following code: Body: { backupDateTime: '12345'} It doesn't work. However, if I change it to: Body: JSON.stringify({ backupDateTime: '12345' }) It works.

Thanks for your help!

@localstack-bot localstack-bot removed the status: response required Waiting for a response from the reporter label May 28, 2024
@Anze1508 Anze1508 added the status: backlog Triaged but not yet being worked on label May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:stepfunctions AWS Step Functions status: backlog Triaged but not yet being worked on type: bug Bug report
Projects
None yet
Development

No branches or pull requests

5 participants