Skip to content
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

Best practices for handling production vs development variables #33

Closed
jcn opened this issue Apr 19, 2016 · 8 comments
Closed

Best practices for handling production vs development variables #33

jcn opened this issue Apr 19, 2016 · 8 comments

Comments

@jcn
Copy link

jcn commented Apr 19, 2016

I know that claudia can handle the deployment of different versions of code, but what is the best practice for deploying a production or a development version of the app that needs to, say, connect to a different backend service depending on which environment it is running in? A typical 12factor solution might be to use environment variables, but this really isn't supported in Lambda. How would you recommend approaching this?

EDIT: I know that API Gateway has stage variables, but it doesn't seem like Lambda has the same thing. claudiajs/claudia-api-builder#9

@gojko
Copy link
Member

gojko commented Apr 20, 2016

not sure if this is 'best practice', but my current practice is:

  1. if the event can contain an origin, no config needed. eg S3 event for file uploads contains the S3 bucket. our exporters are configured so that a bucket triggers an event for :production or :development, so the event comes to the right version, and the lambda just uses the bucket from the event to read and convert the file.
  2. if that's not enough, upload config files named after versions (eg production.json) and then use context.functionVersion to select which config to load during processing

@gojko gojko closed this as completed Apr 20, 2016
@jcn
Copy link
Author

jcn commented Apr 20, 2016

In our particular use case, our events are triggered by an SNS notification and in development they are going to be making API calls either into a live environment (production) or a sandboxed one (development), so we can't really pass in something like an S3 bucket.

For context.functionVersion I'm not sure how this would work in practice. The docs say: "If an alias is used to invoke the function, then function_version will be the version the alias points to." Doesn't this mean that context.functionVersion would be something like 8 instead of production?

@gojko
Copy link
Member

gojko commented Apr 20, 2016

alias is "production", if you invoke it with :production. if you invoke it with :8, then it will be "8", but I prefer to use named aliases when invoking, so I don't have to reconfigure source events. you can set a named alias using --version for create, update and set-version using claudia.

@jcn
Copy link
Author

jcn commented Apr 20, 2016

Oh, ok, this seems inconsistent with the docs, but I'll test it out and see what happens. Thanks.

@gojko
Copy link
Member

gojko commented Apr 20, 2016

sorry, just read that more carefully, you are right. the stuff you can use is the invokedFunctionArn

@gojko
Copy link
Member

gojko commented Apr 20, 2016

Here's an example showing how you can detect the alias: https://github.com/claudiajs/example-projects/tree/master/detecting-context

@jcn
Copy link
Author

jcn commented Apr 21, 2016

Great, thanks. Hopefully Lambda will support environment variables at some point.

@hackerunet
Copy link

is 2019,. and not sure if this is still the case, but I'm a bit lost how can I use dotenv instead of .json files as claudia docs says. Any thoughts?

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

No branches or pull requests

3 participants