Skip to contentSkip to navigationSkip to topbar
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 nameTypeRequiredDescriptionChild properties
sidSID<ZE>Optional
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>Optional

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>Optional

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>Optional

The SID of the build deployed in the environment.

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

unique_namestringOptional
PII MTL: 7 days

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


domain_suffixstringOptional

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


domain_namestringOptional

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_createdstring<date-time>Optional

date_updatedstring<date-time>Optional

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>Optional

The absolute URL of the Environment resource.


linksobject<uri-map>Optional

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.

Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
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 EnvironmentLink to code sample: Create Environment
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createEnvironment() {
11
const environment = await client.serverless.v1
12
.services("ServiceSid")
13
.environments.create({
14
domainSuffix: "stage",
15
uniqueName: "staging",
16
});
17
18
console.log(environment.domainName);
19
}
20
21
createEnvironment();

Output

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
}

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
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchEnvironment() {
11
const environment = await client.serverless.v1
12
.services("ServiceSid")
13
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.fetch();
15
16
console.log(environment.sid);
17
}
18
19
fetchEnvironment();

Output

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
}

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.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function listEnvironment() {
11
const environments = await client.serverless.v1
12
.services("ServiceSid")
13
.environments.list({ limit: 20 });
14
15
environments.forEach((e) => console.log(e.sid));
16
}
17
18
listEnvironment();

Output

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 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
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function deleteEnvironment() {
11
await client.serverless.v1
12
.services("ServiceSid")
13
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.remove();
15
}
16
17
deleteEnvironment();

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.