aws-sam-cli
aws-sam-cli copied to clipboard
default template includes environment variables
Describe your idea/feature/enhancement
I would like for the generated template when running "sam init ..." to include at least one environment variable in the Lambda function, an env_vars.json with a hardcoded value, and an instruction in the generated README.md to demonstrate using it.
Proposal
I think it should include adding the files to the template, updating the serverless::function template, and updating any associated tests.
Things to consider:
- Will this require any updates to the SAM Spec It isn't changing the SAM spec, just the complexity of the boilerplate template.
Additional Details
I can pick up this work if the samcli team thinks it's worth pursuing.
Was planning something like this. Can extend it to all of the runtimes if it looks good. Also used 'real' logging instead of print statements.
https://github.com/rhboyd/aws-sam-cli/commit/b548081a3d921fe4416d062ce4eb74f27ff1b260
I actually like the idea of this for explaining a way to provide environment variables.
I do think it's important that the examples work even if --env-vars
is not provided. So we'd want the default ENV variable to work, and perhaps the file has an alternative value which also works and shows the override nature of the file.
So yes, if it works both with and without the --env-vars
option, happy to take a PR on our examples.
Awesome. I’ll send over a draft PR soon
On Aug 5, 2019, at 6:48 PM, Alex Wood [email protected] wrote:
I actually like the idea of this for explaining a way to provide environment variables.
I do think it's important that the examples work even if --env-vars is not provided. So we'd want the default ENV variable to work, and perhaps the file has an alternative value which also works and shows the override nature of the file.
So yes, if it works both with and without the --env-vars option, happy to take a PR on our examples.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
Hi @rhboyd are you still working on this ? Otherwise I can help with the issue.
Hi, I think it's helpful to add env variables in the hello world templates. I would like to contribute.
I am thinking of adding an additional key in output for the hello world examples to show where the env variables are set. let me know if this makes sense.
- environment variable not set -
sam local invoke
Invoking Container created from helloworldfunction:python3.9-v1
Building image.................
Skip pulling image and use local one: helloworldfunction:rapid-1.53.0-x86_64.
START RequestId: 5bd52e97-9a7e-456b-b4ae-74dc55254bac Version: $LATEST
END RequestId: 5bd52e97-9a7e-456b-b4ae-74dc55254bac
REPORT RequestId: 5bd52e97-9a7e-456b-b4ae-74dc55254bac Init Duration: 0.28 ms Duration: 93.36 ms Billed Duration: 94 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"statusCode": 200, "body": "{\"message\": \"hello world\", \"env_vars\": \"not set\"}"}
- environment variable set in template.yaml -
sam local invoke
Invoking Container created from helloworldfunction:python3.9-v1
Building image.................
Skip pulling image and use local one: helloworldfunction:rapid-1.53.0-x86_64.
START RequestId: c55f05d8-0ccf-448d-9a83-808b6399a855 Version: $LATEST
END RequestId: c55f05d8-0ccf-448d-9a83-808b6399a855
REPORT RequestId: c55f05d8-0ccf-448d-9a83-808b6399a855 Init Duration: 0.41 ms Duration: 111.48 ms Billed Duration: 112 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"statusCode": 200, "body": "{\"message\": \"hello world\", \"env_vars\": \"set in template\"}"}
- environment variable set in env_vars.json -
sam local invoke --env-vars env_vars.json
Invoking Container created from helloworldfunction:python3.9-v1
Building image.................
Skip pulling image and use local one: helloworldfunction:rapid-1.53.0-x86_64.
START RequestId: ec8790ca-6833-41c9-9394-6b175594c300 Version: $LATEST
END RequestId: ec8790ca-6833-41c9-9394-6b175594c300
REPORT RequestId: ec8790ca-6833-41c9-9394-6b175594c300 Init Duration: 0.17 ms Duration: 73.60 ms Billed Duration: 74 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"statusCode": 200, "body": "{\"message\": \"hello world\", \"env_vars\": \"set in env_vars.json\"}"}
Given the age, I am going to elect to close this. Our init templates have grown vastly over the years and while I believe the intent here is good requires a lot of upfront effort. Instead of doing this per init template or even an init template targeted at this specifically, it's better for us to allow customers the ability to go to our docs and get a better understanding of this. We already link out to our SAM Spec docs within the templates and explain how environments work here.
Our docs might not be enough now but it is something we are constantly improving. If something can further be improved, I would encourage future finders of this issue to submit feedback directly on our docs site through the "Provide Feedback" link at the bottom of the page.
Closing
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.