Skip to contentSkip to navigationSkip to topbar
On this page

Deploying with the Serverless Toolkit


(information)

This is a Twilio Labs project

This means this project is 100% open-source. You can find its source code in the Twilio Labs GitHub organization(link takes you to an external page).

We currently don't support the projects through our official support channels. But you are welcome to reach out to us on GitHub for any questions, issues or suggestions or to contribute to this project.

Learn more about Twilio Labs.

There are two ways you can use the toolkit. If you are already using the Twilio CLI, you can install it via a plugin. Alternatively, you can use the toolkit as a standalone using twilio-run via npm or another Node.js package manager.

Throughout the docs we'll reference the Twilio CLI commands.

(information)

Info

The Serverless Toolkit will perform a collection of API requests on your behalf and in order to speed things up might do so in parallel. Depending on your account it might get into the situation where you hit issues deploying due to concurrency issues.

To solve this issue, you can set the environment variable(link takes you to an external page) TWILIO_SERVERLESS_API_CONCURRENCY to a value such as 1 to avoid any requests being performed in parallel.


Deploying new code

deploying-new-code page anchor

The Serverless Toolkit tries to make deploying as seamless and with as little configuration as possible. If you have a project set-up according to the Serverless project structure, all it takes to deploy is one short command.

Deploy a Twilio Serverless project

deploy-a-twilio-serverless-project page anchor
1
# Run a basic deployment with default settings
2
twilio serverless:deploy

By default this will create a new environment for you with the following properties:

  • Domain Suffix: dev
  • Unique Name: dev-environment

You can change the environment it deploys to by passing the domain suffix of the environment into the deploy command using the --environment flag. If an environment with that domain suffix already exists, it will deploy to that one, otherwise it will create a new one.

Deploy a Serverless project to a staging environment

deploy-a-serverless-project-to-a-staging-environment page anchor
twilio serverless:deploy --environment=staging

If you don't pass any other options in, the Functions and Assets that are being deployed will be chosen based on your project structure. If you use a non-default folder name for the deployment of Assets or Functions, you can pass in the --assets-folder or --functions-folder flags to change them. Alternatively you can use the --no-assets and --no-functions flags to turn these features of completely.

Deploy a Serverless project without assets

deploy-a-serverless-project-without-assets page anchor
twilio serverless:deploy --no-assets

Additionally any variables except ACCOUNT_SID and AUTH_TOKEN will be uploaded as part of your deployment. To change the variables that are being uploaded use the --env flag to point against another .env file.

Deploy a Serverless project with different variables

deploy-a-serverless-project-with-different-variables page anchor
twilio serverless:deploy --env .env.prod

There's a lot more configuration you can do for your deployment. The best way you can find out about the various options is using the --help flag. It will list all options you have available.


Replicating an existing deployment

replicating-an-existing-deployment page anchor

Aside of deploying code to an environment by uploading everything again, you can take an existing deployment and activate it on another environment using the promote command. For example to move the same build from the dev environment to an environment with the domain suffix staging you can use the activate command.

Promote a build from one environment to another [serverless]

promote-a-build-from-one-environment-to-another-serverless page anchor
twilio serverless:promote --source-environment=dev --environment=stage

Now that you learned how you can deploy your Twilio Functions, why not learn more, like how you can locally develop and debug your Functions.

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.