Skip to content

[Documentation] Add --cli-binary-format raw-in-base64-out for lambda invoke #351

@tingr

Description

@tingr

When I run 3-invoke.sh, or aws lambda invoke command, I get the error of Unexpected character. See below for output.

$ ./3-invoke.sh string
java-basic-function-BDN7ymVmJFhy

An error occurred (InvalidRequestContentException) when calling the Invoke operation: Could not parse request body into json: Could not parse payload into json: Unexpected character ((CTRL-CHAR, code 132)): Expected space separating root-level values
 at [Source: (byte[])"1��D�F"; line: 1, column: 3]

$ aws lambda invoke --function-name java-basic-function-BDN7ymVmJFhy --payload mystring out.json

An error occurred (InvalidRequestContentException) when calling the Invoke operation: Could not parse request body into json: Could not parse payload into json: Unexpected character ((CTRL-CHAR, code 155)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (byte[])"�+-�)�"; line: 1, column: 2]

I found this StackOverflow post that described the problem and solution: https://stackoverflow.com/questions/67977143/invoking-aws-lambda-via-cli-returns-error-could-not-parse-payload-into-json-un

I will quote the post below:

I had the issue solved by adding: --cli-binary-format raw-in-base64-out as a parameter.

According to : CLI 2 AWS DOCS

This has something to do with encoding changes from CLI 1 to CLI 2. It can also be added to to the aws config file, so you dont have to add it manually every time.

However, I am not sure why the Lambda Tutorial would not mention this, since the tutorial assumes you use CLI 2 and also guides you through the steps of the installation...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions