-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
confused about: --container-env-var #2972
Comments
Neither |
hmmm — so, this should be a bug, instead of a question? if so, any idea how to change the label? |
This has to go into a Bug Report issue since it has a template you can fill out. |
@RonitRudra @autohandle Hi guys can you guys provide the full sam commands that you used, and maybe the part of your template that's key for the build? |
i'm using the pycharm awstoolkit, but here is a partial run where i copied the toolkit command over, added debug, and ran it: (base) MacBookPro2018:read david$ /usr/local/homebrew/bin/sam build ReadByIdFunction --debug --template /Users/david/Documents/amazonws/lambda/python/CrudInImage/template.yaml --build-dir /Users/david/Documents/amazonws/lambda/python/CrudInImage/.aws-sam/build --use-container --container-env-var ReadByIdFunction.GITHUB_TOKEN=TOKEN1 --container-env-var GLOBAL_GITHUB_TOKEN=GLOBAL_TOKEN there is some Layer stuff mixed in, as well, & i'm having trouble with that too |
Here's a snippet (modified for brevity) from an application I was working on which essentially needs aws credentials inside the container to be able to login against CodeArtifact to pull private packages and get published layers:
Building application using SAM CLI: The unexpected behavior being the passed environment variables not overwriting the defaults set in the |
here's the debug output from the application, sensitive values redacted:
As you can see, |
@autohandle Hey first off to answer your question, reading from the line Found Serverless function with name='HelloWorldFunction' and ImageUri='None', I think that you have defined a package type that is not "ZIP", so the CLI recognized your function to have package type "IMAGE" and was looking for an image URI, however container env vars are only supported in functions with package type "ZIP" so far. This should be the reason that you are encountering this behaviour, please make sure your package type is "ZIP" if you do not intend to provide an image URI for your function. Let me know if this doesn't answer your question! |
@RonitRudra to answer your question, you are using package type as "IMAGE" as well, so unfortunately this feature is only meant for ZIP package types so far. That is why you are experiencing this issue. If you consider using env vars for image type builds as a necessary CLI feature please open a feature request and we can have more detailed discussion on this. Sorry about the inconveniences. |
@qingchm thank you for the clarification. The documentation here was a bit misleading on what I'll draft up a feature request soon. |
Thanks for understanding ;) |
@qingchm |
Hey @autohandle that is true, it's the same behaviour for functions and layers! |
|
Setting environment variables within the
|
The only way I was able to get this working was by placing the variable in the Function's
tried using both secretsmanager and ssm with the Until this feature gets added, using an intermediate Docker container to build dependencies, and then copying the libs over to the runtime image. |
Hey, does anybody knows how to use the --container-env-var in the rest of the code ? Where can I reference them ? from the docs it seems that it's a good way to pass a github token, still can't figure out how to use it. |
This should only apply to the running function in AWS, it doesn't get passed to the local build/package step of "sam build". |
Added this comment in a few places, but I think this approach might address some use cases: #3571 (comment) |
Question
when it says:
Environment variables to pass to the build container.
if i pass via sam build:
--container-env-var ReadByIdFunction.GITHUB_TOKEN=TOKEN1 --container-env-var GLOBAL_GITHUB_TOKEN=GLOBAL_TOKEN
in the Dockerfile, should i be able to:
FROM public.ecr.aws/lambda/python:3.7
COPY appRead.py requirements.txt ./
RUN printenv
RUN echo "GLOBAL_GITHUB_TOKEN:" ${GLOBAL_GITHUB_TOKEN}
and see the environment variable?
The text was updated successfully, but these errors were encountered: