lambci / docker-lambda

Docker images and test runners that replicate the live AWS Lambda environment
MIT License
5.83k stars 431 forks source link

AWS CLI v2 invocations fail #314

Closed jeanlescure closed 3 years ago

jeanlescure commented 3 years ago

Describe the bug :bug:

When running docker-lambda in "stay-open" API mode, if I invoke my lambda using the AWS CLI command provided in the README, since I have AWS CLI v2.x installed, I get an Unexpected token error and my lambda function never even tries to execute.

Steps to Reproduce :memo:

Steps to reproduce the behavior:

  1. Install aws-cli v2
  2. run docker-lambda with command:
docker run --rm -e DOCKER_LAMBDA_STAY_OPEN=1 -p 9001:9001 -v \"$(pwd)\":/var/task:ro,delegated lambci/lambda:nodejs12.x index.handler
  1. Invoke lambda using aws-cli:
aws lambda invoke --endpoint http://localhost:9001 --no-sign-request --function-name myfunction --payload "{}" /tmp/output.json

Currently this generates the following error:

2020-10-08T16:26:04.897Z        95559434-1bc4-1a06-dc25-044755258eda    ERROR   Invoke Error      {"errorType":"SyntaxError","errorMessage":"Unexpected token � in JSON at position 1","stack":["SyntaxError: Unexpected token � in JSON at position 1","    at JSON.parse (<anonymous>)","    at Runtime.handleOnce (/var/runtime/Runtime.js:67:14)"]}

Expected behavior :thinking:

The lambda should execute normally.

Environment :computer:

Using Docker version 19.03.13-ce, build 4484c46d9d

Additional context

A workaround for this issue is to invoke the labda using aws-cli v1.x, but in my case this is not a sustainable solution as there are aws-cli v2 features I use in my day-to-day work activities.

mhart commented 3 years ago

The README says:

(if you're using AWS CLI v2, you'll need to add --cli-binary-format raw-in-base64-out to the above command)

mhart commented 3 years ago

This is a breaking change AWS made with v2: https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html#cliv2-migration-binaryparam

jeanlescure commented 3 years ago

Thank you for the fix and the context @mhart !

My bad for not reading the README thoroughly enough. I can corroborate that the --cli-binary-format raw-in-base64-out worked for me using aws-cli v2 :smile:

Cheers :+1: