SIGNAL '19 - Leveraging the Serverless API to manage your deployment process

SIGNAL '19 - Leveraging the Serverless API to manage your deployment process

Twilio's Serverless products allow customers to deploy business-critical telecommunications with baked-in reliability, low latency, and minimal maintenance. However, using these products requires a lot of manual work in the Twilio Console. The new Serverless API and CLI allow for more control over the deployment process for more sophisticated workflows, which can be done right in your terminal!

0722ad084c65f6177d80cf793cfbd013?s=128

Dominik Kundel

August 07, 2019
Tweet

Transcript

  1. 2.
  2. 4.
  3. 5.
  4. 6.
  5. 8.

    SERVICES • Main container for your application • Forms the

    basis of your domain • Can have multiple services per account
  6. 10.

    SERVICES curl -X POST https://serverless.twilio.com/v1/Services \ -d "IncludeCredentials=True" \ -d

    "UniqueName=signal-corgis" \ -d "FriendlyName=Corgis App" \ -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
  7. 12.

    ENVIRONMENTS & VARIABLES • Maintain testing environments instead of deploying

    directly to prod • Environment variables to keep track of configurations easily
  8. 17.

    FUNCTIONS AND ASSETS • Functions: snippets of code • Assets:

    static files • Wrappers for the actual content
  9. 19.

    FUNCTIONS AND ASSETS curl -X POST https://serverless.twilio.com/v1/Services/ ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Functions \ -d

    "FriendlyName=Get Corgi Name" \ -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token curl -X POST https://serverless.twilio.com/v1/Services/ ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Assets \ -d "FriendlyName=Cheddar Picture" \ -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
  10. 20.

    FUNCTION AND ASSET VERSIONS • Upload the content of the

    Function or Asset • Allows for references to previous Versions
  11. 21.

    Services Function Versions Assets Functions Variables Environments Asset Versions Create

    a Version with a path and visibility /get-name /cheddar [private] [public]
  12. 22.

    FUNCTION VERSIONS curl -X POST https://serverless-upload.twilio.com/v1/Services/ ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Functions/ ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Versions \ -F

    "Content=@create_name.js; type=application/javascript" \ -F "Path=/get-name" \ -F "Visibility=public" \ -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
  13. 23.

    ASSET VERSIONS curl -X POST https://serverless-upload.twilio.com/v1/Services/ ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Assets/ ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Versions \ -F

    "Content=@cheddar.jpg" \ -F "Path=/cheddar" \ -F "Visibility=private" \ -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
  14. 24.

    BUILDS • Bundle Function and Asset Versions • Include npm

    packages as dependencies • Ex: ‘dog-names’ (dog name generator)
  15. 25.

    Services Function Versions Assets Functions Builds Variables Environments Asset Versions

    Build a package with specific Function & Asset Versions /get-name /cheddar dog-names: ^2.0.0
  16. 26.

    BUILDS curl -X POST https://serverless.twilio.com/v1/Services/ ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Builds \ -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token -d

    "FunctionVersions=ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -d "AssetVersions=ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -d 'Dependencies=[{"name": "dog-names", "version": "^2.0.0"}]'
  17. 27.

    DEPLOYMENTS • Connects a Build to an Environment • A

    Build can be connected to multiple Environments
  18. 28.

    Services Function Versions Assets Functions Builds Variables Environments Asset Versions

    Deployments Activate a Build in an Environment /get-name /cheddar dog-names: ^2.0.0 active in: dev
  19. 31.

    BENEFITS OF THE API • Multiple environments without credential swapping

    • More control over how you deploy & deployment automation • Ability to incorporate complicated deployment workflows (i.e. rollbacks) • Build tools and integrations for your IDE, CI/CD workflows, etc.
  20. 33.

    SERVERLESS TOOLKIT • CLI to deal with anything Serverless •

    Node.js helper library to built your own integrations • Collection of Function & Asset templates to get you started quicker • github.com/twilio-labs/serverless-toolkit
  21. 35.
  22. 37.

    • Serverless API documentation: twilio.com/docs/runtime/functions-assets-api • Check out the Serverless

    Toolkit: github.com/twilio-labs/serverless-toolkit • Check our existing templates: github.com/twilio-labs/function-templates • Slides: twil.io/signal-serverless-api • Contribute ❤ WHAT’S NEXT?