- Notifications
You must be signed in to change notification settings - Fork1
Serverless Framework plugin for Twilio Runtime
License
twilio-labs/serverless-framework-integration
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This project is in the process of being moved into a monorepo. In the meantime, for any issues please open an issue atgithub.com/twilio-labs/twilio-run/issues
Serverless Framework plugin to deploy to the Twilio Runtime
- Node.js v8.10.0 (this is the runtime version supported by Twilio Functions)
- Serverless CLI v1.50.0+. You can run npm i -g serverless if you don't already have it.
- A Twilio account. If you don't have one you cansign up quickly.
- Run
serverless create -t twilio-nodejs -p my-twilio-project cd my-twilio-project- define
TWILIO_ACCOUNT_SIDandTWILIO_AUTH_TOKENasenvironment vars - run
serverless deployto deploy the service - run
serverless invoke -f hello-worldto invoke the deployedhello-worldfunction - run
serverless infoto retrieve information about your Twilio Runtime service
service:your-service# update this with your service nameprovider:name:twilio# Twilio access credentials (mandatory)config:accountSid:${env:TWILIO_ACCOUNT_SID}authToken:${env:TWILIO_AUTH_TOKEN}# Twilio runtime supports several domains# your functions and assets will be available under# -> defaulting to 'dev'environment:${env:TWILIO_RUNTIME_ENV, 'dev'}# Twilio runtime has to be added as a pluginplugins: -'@twilio-labs/serverless-twilio-runtime'functions:# Function namehello-world:# Path to the JS handler function in the project (without file extension '.js')handler:functions/hello-world# URL path of the function after deploymentpath:/hello-world-path# visibility of the function (can be "public" or "protected")access:public
To deploy, you will need either some environment variables set or manually input theaccountSid andauthToken in theprovider.config section of yourserverless.yml. You can find the credentials inthe Twilio Console.
service:your-service# update this with your service nameprovider:name:twilio# Twilio access credentials (mandatory)config:accountSid:${env:TWILIO_ACCOUNT_SID}authToken:${env:TWILIO_AUTH_TOKEN}
Note that you have to configureprovider.config with aaccountSid andauthToken property.
The Twilio runtime supports the following configuration options as of today:
# serverless.yml# Name of your serviceservice:your-service# Provider definition# all functions and assets# share the same provider configurationprovider:# Twilio runtime as your preferred providername:twilio# Auth credentials which you'll find at twilio.com/consoleconfig:accountSid:${env:TWILIO_ACCOUNT_SID}authToken:${env:TWILIO_AUTH_TOKEN}# Dependency definitions similar# to dependencies in a package.json# -> these dependencies will be available in the# Twilio Node.js runtimedependencies:asciiart-logo:'*'# Twilio runtime supports several domains# your functions and assets will be available under# -> defaulting to 'dev'environment:${env:TWILIO_RUNTIME_ENV, 'dev'}# Environment variables passed to your functions# available in the Twilio runtime via `context` function parameterenvironmentVars:MY_MESSAGE:'This is cool stuff'# Twilio runtime has to be added as a pluginplugins: -'@twilio-labs/serverless-twilio-runtime'functions:# Function namehello-world:# Path to the JS handler function in the project (without file extension '.js')handler:functions/hello-world# URL path of the function after deploymentpath:/hello-world-path# visibility of the function (can be "public" or "protected")access:publicresources:assets:# Asset nameasset-image:# path to the asset in the projectfilePath:assets/image.jpg# URL path to the asset after deploymentpath:/image.jpg# visibility of the assetaccess:public
Deploy all functions and assets defined in yourserverless.yml
$ serverless deploysls deployServerless: Packaging service...Serverless: Excluding development dependencies...Serverless: twilio-runtime: Creating ServiceServerless: twilio-runtime: Configuring "final-test" environmentServerless: twilio-runtime: Creating 2 FunctionsServerless: twilio-runtime: Uploading 2 FunctionsServerless: twilio-runtime: Creating 1 AssetsServerless: twilio-runtime: Uploading 1 AssetsServerless: twilio-runtime: Waiting for deployment.Serverless: twilio-runtime: Waiting for deployment. Current status: buildingServerless: twilio-runtime: Setting environment variablesServerless: twilio-runtime: Activating deploymentServerless: twilio-runtime: Function available at: xxx-123-dev.twil.io/hello-worldServerless: twilio-runtime: Asset available at: xxx-123-dev.twil.io/image.jpgGet information about the currently deployed runtime.
$ serverless infoService information*******Service: xxxService Sid: ZS...Environment: devEnvironment unique name: dev-environmentEnvironment Sid: ZE...Environment domain name: xxx-123-dev.twil.ioEnvironment variables: FOO: BARAssets: access: public creation date: 2019-07-25T11:03:46Z path: /image.jpg sid: ZN... url: https://xxx-123-dev.twil.io/image.jpgFunctions: access: public creation date: 2019-07-25T11:03:31Z path: /hello-world sid: ZN... url: https://xxx-123-dev.twil.io/hello-worldInvoke a deployed function by referencing its name and see the response. Define the function using--function or-f parameter.
Make sure that you deployed the service first.
$ serverless invoke --function hello-worldsls invoke -f hello-world ,--------------------------------------------------------------------------. | | | _____ _ _ _ ____ _ _ | | |_ _|_ _(_) (_) ___ | _ \ _ _ _ __ | |_(_)_ __ ___ ___ | | | | \ \ /\ / / | | |/ _ \ | |_) | | | | '_ \| __| | '_ ` _ \ / _ \ | | | | \ V V /| | | | (_) | | _ <| |_| | | | | |_| | | | | | | __/ | | |_| \_/\_/ |_|_|_|\___/ |_| \_\\__,_|_| |_|\__|_|_| |_| |_|\___| | | | | | | version 1.0.0 | | | | | `--------------------------------------------------------------------------'This project welcomes contributions from the community.
Please note that this project is released with aContributor Code of Conduct. By participating in this project you agree to abide by its terms.
About
Serverless Framework plugin for Twilio Runtime
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.