Lambda invoke command with inline payload depends on the AWS CLI version (v1 vs v2)
Closed this issue · 2 comments
example with version 1 fails
$ awslocal lambda invoke --function-name localstack-lambda-url-example --payload '{"body": "{\"num1\": \"10\", \"num2\": \"10\"}" }' output.txt
An error occurred (ServiceException) when calling the Invoke operation (reached max retries: 2): Internal error while executing lambda
With version 2
awslocal lambda invoke --function-name localstack-lambda-url-example --cli-binary-format raw-in-base64-out --payload '{"body": "{\"num1\": \"10\", \"num2\": \"10\"}" }' output.txt
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
from https://docs.localstack.cloud/user-guide/aws/lambda/#migrating-to-lambda-v2
Hi @tyoc213,
I am unable to reproduce the reported issue. Could you please confirm that you are using AWS CLI v1 when you run v1 of the command?
$ aws --version
aws-cli/1.29.35 Python/3.10.12 Linux/5.15.90.1-microsoft-standard-WSL2 botocore/1.31.35
$ awslocal --version
aws-cli/1.29.35 Python/3.10.12 Linux/5.15.90.1-microsoft-standard-WSL2 botocore/1.31.35
Hi @tyoc213
This error only occurs when running the command for the AWS CLI v1
using the AWS CLI v2
:
aws2 --version
aws-cli/2.13.18 Python/3.11.5 Darwin/22.6.0 source/arm64 prompt/off
aws2 lambda invoke --function-name localstack-lambda-url-example \
--payload '{"body": "{\"num1\": \"10\", \"num2\": \"10\"}" }' \
--profile localstack \
output.txt
An error occurred (ServiceException) when calling the Invoke operation (reached max retries: 0): Internal error while executing lambda
👉 Please use the correct command depending on your version of the AWS CLI.
The error message against real AWS differs from LocalStack:
botocore.errorfactory.InvalidRequestContentException: An error occurred (InvalidRequestContentException) when calling the Invoke operation: Could not parse request body into json: Could not parse payload into json: Invalid UTF-8 start byte 0x87
at [Source: (byte[])"n�r���I�mt"; line: 1, column: 3]
I created a PR to improve this error message in LocalStack: localstack/localstack#9170
I created a PR in the LocalStack documentation to make all Lambda invoke commands with inline payloads compatible with AWS CLI v2 by showing the tabpane with both options: #825
Using the correct command/CLI version resolves this issue and the linked PRs improve the experience around it. Closing. Please let us know @tyoc213 if any issue persists.