Secrets

Vonage Cloud Runtime Secrets allow you to store sensitive information for use in your projects, such as API keys for third-party services. Secrets are managed through the Vonage Cloud Runtime CLI.

Creating a Secret

To create a secret, you can use the Vonage Cloud Runtime CLI secrets create command.

vcr secrets create --name $NAME --value $VALUE

So to create a secret FOO with the value bar:

vcr secrets create --name FOO --value bar

You can also add files as secrets:

vcr secrets create --name $NAME --file $FILE_PATH

Accessing your Secrets

To access a secret in your instance, you need to add it to your configuration file to expose it. Add a environment key to your configuration file with a list of the secrets you want to expose and a name to refer to them by:

Now that the secret is in your configuration file, they will be injected into your instance when you run the Vonage Cloud Runtime debugger or deploy your project. So to use the example of FOO in your application you would write:

const fooValue = process.env.FOO_SECRET;

Updating Secrets

Updating secrets works similarly to creating secrets, but to update you use vcr secrets update:

vcr secrets update --name $NAME --value $NEW_VALUE

To update the FOO example:

vcr secrets update --name FOO --value baz

Removing Secrets

Secrets can be removed using vcr secrets remove:

vcr secrets remove $NAME

To remove the FOO example:

vcr secrets remove FOO

Working with Secrets Locally

When you are debugging your project locally, you will not have access to the secrets stored on the Vonage Cloud Runtime platform. It is recommended that you create a .env file in your project directory and add your development secrets there:

export FOO=BAR
export BAZ=BAT
export X=Y

Then before you start debugging run:

source .env

The environment variables need to be set in the same shell process that you are running the Vonage Cloud Runtime debugger in.

This will export the development secrets in your current terminal shell process, allowing the debugger to access them.