Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

312
Visualizações
Amazon AWS CLI not allowing valid JSON in payload parameter

I am getting an error when I try and invoke a lambda function from the AWS CLI. I am using version 2 of the CLI. I understand that I should pass the --payload argument as a string containing a JSON object.

aws lambda invoke --function-name testsms  --invocation-type Event --payload '{"key": "test"}' response.json 

I get the following error:

Invalid base64: "{"key": "test"}"

I have tried all sorts of variants for the JSON escaping characters etc. I have also tried to use the file://test.json option I receive the same error.

over 4 years ago · Santiago Trujillo
5 Respostas
Responde à pergunta

0

Looks like awscli v2 requires some parameters be base64-encoded.

By default, the AWS CLI version 2 now passes all binary input and binary output parameters as base64-encoded strings. A parameter that requires binary input has its type specified as blob (binary large object) in the documentation.

The payload parameter to lamba invoke is one of these blob types that must be base64-encoded.

--payload (blob) The JSON that you want to provide to your Lambda function as input.

One solution is to use openssl base64 to encode your payload.

echo '{"key": "test"}' > clear_payload  
openssl base64 -out encoded_payload -in clear_payload
aws lambda invoke --function-name testsms  --invocation-type Event --payload file://~/encoded_payload response.json
over 4 years ago · Santiago Trujillo Relatório

0

As @MCI said, AWS V2 defaults to base 64 input. For your case to work, simply add a --cli-binary-format raw-in-base64-out parameter to your command, so it'd be

aws lambda invoke --function-name testsms \
    --invocation-type Event \
    --cli-binary-format raw-in-base64-out \
    --payload '{"key": "test"}' response.json
over 4 years ago · Santiago Trujillo Relatório

0

This solution worked for me and I find it simpler than having to remember/check the man page for the correct flags each time.

aws lambda invoke --function-name my_func --payload $(echo "{\"foo\":\"bar\"}" | base64) out
over 4 years ago · Santiago Trujillo Relatório

0

Firstly, a string is a valid json.

In my case I had this problem

$ aws --profile diegosasw lambda invoke --function-name lambda-dotnet-function --payload "Just Checking If Everything is OK" out

An error occurred (InvalidRequestContentException) when calling the Invoke operation: Could not parse request body into json: Could not parse payload into json: Unrecognized token 'Just': was expecting ('true', 'false' or 'null')
 at [Source: (byte[])"Just Checking If Everything is OK"; line: 1, column: 6]

and it turns out the problem was due to the AWS CLI trying to convert it to JSON. Escaping the double quotes did the trick

$ aws --profile diegosasw lambda invoke --function-name lambda-dotnet-function --payload "\"Just Checking If Everything is OK\"" out
{
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"
}
over 4 years ago · Santiago Trujillo Relatório

0

In Windows, I have tried the following, which worked for me

aws lambda invoke --function-name testsms  --invocation-type Event --cli-binary-format raw-in-base64-out --payload {\"key\": \"test\"} response.json 

Note that, added --cli-binary-format raw-in-base64-out in the command and escaped " to \" in payload

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda