zombie apocalypse workshop 20160922 · building serverless microservices. we have to save the...

39
© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Danilo Poccia @danilop Paolo Latella @LatellaPaolo September 22 nd , 2016 Zombie Apocalypse Workshop Building Serverless Microservices

Upload: others

Post on 21-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Danilo Poccia @danilopPaolo Latella @LatellaPaolo

September 22nd, 2016

Zombie Apocalypse WorkshopBuilding Serverless Microservices

Page 2: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

We have to save the World!

Page 3: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

What to expect from this workshop

• Goal of serverless architectures• Overview of AWS Lambda• Overview of Amazon API Gateway• Workshop Breakout – Time to build!• Wrap-up/Q&A

Page 4: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Why serverless architectures?

• No servers to manage and scale• Run at scale• Respond quickly to events• Only pay for compute time that you use• Developer productivity

Page 5: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Serverless microservice architecture

Static web content served from Amazon S3

AWS Lambda

Web client

Amazon API Gateway

Page 6: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

AWS Lambda

Page 7: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Your feedback helped create Lambda!

• No direct responsibility for infrastructure resources• Quick and simple deployments• Highly available and scalable apps with zero administration• Costs that are closely aligned to application usage

Page 8: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

AWS compute offerings

Amazon EC2Resizable virtual

servers in the cloud

Amazon ECSContainer management

service for running Docker on EC2

AWS LambdaServerless compute, run

code in response to events

Page 9: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Benefits of using Lambda

Continuous ScalingNo Servers to Manage

Lambda automatically scales your application by running code in response to each trigger. Your code runs in parallel and processes each trigger individually, scaling precisely with the size of the workload.

Subsecond Metering

With Lambda, you are charged for every 100 ms your code executes and the number of times your code is triggered. You don’t pay anything when your code isn’t running.

Lambda automatically runs your code without requiring you to provision or manage servers. Just write the code and upload it to Lambda.

Page 10: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

AWS Lambda – How it works

Bring your own code• Node.js, Java, Python• Java = Any JVM based

language such as Scala, Clojure, etc.

• Bring your own libraries

Flexible invocation paths• Event or RequestResponse

invoke options• Existing integrations with

various AWS services

Simple resource model• Select memory from 128MB

to 1.5GB in 64MB steps• CPU & Network allocated

proportionately to RAM• Reports actual usage

Fine grained permissions• Uses IAM role for Lambda

execution permissions• Uses Resource policy for

AWS event sources

Page 11: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

AWS Lambda – Use Cases

Data ProcessingExecute code in

response to changes in data, shifts in system

state, or actions by users

Control SystemsCustomize responses

and response workflows to state and data

changes within AWS

BackendsExecute backend logic to handle requests for web, mobile, IoT, and 3rd APIs

Page 12: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Amazon API Gateway

Page 13: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Your feedback

Managing multiple versions and stages of an API is difficult

Monitoring third-party developers’ access is time consuming

Access authorization is a challenge

Traffic spikes create an operational burden

What if I don’t want servers at all?

Page 14: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

API Gateway - Capabilities

• Host multiple versions and stages of your APIs

• Create and distribute API keys to developers

• Leverage signature version 4 to authorize access to APIs

• Throttle and monitor requests to protect your backend

• Utilize Lambda as a backend

Page 15: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Benefits of API Gateway• Managed cache to store API responses

• Reduced latency and distributed denial of service (DDoS) protection through Amazon CloudFront

• SDK generation for iOS, Android, and JavaScript

• Swagger support

• Request and response data transformation

Page 16: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

An API call flow

Internet

Mobile apps

Websites

Services

AWS Lambda functions

AWS

API Gateway cache

Endpoints on Amazon

EC2/AWS Elastic

Beanstalk

Any other publicly accessible endpoint

Amazon CloudWatch monitoring

API Gateway

Page 17: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Amazon Cognito

Page 18: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Amazon Cognito Identity

Federated User Identities

Your users can sign-in through social identity providers such as Facebook, Twitter and SAML providers and you can control access to AWS resources from your app.

Cognito User Pools

You can easily and securely add sign-up and sign-in functionality to your mobile and web apps with a fully-managed service that scales to support 100s of millions of users.

GuestYour own auth

SAML

Page 19: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Amazon Cognito User Pools

Add user sign-up and sign-in easily to your mobile and web apps without worrying about

server infrastructure

Serverless Authentication and User Management

Verify phone numbers and email addresses and offer multi-factor

authentication

Enhanced Security Features

A simple, secure, low-cost, and fully managed

service to create and maintain a user

directory that scales to 100s of millions of users

Managed User Directory

Page 20: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Comprehensive Support for Identity Use Cases

Page 21: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

The Zombie Apocalypse Survival

Page 22: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

ZOMBIES!

Zombies have taken over major metropolitan areas. The AWS Lambda Signal Corps has built a communications system to connect remaining survivors. Come learn how AWS

Lambda provides a platform for building event-driven microservices, all without the need to provision, manage, and scale servers. In this workshop, we will introduce the basics of using AWS Lambda to run code in response to events from Amazon DynamoDB, S3, and

API Gateway. You'll work within a team to build a secure, scalable, fault-tolerant chat service with global reach from scratch using blueprints provided by us. Unfortunately, the

blueprints provided only describe a very rudimentary communications system (the engineers of the project got mysteriously ill). We are looking to you and your team to add

