Skip to content
This repository was archived by the owner on Jan 15, 2023. It is now read-only.

"argument list too long" when passing a large custom event #64

Closed
shinichy opened this issue Jan 3, 2018 · 6 comments
Closed

"argument list too long" when passing a large custom event #64

shinichy opened this issue Jan 3, 2018 · 6 comments

Comments

@shinichy
Copy link

shinichy commented Jan 3, 2018

I debugged aws/aws-sam-cli#188 and found that a large binary data is passed as a body like below and it causes argument list too long error.

{"httpMethod":"POST","body":"<large data>","resource":"/","requestContext":{"resourcePath":"/","httpMethod":"POST","stage":"prod","identity":{"sourceIp":"127.0.0.1:49921"}},"queryStringParameters":{},"headers":{"Accept":"*/*","Content-Length":"128680","Content-Type":"application/x-www-form-urlencoded","Expect":"100-continue","User-Agent":"curl/7.54.0"},"pathParameters":null,"stageVariables":null,"path":"/"}

Is there a way to pass a large custom event?

@mhart
Copy link
Member

mhart commented Jan 3, 2018

Yes, you can use the AWS_LAMBDA_EVENT_BODY env variable instead of passing over the command line

@mhart
Copy link
Member

mhart commented Jan 3, 2018

@shinichy
Copy link
Author

shinichy commented Jan 4, 2018

I tried AWS_LAMBDA_EVENT_BODY but still I get the same error.
Looks like both command line argument and env variable have the same limitation.
https://stackoverflow.com/questions/28865473/setting-environment-variable-to-a-large-value-argument-list-too-long

I think docker-lambda needs an option to read from stdin or a file for a large json.

index.js

exports.handler = function(event, context, cb) {
  console.log(event)
  cb()
}

Generate a large json and run with it

LARGE_DATA=`printf 'a%.0s' {1..500000}`; LARGE_JSON="{\"body\": \"$LARGE_DATA\"}"; docker run -v "$PWD":/var/task -e AWS_LAMBDA_EVENT_BODY=$LARGE_JSON lambci/lambda index.handler

@franciscohanna92
Copy link

@mhart How I pass data using that env variable? I'm facing this same issue running my lambda function + API locally. It works when deployed though.

@mhart
Copy link
Member

mhart commented Mar 10, 2018

Added support for events via stdin using an DOCKER_LAMBDA_USE_STDIN env variable. So:

echo '{"some": "event"}' | docker run --rm -v "$PWD":/var/task -i -e DOCKER_LAMBDA_USE_STDIN=1 lambci/lambda

Should work on all runtimes

@shinichy
Copy link
Author

@mhart Great! Thank you!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants