Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A quick intro to serverless & AWS

A quick intro to serverless & AWS

ItalianCoders DevTalks, March 31st, 2020

Danilo Poccia

March 31, 2020
Tweet

More Decks by Danilo Poccia

Other Decks in Programming

Transcript

  1. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Danilo Poccia
    Principal Evangelist, Serverless
    @danilop
    A quick intro to
    serverless & AWS

    View full-size slide

  2. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Why serverless?

    View full-size slide

  3. © 2020, Amazon Web Services, Inc. or its Affiliates.
    IT often starts with a single server…
    Single
    Server

    View full-size slide

  4. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Your customers are happy…
    Single
    Server
    Customers

    View full-size slide

  5. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Your customers are happy… until they are not
    Single
    Server
    Customers

    View full-size slide

  6. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Separate business logic from data
    Application
    Server
    Database
    Server
    Customers

    View full-size slide

  7. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Scalability & availability
    Two Application
    Servers
    Database
    Server
    Customers

    View full-size slide

  8. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Balancing traffic across multiple application server
    Two Application
    Servers
    Database
    Server
    Load
    Balancer
    Customers

    View full-size slide

  9. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Managing failover across multiple application server
    Two Application
    Servers
    Database
    Server
    Load
    Balancer
    Customers

    View full-size slide

  10. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Availability for the database
    Two Application
    Servers
    Active / Standby
    Database
    Load
    Balancer
    Customers

    View full-size slide

  11. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Availability for the database
    Two Application
    Servers
    Active / Standby
    Database
    Load
    Balancer
    Customers

    View full-size slide

  12. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Deploying on AWS...
    Two Amazon EC2
    Instances
    Amazon RDS
    Database
    Application
    Load
    Balancer
    Customers

    View full-size slide

  13. © 2020, Amazon Web Services, Inc. or its Affiliates.
    3 it’s better than 2, elasticity is better than any number
    Amazon EC2
    Auto Scaling
    Amazon RDS
    Database
    Application
    Load
    Balancer
    Customers
    Amazon Aurora
    RDS for MySQL
    RDS for PostgreSQL
    RDS for MariaDB
    RDS for Oracle
    RDS for SQL Server

    View full-size slide

  14. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Scaling the database is more difficult
    Amazon EC2
    Auto Scaling
    Amazon Aurora
    Database
    Application
    Load
    Balancer
    Customers
    Amazon Aurora
    MySQL or PostgreSQL
    compatible

    View full-size slide

  15. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Which database to use?
    Amazon EC2
    Auto Scaling
    Amazon Aurora
    Database
    Application
    Load
    Balancer
    Customers

    View full-size slide

  16. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Database freedom
    Amazon Aurora
    MySQL or PostgreSQL
    compatible
    Amazon DynamoDB
    Amazon DocumentDB
    with MongoDB compatibility
    Amazon Neptune
    (Graph)
    Amazon QLDB
    (Ledger)
    Amazon Managed
    Apache Cassandra Service

    View full-size slide

  17. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Using containers
    Amazon Aurora
    MySQL or PostgreSQL
    compatible
    Amazon DynamoDB
    Amazon DocumentDB
    with MongoDB compatibility
    Amazon Neptune
    (Graph)
    Amazon QLDB
    (Ledger)
    Amazon Managed
    Apache Cassandra Service
    Amazon Elastic
    Container Service
    Amazon Elastic
    Kubernetes Service
    Container
    Container
    Container
    Container
    Container

    View full-size slide

  18. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Tasks, Pods, and Services
    Amazon Aurora
    MySQL or PostgreSQL
    compatible
    Amazon DynamoDB
    Amazon DocumentDB
    with MongoDB compatibility
    Amazon Neptune
    (Graph)
    Amazon QLDB
    (Ledger)
    Amazon Managed
    Apache Cassandra Service
    Amazon ECS
    Amazon EKS
    Task
    Pod
    Service

    View full-size slide

  19. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Managing containers, not clusters
    Amazon Aurora
    MySQL or PostgreSQL
    compatible
    Amazon DynamoDB
    Amazon DocumentDB
    with MongoDB compatibility
    Amazon Neptune
    (Graph)
    Amazon QLDB
    (Ledger)
    Amazon Managed
    Apache Cassandra Service
    Amazon ECS
    Amazon EKS
    Task
    Pod
    Service
    AWS Fargate

    View full-size slide

  20. © 2020, Amazon Web Services, Inc. or its Affiliates.
    AWS Lambda
    Function
    Function
    Function
    What about functions?
    Something
    happens!
    Event
    Any public or
    private resource

    View full-size slide

  21. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Using functions
    AWS Lambda
    Function
    Function
    Function
    Amazon API
    Gateway
    Application
    Load Balancer
    AWS SDK
    Lambda Invoke API
    sync/async

    View full-size slide

  22. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Adding storage
    AWS Lambda
    Function
    Function
    Function
    Amazon API
    Gateway
    Application
    Load Balancer
    AWS SDK
    Lambda Invoke API
    sync/async
    Amazon S3
    Bucket
    HTML,
    CSS, JS
    Images

    View full-size slide

  23. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Adding storage and authentication
    AWS Lambda
    Function
    Function
    Function
    Amazon API
    Gateway
    Application
    Load Balancer
    AWS SDK
    Lambda Invoke API
    sync/async
    Amazon S3
    Bucket
    Amazon Cognito
    User
    Auth
    HTML,
    CSS, JS
    Images

    View full-size slide

  24. © 2020, Amazon Web Services, Inc. or its Affiliates.
    How does serverless work?
    API Gateway
    Storage
    Databases
    Analytics
    . . .
    Your
    unique
    business
    logic
    API call
    User uploads a picture
    Customer data updated
    Anomaly detected
    . . .
    Fully-managed
    services
    Events
    Functions

    View full-size slide

  25. © 2020, Amazon Web Services, Inc. or its Affiliates.
    What about availability
    and scalability?

    View full-size slide

  26. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Availability and scalability – AWS Global Infrastructure

    View full-size slide

  27. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Availability and scalability – AWS Region
    Region

    View full-size slide

  28. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Availability and scalability – Availability Zones
    Region
    Availability Zone Availability Zone Availability Zone

    View full-size slide

  29. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Availability and scalability – EC2 instances
    Region
    Availability Zone Availability Zone Availability Zone

    View full-size slide

  30. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Availability and scalability – EC2 Auto Scaling
    Region
    Availability Zone Availability Zone Availability Zone
    Auto Scaling group
    Auto Scaling group

    View full-size slide

  31. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Availability and scalability – Containers
    Region
    Availability Zone Availability Zone Availability Zone

    View full-size slide

  32. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Availability and scalability – Load Balancer
    Region
    Availability Zone Availability Zone Availability Zone

    View full-size slide

  33. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Availability and scalability – Fully managed services
    Region
    Availability Zone Availability Zone Availability Zone
    API Gateway
    Lambda Function
    DynamoDB Table
    S3 Bucket

    View full-size slide

  34. © 2020, Amazon Web Services, Inc. or its Affiliates.
    AWS operational responsibility models
    On-Premises Cloud
    Less More
    Compute Virtual Machine
    EC2 Elastic Beanstalk AWS Lambda
    Fargate
    Databases MySQL MySQL on EC2
    RDS MySQL RDS Aurora Aurora Serverless DynamoDB
    Storage Storage
    S3
    Messaging ESBs
    Amazon MQ Kinesis SQS / SNS
    Analytics
    Hadoop Hadoop on EC2 EMR Elasticsearch Service Athena

    View full-size slide

  35. © 2020, Amazon Web Services, Inc. or its Affiliates.
    A serverless demo

    View full-size slide

  36. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Serverless real-time apps – What to build?
    • Building a chat is the mandatory example for WebSockets
    • Can I build something that can help in being a “better” person?
    • Not in person communication is hard
    • Can machine learning help? Some services are super easy to use!

    View full-size slide

  37. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Let’s build a “Positive Chat” J
    • Avoid negative sentiment
    • Reject negative sentences
    • Positive sentiment gamification
    • Automatically translate between different languages
    • Extract message topics to improve searchability and discoverability
    • Create and update a chat room “tag cloud”
    • Search or filter messages by “tag”

    View full-size slide

  38. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Let’s build a “Positive Chat” J
    • Attach images to messages
    • Moderate content
    • Describe image content (objects, people, emotions)
    • Find text in images
    • Anonymize people faces
    • For all people or based on estimated age
    • Cover faces with emoticon based on actual emotions

    View full-size slide

  39. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Positive Chat – Serverless architecture
    Amazon
    DynamoDB
    Amazon
    Cognito
    Amazon API
    Gateway
    WebSocket
    connection
    PositiveChat
    Lambda function
    Connections
    table
    Conversations
    table
    Topics
    table
    Web
    browser
    AWS Cloud
    S3 bucket for
    static assets
    (HTML, CSS, JS)
    Authentication
    Authorization
    To be implemented
    Amazon
    Comprehend
    Amazon
    Translate
    Amazon
    Rekognition
    To be implemented

    View full-size slide

  40. © 2020, Amazon Web Services, Inc. or its Affiliates.
    $ wc -l positive-chat/app.js
    326 positive-chat/app.js
    $ wc -l www/index.js
    204 www/index.js
    backend + frontend ≃ 460 lines of code
    removing empty lines and comments
    https://github.com/danilop/serverless-positive-chat

    View full-size slide

  41. © 2020, Amazon Web Services, Inc. or its Affiliates.
    How to start with serverless?

    View full-size slide

  42. © 2020, Amazon Web Services, Inc. or its Affiliates.
    How to start with serverless?
    AWS Amplify
    AWS Serverless
    Application Model (SAM)
    https://aws-amplify.github.io https://aws.amazon.com/serverless/sam

    View full-size slide

  43. © 2020, Amazon Web Services, Inc. or its Affiliates.
    $ amplify

    View full-size slide

  44. © 2020, Amazon Web Services, Inc. or its Affiliates.
    $ sam

    View full-size slide

  45. © 2020, Amazon Web Services, Inc. or its Affiliates.
    More tooling available

    View full-size slide

  46. © 2020, Amazon Web Services, Inc. or its Affiliates.
    And serverless workshops J
    https://github.com/aws-samples/aws-serverless-workshops

    View full-size slide

  47. © 2020, Amazon Web Services, Inc. or its Affiliates.
    Thank you!
    @danilop Please give me your feedback! J

    View full-size slide