additional real-time life saving features (e.g., food cache locations, zombie motion detectors, undead counters) to the chat platform using Lambda functions.

Page 23: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Engineers got this far…

Page 24: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

High-level Zombie Chat Architecture

Amazon S3Static Content/Chat Web App

AWS LambdaBackend Logic

Web clientEnd user

Amazon API GatewayREST Interface

AmazonDynamoDB

Messages Data Store

Amazon Cognito User Authentication

Page 25: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Zombie Chat implementation

S3A new S3 bucket with single-page HTML5 web app

API Gateway/zombie/messages API with GET and POST methods

LambdaFunctions GetMessagesFromDynamoDB and WriteMessagesToDynamoDB

DynamoDBA ‘messages’ table to track channel, timestamp, message, and name

Page 26: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

AWS Service Flow

Internet

Activity Indicator

Chat Service

Activity

Messages

Search Service

DynamoDB Streams

ElasticsearchService

S3 Web HostingTwilio

Slack Chat

API Gateway

IoT Device

IoT Processing

Website

AWS IoT or Amazon SNS

Page 27: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Lab ArchitecturesWhat you’ll build today!

Page 28: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Setup Authentication w/ Cognito User Pools

API

User Sign-up/Sign-in1. Users authenticate to your

Cognito User Pool2. Receive temporary AWS

credentials from Identity Pool

IAM Authorization enabled on protected endpoint.

Requests from client are signed with credentials from Identity Pool

Zombie Chat

Cognito User Pool

Federated Identity Pool

Page 29: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Lab 1: Typing Indicator

Internet Typing Indicator Service

talkers/talkers

Continuous GET Request polling of Typing Indicator Service to display current ‘talkers’

Single reusable service with DynamoDB PutItem implementation

POST from Zombie chat to /talkers with Name, Channel, Timestamp when survivor types message

Zombie Chat

Page 30: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Lab 2: SMS Integration with Twilio

Internet Twilio Processing

Mobile/SMS

/message Chat Service messagesTwilio Phone

Number/twilio

Integration Response:Apache Velocity Template Language (VTL) to transform response to XML for Twilio

• Pre-process Twilio message• Convert/standardize incoming

parameters for Chat Service• HTTPS POST to Chat Service

• Design Principle: Service re-use• Single implementation of

DynamoDB PutItem

Integration Request:Apache Velocity Template Language (VTL) to transform POST parameters into JSON.

Page 31: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Lab 3: Search with Elasticsearch Service

Search Service

Dynamo Streams

ElasticsearchService

messages

Kibana plugin with AmazonElasticsearch Service providesreal-time UI to search messages

Lambda function processes eventsand indexes them in AmazonElasticsearch Service

DynamoDB Streams provides atime-ordered flow of events(incoming survivor messages)

Amazon Elasticsearch Serviceprovides a managed service forsearch and analytics

Page 32: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Lab 4: Send Messages from Slack

Chat Service

Slack Service

messagesSlack Chat Internet

Pre-process Slack message before sending message to Chat Service

• Design Principle: Service re-use• Single implementation of

DynamoDB PutItem

/slack /message

Page 33: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Lab 5: Zombie Sensor with Intel Edison

InternetZombie

Sensor Data

Zombie Sensor

Amazon SNS

/message

Chat Service messages

• Lambda subscribes to SNS Topic• Pre-process message• HTTPS POST to Chat Service

Node.js on Edison sends sensorevents to Amazon SNS

• Design Principle: Service re-use• Single implementation of

DynamoDB PutItem

Page 34: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Your challenge

Base Challenge1. Implement chat add-ons with the steps from the Lab Guide

Extra Credit Challenges1. Implement channel functionality for different chat rooms/private chats2. Data store for weapons/food caches & bot to notify survivors of cache levels3. Build your own challenges and share your design with us!

Page 35: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Steps to get started

• Break into groups (less than 4 people) or work solo!• Select a leader to launch the CloudFormation Stack.• Complete add-ons from Lab Guide.• Decide on other challenges you’ll build!• Share your designs with fellow survivors!

Workshop available at:https://github.com/awslabs/aws-lambda-zombie-workshop

Page 36: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Steps to get started

• Replace the signup files on to accept non-US phones

https://github.com/danilop/aws-lambda-zombie-workshop

Page 37: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Run Apps for Pennies!Cost estimate to run this 3 hour workshop!

• Lambda: FREE• 1st 1m requests are free each month! Duration pricing will be sub-1penny!

• DynamoDB: $0.0585• $0.0065/hr for every 10 read units provisioned - 75 units provisioned/hr• $0.0065/hr for every 50 write units provisioned – 75 units provisioned/hr• DynamoDB Streams: 2.5m reads free per month

• ElasticSearch Service: $0.282• M3.medium with instance storage - $0.094/hr

• API Gateway: $0.035• $3.50/million API calls. Assume 10,000 calls made per hour during lab

• CloudWatch Logs: $0.25• $0.50 per GB/month ingested. Super high end estimate of 500MB of log data during workshop

• S3: $0.03• $0.03 per GB for first 1TB a month.

• Data Transfer: FREE• First 1GB/month out is free. Data transfer in is free!

Page 38: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Go save the World!

Page 39: Zombie Apocalypse Workshop 20160922 · Building Serverless Microservices. We have to save the World! What to expect from this workshop ... service for running Docker on EC2 AWS Lambda

Thank You!

Danilo Poccia @danilopPaolo Latella @LatellaPaolo