I am working on serverless functions and my function includes API keys.
Thanks!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hey!
As we discussed recently here, similar to the standard development process, what you could do is to use a .env files with the required values.
You can template variables in project.yml from local .env files or App Platform environment variables.
You can substitute in variables from the runtime environment using the format "${SECRET_KEY}", where SECRET_KEY is the name of the variable specified in App Platform or your .env file:
environment: {}
parameters: {}
packages:
- name: sample
environment: {}
parameters: {}
annotations: {}
functions:
- name: hello
binary: false
main: ''
runtime: 'python:default'
web: true
parameters: {}
environment:
SECRET_KEY: "${SECRET_KEY}"
annotations: {}
limits: {}
That way you never commit your .env file to GitHub and you control what the values are based on your environment.
By default, the doctl serverless deploy command will look for an .env file in the same directory as the project.yml file. You can also add an --env <path to .env-formatted file> flag to specify an alternate file name and location anywhere on the filesystem. So that way you could have .env.prod and .env.dev with different values.
Alternatively, if there are bigger differences in your dev and prod environments, you can even have separate project.yaml files. For example, you could have project.staging.yml and project.live.yml, each configured with appropriate environment variables. Then when deploying using the doctl, you can use the different files by passing the --config flag:
doctl serverless deploy package-name --config project.staging.yml
For more information about the available flags, you can take a look at the documentation here:
https://docs.digitalocean.com/reference/doctl/reference/serverless/deploy/
Let me know if you have any questions and if this works for you!
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.