Environments define the different domains your Functions and Assets are available under. You can have one environment, or you can have many, e.g., a dev, stage, and prod. You can deploy a Build to any of your Environments.
The unique string that we created to identify the Environment resource.
^ZE[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Account that created the Environment resource.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Service that the Environment resource is associated with.
^ZS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the build deployed in the environment.
^ZB[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
A user-defined string that uniquely identifies the Environment resource.
A URL-friendly name that represents the environment and forms part of the domain name.
The domain name for all Functions and Assets deployed in the Environment, using the Service unique name, a randomly-generated Service suffix, and an optional Environment domain suffix.
The date and time in GMT when the Environment resource was created specified in ISO 8601 format.
The date and time in GMT when the Environment resource was last updated specified in ISO 8601 format.
The URLs of the Environment resource's nested resources.
POST https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments
The SID of the Service to create the Environment resource under.
application/x-www-form-urlencoded
A user-defined string that uniquely identifies the Environment resource. It can be a maximum of 100 characters.
A URL-friendly name that represents the environment and forms part of the domain name. It can be a maximum of 16 characters.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createEnvironment() {11const environment = await client.serverless.v112.services("ServiceSid")13.environments.create({14domainSuffix: "stage",15uniqueName: "staging",16});1718console.log(environment.domainName);19}2021createEnvironment();
1{2"sid": "ZE00000000000000000000000000000000",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"service_sid": "ServiceSid",5"build_sid": null,6"unique_name": "staging",7"domain_suffix": "stage",8"domain_name": "foobar-1234-stage.twil.io",9"custom_domain_name": null,10"date_created": "2018-11-10T20:00:00Z",11"date_updated": "2018-11-10T20:00:00Z",12"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000",13"links": {14"variables": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Variables",15"deployments": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Deployments",16"logs": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Logs"17}18}
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{Sid}
The SID of the Environment resource to fetch.
^ZE[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function fetchEnvironment() {11const environment = await client.serverless.v112.services("ServiceSid")13.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")14.fetch();1516console.log(environment.sid);17}1819fetchEnvironment();
1{2"sid": "ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"service_sid": "ServiceSid",5"build_sid": "ZB00000000000000000000000000000000",6"unique_name": "testing-environment",7"domain_suffix": "testing",8"domain_name": "foobar-1234-testing.twil.io",9"custom_domain_name": null,10"date_created": "2018-11-10T20:00:00Z",11"date_updated": "2018-11-10T20:00:00Z",12"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000",13"links": {14"variables": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Variables",15"deployments": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Deployments",16"logs": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Logs"17}18}
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments
The SID of the Service to read the Environment resources from.
How many resources to return in each list page. The default is 50, and the maximum is 1000.
1
Maximum: 1000
The page token. This is provided by the API.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function listEnvironment() {11const environments = await client.serverless.v112.services("ServiceSid")13.environments.list({ limit: 20 });1415environments.forEach((e) => console.log(e.sid));16}1718listEnvironment();
1{2"environments": [],3"meta": {4"first_page_url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments?PageSize=50&Page=0",5"key": "environments",6"next_page_url": null,7"page": 0,8"page_size": 50,9"previous_page_url": null,10"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments?PageSize=50&Page=0"11}12}
DELETE https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{Sid}
The SID of the Environment resource to delete.
^ZE[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function deleteEnvironment() {11await client.serverless.v112.services("ServiceSid")13.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")14.remove();15}1617deleteEnvironment();