SUPPORT.TWILIO.COM END OF LIFE NOTICE: This site, support.twilio.com, is scheduled to go End of Life on February 27, 2024. All Twilio Support content has been migrated to help.twilio.com, where you can continue to find helpful Support articles, API docs, and Twilio blog content, and escalate your issues to our Support team. We encourage you to update your bookmarks and begin using the new site today for all your Twilio Support needs.

Configuring a Custom Domain for Twilio Functions

Overview

Twilio Functions provides a serverless environment for deploying and running code, accessible via auto-generated .twil.io domains. Many developers and businesses want to use a branded custom domain (such as api.yourcompany.com) for their Functions endpoints. This article explains the current options, limitations, and recommended approaches for mapping a custom domain to Twilio Functions.

 

Using Custom Domains with Twilio Functions

Direct custom domain mapping is not natively supported for Twilio Functions. When you create a Functions service, Twilio automatically assigns a unique .twil.io subdomain (e.g., https://your-service-1234.twil.io). You cannot set a fixed or custom domain directly within Twilio.

 

What You Need To Know

Recommended Approaches

1. Proxying Through Your Own Domain

To use a branded domain, set up a proxy or redirect from your custom domain to your Twilio Functions endpoint:

  • API Gateway or Reverse Proxy:
    Use a service like AWS API Gateway, NGINX, or similar to route requests from your custom domain (e.g., api.yourcompany.com) to the Twilio Functions URL.
  • DNS Configuration:
    Configure a CNAME record for your subdomain pointing to your proxy or gateway.
  • SSL/HTTPS:
    Manage SSL certificates for your custom domain through your proxy or gateway. Twilio automatically provides SSL for .twil.io domains.

2. Ensuring URL Stability

  • When deploying with the Twilio Serverless Toolkit, use the --service-name flag to keep your .twil.io domain consistent across deployments:

    twilio serverless:deploy --service-name=your-service-name
    
  • As long as you deploy to the same service name, the .twil.io domain remains unchanged.

 

Limitations

  • Root Domain Mapping:
    You cannot map the root domain (e.g., yourcompany.com) directly to Twilio Functions. Use a subdomain (e.g., api.yourcompany.com).
  • No Native Custom Domain Support:
    Twilio does not currently allow direct custom domain assignment or management for Functions.

 

Example Workflow

  1. Create a Twilio Functions Service
    Deploy your code and note the .twil.io domain assigned.
  2. Set Up a Proxy
    Configure your API Gateway or reverse proxy to forward requests from your custom domain to the Twilio Functions endpoint.
  3. Update DNS
    Add a CNAME record for your subdomain pointing to your proxy.
  4. Manage SSL
    Ensure SSL certificates are in place for your custom domain.

 

Conclusion

While Twilio Functions does not natively support custom domains, you can achieve a branded URL by proxying requests through your own infrastructure. This approach gives you control over your public-facing domain and ensures URL stability, even if the underlying Twilio domain changes.

Below you will find references to useful documents:

For further questions or guidance, consult Twilio documentation or reach out to your support contact.

Have more questions? Submit a request
Powered by Zendesk