aws / aws/aws-lambda-base-images
Docker Build with Environment Variables: entrypoint requires the handler name to be the first argument
- Dominant language
- No language data
- Stars
- 777
- Forks
- 118
- PR merge metrics
- No merged PRs in 30d
Description
Hello -
Could some documentation be added on how to give the image access to environment variables?
### This works locally
Testing locally, running the file I have with my function in it works as expected, and it gets the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION` and other environment variables just fine.
When I hardcode the variables in the function and build an image using the base image from this repo, run the image locally, and invoke the function with the command in the docs for testing images locally, the function works exactly as expected.
### The real issue
As soon as I locally try a `docker run -p 9000:8080 hello-lambda --env AWS_ACCESS_KEY_ID --env AWS_REGION --env AWS_SECRET_ACCESS_KEY`, I get the following message: "entrypoint requires the handler name to be the first argument."
Trying different formats of the above result in the same message.
### Things I've tried
I've also tried pushing the image and building the lambda in the console from the image, thinking maybe when pushed, at least the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION` might somehow be added to the container when AWS is running the image, but when I test the lambda in my account, from the logs it's clear it wasn't added at least as an environment variable. I used environment variables as specified in [these docs](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html). Even if there was some magic happening when AWS runs the image that gets those variables in there, I'd still need a way to put other environment variables in the container.
I'll note I also tried adding the environment variables through the console and apparently the way the AWS keys I'm trying to get into the container are already added from the execution role, and I tried hitting the "Test" button from an Admin role.
I've also tried a bunch of other things inspired from Docker docs that I don't think would be so helpful here. ¯\_(ツ)_/¯
### Where I'm at in this journey
What I think may be happening is that the last line of this base image `ENTRYPOINT ["/lambda-entrypoint.sh"]` changes how the image is actually run and requires treating the image differently.
I'd really like to just have my variables set up in a separate file that makes it so when I do a `docker run <...>` the container can access them, and I can override that during the docker run with the same kind of command I shared above: `docker run -p 9000:8080 hello-lambda --env AWS_ACCESS_KEY_ID --env AWS_REGION --env AWS_SECRET_ACCESS_KEY`.
Thank you for your help -
Hannah
(She/Her)
Contributor guide
Assessment
This issue has not been assessed yet.