Rate this page:

Deploying with the Serverless Toolkit

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.

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.

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 TWILIO_SERVERLESS_API_CONCURRENCY to a value such as 1 to avoid any requests being performed in parallel.

Deploying new code

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.

Loading Code Sample...

        Deploy a Twilio Serverless project

        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.

        Loading Code Sample...

              Deploy a Serverless project to a staging environment

              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.

              Loading Code Sample...

                    Deploy a Serverless project without 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.

                    Loading Code Sample...

                          Deploy a Serverless project with different variables

                          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

                          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.

                          Loading Code Sample...

                                Promote a build from one environment to another [serverless]

                                What's next?

                                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.

                                Rate this page:

                                Need some help?

                                We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

                                Loading Code Sample...

                                      Thank you for your feedback!

                                      Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

                                      Sending your feedback...
                                      🎉 Thank you for your feedback!
                                      Something went wrong. Please try again.

                                      Thanks for your feedback!