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!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
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}"
, whereSECRET_KEY
is the name of the variable specified in App Platform or your.env
file: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 theproject.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 haveproject.staging.yml
andproject.live.yml
, each configured with appropriate environment variables. Then when deploying using thedoctl
, you can use the different files by passing the--config
flag:For more information about the available flags, you can take a look at the documentation here:
Let me know if you have any questions and if this works for you!
Best,
Bobby