Parameters
Serverless Cloud allows developers to define parameters (a.k.a. secrets) and pass those parameters to the Serverless Cloud apps in runtime. All the parameters are encrypted both at transit and at rest and can only be decrypted by your application.
Parameter Scopes
For software organizations, some parameters are organization-wide while some of them are specific to an application. Besides, an application will probably use a different value of a parameter for production and for dev environments. To achieve all of this effortlessly, there are three different scopes for the parameters on Serverless Cloud.
Organization-level parameters are defined under Organization Settings in Serverless Cloud Dashboard. Every app and every instance of the organization will inherit those parameters automatically. Organization-level parameters can be overridden in the app and instance level. For example; you might have a key for the shared MongoDB instance of all apps. You can define the access token to MongoDB organization-wide and you can override this parameter for the production instances.
App-level parameters are defined under App Settings for each application. This is useful when you need to define a secret that needs to be used by all instances of a single app. For example; you can define the STRIPE_KEY for all instances of the billing app and they will be good to go. Note that you can add a friendly name and description for your parameters. Those are useful when you make your application public or forkable.
You can also override the organization-level params here if you need it.
Instance-level parameters are the summation of org-level parameters and app-level parameters. Instance-level parameters can be regarded as the environment variables passed into your application. You can always override the params inherited at an instance level after defining them at the org/app level. Most common use case is to override the parameters that are only used for production instances.
Note that when you edit a parameter value in Serverless Cloud Dashboard, all the changes will be applied to all running instances that use the parameter. You don't need to restart the applicaiton to flush the values.
Reserved Parameters
Serverless Cloud reserves some of the parameter keys that are automatically populated by our runtime engine. The following parameters below are already used by Serverless Cloud and developers are prevented to pick these as the key.
KEY | Value |
---|---|
ORG_NAME | The organization that application belongs to |
APP_NAME | The name of the application |
INSTANCE_NAME | The name of the instance that application runs on |
CLOUD_URL | The URL of the application generated by Serverless Cloud |
Reading parameters programmatically
Developers can access the params injected to the runtime by using the param
interface. Note that Serverless Cloud allows only reading the parameters programmatically. To make change on any parameter, visit Serverless Cloud Dashboard.
const { api, params } = require("@serverless/cloud");
// your params are available at params.KEY
api.get("/", (req, res) => {
console.log(params.KEY);
// reading reserved parameters is same as reading the custom parameters
console.log(params.CLOUD_URL);
});