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. DEPLOYING WITH THE SERVERLESS API & CLI

  2. None
  3. Vinci Chen Software Engineer vchen@twilio.com LinkedIn: linkedin.com/in/vincianechen Dominik Kundel Developer

    Evangelist dkundel@twilio.com Twitter: @dkundel
  4. None
  5. None
  6. None
  7. SERVERLESS API

  8. SERVICES • Main container for your application • Forms the

    basis of your domain • Can have multiple services per account
  9. Services signal-corgis A container for everything

  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
  11. BRING YOUR OWN LANGUAGE TWILIO.COM/DOCS/RUNTIME/FUNCTIONS-ASSETS-API

  12. ENVIRONMENTS & VARIABLES • Maintain testing environments instead of deploying

    directly to prod • Environment variables to keep track of configurations easily
  13. Services Environments Represents a single twil.io domain. signal-corgis-1234-dev.twil.io

  14. ENVIRONMENTS curl -X POST https://serverless.twilio.com/v1/Services/ ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Environments \ -d "UniqueName=development" -d

    "DomainSuffix=dev" \ -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
  15. Services Variables Environments Can be referenced in Function code {"WORLD_GREETING":

    "Cloud"}
  16. ENVIRONMENT VARIABLES curl -X POST https://serverless.twilio.com/v1/Services/ ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Environments/ ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Variables \ -d

    "Key=WORLD_GREETING" -d "Value=Cloud" \ -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
  17. FUNCTIONS AND ASSETS • Functions: snippets of code • Assets:

    static files • Wrappers for the actual content
  18. Services Assets Functions Variables Environments Get Corgi Name Cheddar Picture

    Static file Code snippet
  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
  20. FUNCTION AND ASSET VERSIONS • Upload the content of the

    Function or Asset • Allows for references to previous Versions
  21. Services Function Versions Assets Functions Variables Environments Asset Versions Create

    a Version with a path and visibility /get-name /cheddar [private] [public]
  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
  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
  24. BUILDS • Bundle Function and Asset Versions • Include npm

    packages as dependencies • Ex: ‘dog-names’ (dog name generator)
  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
  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"}]'
  27. DEPLOYMENTS • Connects a Build to an Environment • A

    Build can be connected to multiple Environments
  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
  29. DEPLOYMENTS curl -X POST https://serverless.twilio.com/v1/Services/ ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Environments/ ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Deployments \ -d "BuildSid=ZBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

    \ -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
  30. INVOCATION signal-corgis-1234-dev.twil.io/get-name signal-corgis-1234-dev.twil.io/cheddar

  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.
  32. SERVERLESS TOOLKIT

  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
  34. npm install -g twilio-cli twilio plugins:install @twilio-labs/plugin-serverless twilio serverless:init signal-corgis

    cd signal-corgis HOW TO INSTALL THE SERVERLESS TOOLKIT
  35. DEMO!

  36. SERVERLESS TOOLKIT SERVERLESS FRAMEWORK INTEGRATION VS CODE INTEGRATION github.com/twilio-labs/serverless-toolkit

  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?
  38. TEXT “IN” TO 415-289-5198 to participate in future user research

  39. THANK YOU We can’t wait to see what you build!

  40. Services Function Versions Assets Functions Builds Variables Environments Asset Versions

    Deployments