Use Functions and Assets with Twilio Regions
Legal information
Functions and Assets in IE1 are not PCI compliant or HIPAA Eligible Services and should not be used in workflows that are subject to HIPAA or PCI.
You can use Functions and Assets in Twilio's Ireland (IE1) Region for EU data residency. Functions and Assets in IE1 work the same way they do in US1, with the differences called out on this page. For the complete list of Twilio Regions and product availability, see Regional product and feature availability.
To use Functions and Assets in IE1, complete the following steps:
-
In the Twilio Console, use the region selector to switch to Ireland (IE1). When you set the Console to the IE1 region, created Services only run in IE1.
-
Use Region-specific credentials. Twilio isolates its Regions, so a US1 Auth Token or API key doesn't work when you target IE1. For details, see Manage Regional API Credentials.
- In the Console, go to API keys & tokens.
- Change the region selector to Ireland (IE1).
- Find your IE1 Auth Token.
- Create API keys with the Console region selector set to Ireland (IE1). Any keys you create only work in IE1.
-
Send Serverless API requests to the
dublinedge with this base URL:Resource Base URL Serverless API serverless.dublin.ie1.twilio.com Using the Twilio CLI, sign in with the IE1 region and the
dublinedge.twilio login --region ie1 --edge dublinUsing a Twilio helper library, pass both the region and the edge when you create the client. In Node.js:
const client = require('twilio')(accountSid, authToken, { region: 'ie1', edge: 'dublin' });
Info
For the @twilio-labs/serverless-api library, you can pass region and edge when you initialize the client.
To deploy a Service to IE1 with the Twilio CLI, complete the following steps:
- Make sure that you have the Twilio CLI and version 3.1.2 or later of the Serverless Toolkit plugin installed.
- Create an IE1 profile by signing in with the IE1 region and the
dublinedge, as described in Configure your account for IE1. - If you don't already have a Service, create and develop one. Otherwise, skip to the next step.
- Deploy your Service with the Serverless Toolkit, and specify the profile for IE1:
twilio serverless:deploy -p <YOUR_REGIONAL_PROFILE_NAME>.
Info
If you use twilio-run, or if you want to pass credentials directly into your deployment command, you can use the --region flag. For example:
1twilio serverless:deploy \2--region=ie1 \3--username=<YOUR_TWILIO_REGIONAL_API_KEY> \4--password=<YOUR_TWILIO_REGIONAL_API_SECRET>
To host a Service in multiple Regions, you must deploy to each Region individually. The Console can't deploy a Service to multiple Regions at once. To use different environment variables for each Region, add your Account SID and the Region to the projects section of your .twilioserverlessrc configuration file. For example:
1{2"projects": {3"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:us1": {4"env": ".env"5},6"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:ie1": {7"env": ".env.ie1"8}9}10}
Warning
Deployments that use dependencies still contact the npm registry to fetch them. Twilio doesn't control whether npm fetches those dependencies from the US.
The domain of a Service includes its Edge and Region. Functions URLs with regional support use the following pattern:
<unique-name>-<random-four-digits>[-<optional-environment-suffix>].<edge>.<region>.twil.io
For example, a Service in IE1 might use ahoy-1234.dublin.ie1.twil.io.
The Runtime Handler provides Environment Variables that identify where a Function is running. You can use these in logs or any other logic:
context.TWILIO_REGIONcontext.TWILIO_EDGE
If context.TWILIO_REGION is undefined in a deployed Function, the Function is running in US1.
Protected Functions and Assets use signature validation to protect them from requests that don't originate from Twilio products and services, or from your own code that generates secure signatures.
Your Auth Token, which Twilio uses to generate these signatures, differs by Region. This means that Functions and Assets in one Region can only be triggered by Twilio products in that same Region. To send a request to a Protected Function or Asset in a different Region, generate a valid X-Twilio-Signature header based on credentials from the Region where the Function or Asset is deployed.
By default, Functions provide the Auth Token for the Region where the Function is deployed through context.AUTH_TOKEN, and use it to initialize the built-in Twilio REST Client that context.getTwilioClient() returns. The default client can only make requests to Twilio products and APIs in the same Region. A Function that runs in IE1 can't reach a product that exists only in US1 without additional credentials.
Danger
If your Function interacts with Twilio services in a Region other than where your Function is deployed, the data for those requests is transmitted to and processed or stored in that Region.
To create a Twilio client that can communicate with Twilio products in a different Region, complete the following steps:
-
In the Console, create a new API Key SID and Secret pair.
-
Add the API Key SID and Secret as environment variables to your Service. For example,
TWILIO_US1_API_KEY_SIDandTWILIO_US1_API_KEY_SECRET. -
In your Function, create a new Twilio client:
1const clientUs1 = new Twilio(2context.TWILIO_US1_API_KEY_SID,3context.TWILIO_US1_API_KEY_SECRET,4{5region: 'us1',6edge: 'ashburn',7accountSid: context.TWILIO_ACCOUNT_SID8}); -
Use this US-specific client to make requests to Twilio services in the US, even though your Function runs in another Region such as Ireland:
1clientUs1.messages.create({2from: context.US_PHONE_NUMBER,3to: 'some other US number',4body: 'Ahoy from another region!',5})6.then((message) => {7console.log({ callSid: message.sid });8return callback();9})10.catch((error) => {11console.error(error);12return callback(error);13});