gkrizek / bash-lambda-layer

Run Bash scripts in AWS Lambda via Layers
MIT License
428 stars 89 forks source link

aws cli commands slow; python3 runtime w/ $HOME=/tmp #14

Closed peter-t-kim closed 5 years ago

peter-t-kim commented 5 years ago

Hi @gkrizek ,

  1. Do you have any idea why the aws cli commands run so slowly using this bash-lambda-layer? On my local they take ~2 seconds but on the lambda they take ~15 seconds.

  2. Because the aws cli takes so long, I want to use Boto3 instead, but I need $HOME to be writable for gpg. How would one create a custom python3 layer with the $HOME=/tmp as is done in the bash bootstrap?

Thank you!

gkrizek commented 5 years ago
  1. I haven't compared actual CLI command times between local and in Lambda. If I had to guess, I would say it has to do with some caching and/or initialization. I'm not super familiar with the internals of the CLI, but I'd guess when running it locally your responses are getting cached at edge locations and the CLI is already initialized with everything it needs. When running in Lambda it's like a new computer each time so it might take a little extra initialization. Not to mention Cold Starts.

  2. Have you tried setting an environment variable in your Lambda configuration of HOME=/tmp. Maybe even try os.environ['HOME'] = '/tmp' in your Python code.

peter-t-kim commented 5 years ago

Yes I actually just realized I never tried manually setting the ENV vars in the console! So silly of me!!

Thanks for all the help--much appreciated.