By using AWS re:Post, you agree to the Terms of Use

Failed to convert 'Body' to string S3.InvalidContent arn:aws:states:::aws-sdk:s3:getObject step function


I am a newbie so pardon my ignorance.

I am writing a very simple step function state machine that uses the AWS SDK to retrieve a file from S3.

Every time I run it the task that gets the file from S3 fails with an "S3.InvalidContent" error with "Failed to convert 'Body' to string" as the cause.

The full definition of my state machine is:

  "Comment": "A description of my state machine",
  "StartAt": "GetAudioFile",
  "States": {
    "GetAudioFile": {
      "Type": "Task",
      "Parameters": {
        "Bucket": "11123",
        "Key": "test.wav"
      "Resource": "arn:aws:states:::aws-sdk:s3:getObject",
      "End": true

The full text of the TaskFailed event is:

  "resourceType": "aws-sdk:s3",
  "resource": "getObject",
  "error": "S3.InvalidContent",
  "cause": "Failed to convert 'Body' to string"

The full text of the CloudWatch log entry with the error is:

    "id": "5",
    "type": "TaskFailed",
    "details": {
        "cause": "Failed to convert 'Body' to string",
        "error": "S3.InvalidContent",
        "resource": "getObject",
        "resourceType": "aws-sdk:s3"
    "previous_event_id": "4",
    "event_timestamp": "1651894187569",
    "execution_arn": "arn:aws:states:us-east-1:601423303632:execution:test:44ae6102-b544-3cfa-e186-181cdf331493"
  1. What am I doing wrong?
  2. How do I fix it?
  3. What additional information do you need from me?
  4. Most importantly, where can I find answers to these stupid questions so I don't have to post these stupid questions on re:Post again? (I have spent nearly a day scouring AWS docs and Googling without finding anything.)
1 Answer
Accepted Answer

Sorry you ran into this trouble. Step Functions needs the response from that API call to be serializable as JSON. State payload (what's passed between states in your State Machine) If you have a file in S3 that contains such data, you will get that back in the response payload and it will be used (after output processing) as state output from that Task. In this case, your file is a binary .wav file can't. See the link below for more on the State Machine data in the Developer Guide for Step Functions:

Given this, I'm curious what you were looking to accomplish with your workflow that involved the .wav file? Builders often use Step Functions to manage such data, but do it using "pointers" (i.e. S3 keys) in their workflow rather than loading data into the workflow state.

answered 5 months ago
    1. Is there a way I can retrieve the binary .wav encoded in a format that is serializable as text such as base64 or UTF-8?
    2. What I am trying to do is build a serverless, codeless solution that sends an email with the body from one file an S3 bucket with a wav file (which can be very large) from another S3 bucket attached. I see the following challenges: a. The SendEmail Action in the SES V2 API does not accept S3 keys as input. b. The SendEmail Action in the SES V2 does not provide an easy way to add an attachment. The only way is to manually build a properly formatted and encoded MIME message. c. There is no AWS service that I can find that codelessly handles building and encoding MIME messages. d. The size of some of the WAV file attachments exceed the 262,144 byte maximum input/output size of a step function task.
    3. What is your advice about addressing the challenges?
    4. Is my only option to use Lambda and forget about it being codeless?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions