Top Banner
AWS Cloud Kata for Start-Ups and Developers Hong Kong Aug 3
58

Running Microservices with Lambda and API Gateway

Apr 15, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Hong Kong

Aug 3

Page 2: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Hong Kong

Building Serverless BackendsUsing AWS Lambda and Amazon API Gateway

Alex Smith

Head of Media & Entertainment Architecture, Asia Pacific

Amazon Web Services

Page 3: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

The Familiar 3 Tier Architecture

https://d0.awsstatic.com/whitepapers/AWS_Serverless_Multi-Tier_Architectures.pdf

Page 4: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Here is what that translates to in real life

http://media.amazonwebservices.com/architecturecenter/AWS_ac_ra_web_01.pdf

Page 5: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 6: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Dr Werner Vogels

CTO - Amazon

Page 7: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

No server is easier to manage…

Page 8: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

No server is easier to manage…

…than no server.

Page 9: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

No server is easier to manage…

…than no server.

AWS Lambda

Page 10: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

AWS Lambda: Run code in response to events

Lambda functions: Stateless, trigger-based code execution

Triggered by events:

• Direct Sync and async API calls

• AWS Service integrations

• 3rd party triggers

Makes it easy to:

• Perform data-driven auditing, analysis, and notification

• Build back-end services that perform at scale

Page 11: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Cost-effective and

efficient

No Infrastructure

to manage

Pay only for what you use

Bring Your

Own Code

Productivity focused compute platform to build powerful, dynamic, modular

applications in the cloud

Run code in standard

languages

Focus on business logic

Benefits of AWS Lambda

1 2 3

Page 12: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Utilisation Window

Page 13: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

AWS Compute offerings

VM App Function

Service EC2 ECS Lambda

H/W OS Runtime

Unit of scale

Level of

abstraction

Page 14: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Multiple Application Types using AWS

LambdaAnalytics

• Operational management

• Live Dashboards

Data workflows

• Content management

• ETL workflows

Interactive Backends

• Bots

• Webhooks

Autonomous IT

• Policy engines

• Infrastructure management

Page 15: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Applications Components for Serverless

appsEVENT SOURCE FUNCTION SERVICES (ANYTHING)

Changes in

data state

Requests to

endpoints

Changes in

resource state

Node

Python

Java

… more coming

Page 16: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Amazon

S3

Amazon

DynamoDB

Amazon

Kinesis

AWS

CloudFormationAWS

CloudTrail

Amazon

CloudWatch

Amazon

SNS

Amazon

SES

Amazon

API Gateway

Amazon

Cognito

AWS

IoT

Amazon

Alexa

Cron events

DATA STORES ENDPOINTS

REPOSITORIES EVENT/MESSAGE SERVICES

Event Sources that integrate with AWS

Lambda

… and the list continues to grow.

Page 17: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

That’s Great!

I wish I had that, but for my…

Page 18: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

That’s Great!

I wish I had that, but for my…

APIs

Page 19: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

That’s Great!

I wish I had that, but for my…

APIs

WebApps

Page 20: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

That’s Great!

I wish I had that, but for my…

APIs

WebApps

Page 21: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

The Other Challenge..

Page 22: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

APIs are Hard

Managing multiple versions and stages of an API is difficult

Monitoring 3rd party developers’ access is time consuming

Access authorization is a challenge

Traffic spikes create operational burden

What if I don’t want servers at all?

Page 23: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

API Gateway to manage your REST endpoints

Build, Deploy, and Manage APIs

Throttling rules per HTTP method

Cache with customizable keys

Multiple API versions and stages

Generate client SDKs

Dashboard for visual monitoring

Flexible authorization model

API Keys for 3rd party developers

Page 24: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Benefits of API Gateway for web/mobile

appsLow cost and efficient

Performance at any

scale

DDoS protection and

throttling

Streamline API

development

Authenticate and

authorize requests

Create RESTful

Endpoints

Page 25: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

API Gateway + Lambda = Frontend + Backend

Internet

Mobile Apps

Websites

Services

API

Gateway

AWS

Endpoints on

Amazon EC2

Any other publicly

accessible endpoint

Amazon

CloudWatch

Monitoring

Amazon

CloudFront

AWS Lambda

functions

API Gateway

Cache

Page 26: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Real World Architecture

http://media.amazonwebservices.com/architecturecenter/AWS_ac_ra_web_01.pdf

Page 27: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Real World “Serverless” Architecture

https://s3.amazonaws.com/awslambda-reference-architectures/web-app/lambda-refarch-webapp.pdf

Page 28: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Live Demo: Building a Serverless

web application

https://vote.alexjs.im

http://vote.alex.中文网

Page 29: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Demo site: A simple Serverless CRUD backend

http://squirrelbin.com/

Page 30: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Best practices for Lambda functions• Memory:

• CPU proportional memory

• Increasing memory makes your code

execute faster (if CPU bound)

• Timeout

• Increasing timeout allows for longer

functions, but more wait in case of errors

• Retries:

• For API Gateway, Lambda doesn’t retry

the function execution if failed

• Gateway generated SDKs retry throttled

requests

• Permission model:

• API Gateway synchronously triggers

Lambda, so assign API Gateway a

resource policy to invoke Lambda.

Page 31: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Monitoring and Debugging Lambda functions

• Console Dashboard

• Lists all Lambda functions

• Easy editing of resources,

event sources and other

settings

• At-a-glance metrics

• Metrics in CloudWatch

• Requests

• Errors

• Latency

• Throttles

• Logging in CloudWatch Logs

Page 32: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Using API Gateway Input/Output

TransformsFilter output results

• Remove private/unnecessary data

• Filter dataset size to improve API performance

Translate between client-backend

• Convert GET query string parameters to body for POST

• Talk XML to API user-interface but JSON to Lambda

Page 33: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Managing different versions of your API

stack• Operate multiple API versions and

multiple stages for each version

simultaneously

• Clone an existing API to start working

on the next major version

• Set up custom domain names to point

directly to a stage

• Version Lambda functions, and

associate API stage with Lambda

function version alias

Page 34: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Three Next Steps

1. Check out http://squirrelbin.com/

2. Try out the “Serverless Web-App Reference Architecture” at

https://github.com/awslabs/lambda-refarch-webapp/

3. Build your own custom web-app using the AWS Lambda

blueprints at https://console.aws.amazon.com/lambda

Page 35: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Questions?

E: [email protected]

T: @alexjs

Page 36: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

THANK YOU!

Please remember to fill out evaluations

Page 37: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Hong Kong

Aug 3

Page 38: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 39: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 40: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 41: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 42: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 43: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 44: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 45: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 46: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 47: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 48: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 49: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 50: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 51: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 52: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 53: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 54: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 55: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 56: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 57: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers

Page 58: Running Microservices with Lambda and API Gateway

AWS Cloud Kata for Start-Ups and Developers