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

sample-apps - CLI v2 Invalid base64 error on lambda invoke #180

Closed
Raptormstr opened this issue May 1, 2020 · 9 comments
Closed

sample-apps - CLI v2 Invalid base64 error on lambda invoke #180

Raptormstr opened this issue May 1, 2020 · 9 comments

Comments

@Raptormstr
Copy link

The AWS CLI v2 has a breaking change in which it treats a file:// CLI option as base64-encoded text.
https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html#cliv2-migration-binaryparam

This breaks the 4-invoke.sh script lambda invoke call.

aws lambda invoke --function-name $FUNCTION --payload file://event.json out.json

One fix is to add the argument --cli-binary-format raw-in-base64-out which reverts the call back to CLI v1 behavior.

@mwunderl
Copy link
Member

mwunderl commented May 5, 2020

Hi Stephen,

Thanks for your feedback. Unfortunately, adding that argument is messy and breaks the command for the v1 CLI. I wonder if there's a way to avoid using file:// completely. If you're not otherwise using file:// with base64-encoded data, I'd suggest setting the option in ~/.aws/config as mentioned in the topic you linked:

cli_binary_format=raw-in-base64-out

Thanks,
-Michael

@neelakansha85
Copy link

I ran into this same issue today. I understand the need to keep it backward compatible, would it atleast help by adding a note in the Readme doc somewhere?

I am aware that the requirements section clearly mention to use AWS CLI v1 but I would imagine most people might be already having aws cli v2 installed and may not even notice this issue until after experiencing it.

@mwunderl
Copy link
Member

mwunderl commented Jun 4, 2020

I think we can make this work by changing --payload file://event.json to --payload "$(cat event.json)". I've tested this with the v1 CLI on WSL Ubuntu Bash. Please check with your setup and let me know if it works.

Thanks,
-Michael

@neelakansha85
Copy link

Thanks for looking into this Michael.
I tried changing --payload file://event.json to --payload "$(cat events/kinesis.json)" but it doesn't necessarily work because we do not have kinesis.json file and simply ignores the payload at that time. This is equivalent to not passing --payload option as it doesn't log custom Event Records from our events.json file. It does invoke the Lambda function and log other events from the function and can be misleading.

Using --payload "$(cat events.json)" fails with the original issue error on v2 CLI since it requires payload to be base64 encoded by default.

I did notice that using --payload fileb://events.json works fine for both v1 and v2 CLI though I am not sure if this is a feature or a bug with the logic in fileb:// as I would have expected it to throw some kind of error saying the file is not a binary file.

@mwunderl
Copy link
Member

mwunderl commented Jun 4, 2020

Sorry that was a typo, I meant to say "$(cat event.json)". Sounds like it won't work though. Another option is to add cli_binary_format=raw-in-base64-out to ~/.aws/config if you use v2 of the CLI. Then it should work with the hundreds (thousands?) of existing examples that use file:// to load parameters from a JSON file.

@memark
Copy link

memark commented Feb 21, 2021

Is there a fix coming? Still getting the invalid base64 error for Python. This repo is linked to from the official AWS documentation, would be nice if it worked.

@jpascoe
Copy link

jpascoe commented Jul 28, 2021

I fixed by converting to base64

PAYLOAD=$(cat ./events/xxxxxxxx.json | base64)
aws lambda invoke --function-name $FUNCTION --payload $PAYLOAD out.json

@zhangbin0027
Copy link

zhangbin0027 commented Jun 27, 2022

The cli-binary-format option is required if you are using AWS CLI version.

aws lambda invoke --function-name $FUNCTION --cli-binary-format raw-in-base64-out --payload file://event.json out.json

@mwunderl
Copy link
Member

Updated the invoke scripts to use fileb:// instead of file:// in #450
Tested with 3 sample apps so far on WSL2 with CLI versions 1 and 2.

@mwunderl mwunderl changed the title Invalid base64 error on lambda invoke sample-apps - CLI v2 Invalid base64 error on lambda invoke Oct 31, 2023
@mwunderl mwunderl closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants