$30 off During Our Annual Pro Sale. View Details »

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!

Dominik Kundel

August 07, 2019
Tweet

More Decks by Dominik Kundel

Other Decks in Technology

Transcript

  1. DEPLOYING WITH THE
    SERVERLESS API & CLI

    View Slide

  2. View Slide

  3. Vinci Chen
    Software Engineer
    [email protected]
    LinkedIn: linkedin.com/in/vincianechen
    Dominik Kundel
    Developer Evangelist
    [email protected]
    Twitter: @dkundel

    View Slide

  4. View Slide

  5. View Slide

  6. View Slide

  7. SERVERLESS API

    View Slide

  8. SERVICES
    • Main container for your application
    • Forms the basis of your domain
    • Can have multiple services per account

    View Slide

  9. Services
    signal-corgis
    A container for everything

    View Slide

  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

    View Slide

  11. BRING YOUR OWN LANGUAGE
    TWILIO.COM/DOCS/RUNTIME/FUNCTIONS-ASSETS-API

    View Slide

  12. ENVIRONMENTS & VARIABLES
    • Maintain testing environments instead of deploying directly to prod
    • Environment variables to keep track of configurations easily

    View Slide

  13. Services Environments Represents a single twil.io domain.
    signal-corgis-1234-dev.twil.io

    View Slide

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

    View Slide

  15. Services Variables
    Environments
    Can be referenced in Function code
    {"WORLD_GREETING": "Cloud"}

    View Slide

  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

    View Slide

  17. FUNCTIONS AND ASSETS
    • Functions: snippets of code
    • Assets: static files
    • Wrappers for the actual content

    View Slide

  18. Services
    Assets
    Functions
    Variables
    Environments
    Get Corgi Name
    Cheddar Picture
    Static file
    Code snippet

    View Slide

  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

    View Slide

  20. FUNCTION AND ASSET VERSIONS
    • Upload the content of the Function or Asset
    • Allows for references to previous Versions

    View Slide

  21. Services
    Function Versions
    Assets
    Functions
    Variables
    Environments
    Asset Versions
    Create a Version with a
    path and visibility
    /get-name
    /cheddar [private]
    [public]

    View Slide

  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

    View Slide

  23. ASSET VERSIONS
    curl -X POST https://serverless-upload.twilio.com/v1/Services/
    ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Assets/
    ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Versions \
    -F "[email protected]" \
    -F "Path=/cheddar" \
    -F "Visibility=private" \
    -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token

    View Slide

  24. BUILDS
    • Bundle Function and Asset Versions
    • Include npm packages as dependencies
    • Ex: ‘dog-names’ (dog name generator)

    View Slide

  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

    View Slide

  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"}]'

    View Slide

  27. DEPLOYMENTS
    • Connects a Build to an Environment
    • A Build can be connected to multiple Environments

    View Slide

  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

    View Slide

  29. DEPLOYMENTS
    curl -X POST https://serverless.twilio.com/v1/Services/
    ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Environments/
    ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Deployments \
    -d "BuildSid=ZBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
    -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token

    View Slide

  30. INVOCATION
    signal-corgis-1234-dev.twil.io/get-name
    signal-corgis-1234-dev.twil.io/cheddar

    View Slide

  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.

    View Slide

  32. SERVERLESS
    TOOLKIT

    View Slide

  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

    View Slide

  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

    View Slide

  35. DEMO!

    View Slide

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

    View Slide

  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?

    View Slide

  38. TEXT “IN” TO 415-289-5198
    to participate in future user research

    View Slide

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

    View Slide

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

    View Slide