lambci / docker-lambda

Docker images and test runners that replicate the live AWS Lambda environment

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AWS CLI v2 invocations fail

jeanlescure opened this issue Β· comments

Describe the 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 πŸ“

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 πŸ€”

The lambda should execute normally.

Environment πŸ’»

  • OS: Arch Linux and MacOSX

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.

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)

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 πŸ˜„

Cheers πŸ‘