Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Environment


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.


Environment Properties

environment-properties page anchor
Property nameTypePIIDescription
sidSID<ZE>
Not PII

The unique string that we created to identify the Environment resource.

Pattern: ^ZE[0-9a-fA-F]{32}$Min length: 34Max length: 34

account_sidSID<AC>

The SID of the Account that created the Environment resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

service_sidSID<ZS>

The SID of the Service that the Environment resource is associated with.

Pattern: ^ZS[0-9a-fA-F]{32}$Min length: 34Max length: 34

build_sidSID<ZB>

The SID of the build deployed in the environment.

Pattern: ^ZB[0-9a-fA-F]{32}$Min length: 34Max length: 34

unique_namestring
PII MTL: 7 days

A user-defined string that uniquely identifies the Environment resource.


domain_suffixstring

A URL-friendly name that represents the environment and forms part of the domain name.


domain_namestring

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.


date_updatedstring<date-time>

The date and time in GMT when the Environment resource was last updated specified in ISO 8601(link takes you to an external page) format.


urlstring<uri>

The absolute URL of the Environment resource.


linksobject<uri-map>

The URLs of the Environment resource's nested resources.


Create an Environment resource

create-an-environment-resource page anchor
POST https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments

Path parameters

path-parameters page anchor
Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Service to create the Environment resource under.

Property nameTypeRequiredPIIDescription
UniqueNamestringrequired

A user-defined string that uniquely identifies the Environment resource. It can be a maximum of 100 characters.


DomainSuffixstringOptional

A URL-friendly name that represents the environment and forms part of the domain name. It can be a maximum of 16 characters.

Create Environment

create-environment page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_21
// Download the helper library from https://www.twilio.com/docs/node/install
_21
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_21
_21
// Find your Account SID and Auth Token at twilio.com/console
_21
// and set the environment variables. See http://twil.io/secure
_21
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_21
const authToken = process.env.TWILIO_AUTH_TOKEN;
_21
const client = twilio(accountSid, authToken);
_21
_21
async function createEnvironment() {
_21
const environment = await client.serverless.v1
_21
.services("ServiceSid")
_21
.environments.create({
_21
domainSuffix: "stage",
_21
uniqueName: "staging",
_21
});
_21
_21
console.log(environment.domainName);
_21
}
_21
_21
createEnvironment();

Output

_18
{
_18
"sid": "ZE00000000000000000000000000000000",
_18
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18
"service_sid": "ServiceSid",
_18
"build_sid": null,
_18
"unique_name": "staging",
_18
"domain_suffix": "stage",
_18
"domain_name": "foobar-1234-stage.twil.io",
_18
"custom_domain_name": null,
_18
"date_created": "2018-11-10T20:00:00Z",
_18
"date_updated": "2018-11-10T20:00:00Z",
_18
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000",
_18
"links": {
_18
"variables": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Variables",
_18
"deployments": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Deployments",
_18
"logs": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Logs"
_18
}
_18
}


Fetch an Environment resource

fetch-an-environment-resource page anchor
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{Sid}

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Service to fetch the Environment resource from.


SidSID<ZE>required

The SID of the Environment resource to fetch.

Pattern: ^ZE[0-9a-fA-F]{32}$Min length: 34Max length: 34
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_19
// Download the helper library from https://www.twilio.com/docs/node/install
_19
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19
_19
// Find your Account SID and Auth Token at twilio.com/console
_19
// and set the environment variables. See http://twil.io/secure
_19
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19
const authToken = process.env.TWILIO_AUTH_TOKEN;
_19
const client = twilio(accountSid, authToken);
_19
_19
async function fetchEnvironment() {
_19
const environment = await client.serverless.v1
_19
.services("ServiceSid")
_19
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19
.fetch();
_19
_19
console.log(environment.sid);
_19
}
_19
_19
fetchEnvironment();

Output

_18
{
_18
"sid": "ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18
"service_sid": "ServiceSid",
_18
"build_sid": "ZB00000000000000000000000000000000",
_18
"unique_name": "testing-environment",
_18
"domain_suffix": "testing",
_18
"domain_name": "foobar-1234-testing.twil.io",
_18
"custom_domain_name": null,
_18
"date_created": "2018-11-10T20:00:00Z",
_18
"date_updated": "2018-11-10T20:00:00Z",
_18
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000",
_18
"links": {
_18
"variables": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Variables",
_18
"deployments": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Deployments",
_18
"logs": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Logs"
_18
}
_18
}


Read multiple Environment resources

read-multiple-environment-resources page anchor
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Service to read the Environment resources from.

Property nameTypeRequiredPIIDescription
PageSizeintegerOptional

How many resources to return in each list page. The default is 50, and the maximum is 1000.

Minimum: 1Maximum: 1000

PageintegerOptional

The page index. This value is simply for client state.

Minimum: 0

PageTokenstringOptional

The page token. This is provided by the API.

List multiple Environments

list-multiple-environments page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function listEnvironment() {
_18
const environments = await client.serverless.v1
_18
.services("ServiceSid")
_18
.environments.list({ limit: 20 });
_18
_18
environments.forEach((e) => console.log(e.sid));
_18
}
_18
_18
listEnvironment();

Output

_12
{
_12
"environments": [],
_12
"meta": {
_12
"first_page_url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments?PageSize=50&Page=0",
_12
"key": "environments",
_12
"next_page_url": null,
_12
"page": 0,
_12
"page_size": 50,
_12
"previous_page_url": null,
_12
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments?PageSize=50&Page=0"
_12
}
_12
}


Delete an Environment resource

delete-an-environment-resource page anchor
DELETE https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{Sid}

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Service to delete the Environment resource from.


SidSID<ZE>required

The SID of the Environment resource to delete.

Pattern: ^ZE[0-9a-fA-F]{32}$Min length: 34Max length: 34
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_17
// Download the helper library from https://www.twilio.com/docs/node/install
_17
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_17
_17
// Find your Account SID and Auth Token at twilio.com/console
_17
// and set the environment variables. See http://twil.io/secure
_17
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_17
const authToken = process.env.TWILIO_AUTH_TOKEN;
_17
const client = twilio(accountSid, authToken);
_17
_17
async function deleteEnvironment() {
_17
await client.serverless.v1
_17
.services("ServiceSid")
_17
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_17
.remove();
_17
}
_17
_17
deleteEnvironment();


Rate this page: