Amazon API Gateway and AWS Lambda: Better Together

32
Amazon API Gateway and AWS Lambda: Better Together Danilo Poccia AWS Technical Evangelist @danilop danilop

Transcript of Amazon API Gateway and AWS Lambda: Better Together

Page 1: Amazon API Gateway and AWS Lambda: Better Together

Amazon API Gateway and AWS Lambda:Better Together

Danilo PocciaAWS Technical Evangelist

@danilopdanilop

Page 2: Amazon API Gateway and AWS Lambda: Better Together

You Want to BuildYour Brand New Application

Page 3: Amazon API Gateway and AWS Lambda: Better Together

Application+

Data

Page 4: Amazon API Gateway and AWS Lambda: Better Together

Application+

Data

Websites

Mobile Apps

Wearable

Page 5: Amazon API Gateway and AWS Lambda: Better Together

Application Data

Websites

Mobile Apps

Wearable

Page 6: Amazon API Gateway and AWS Lambda: Better Together

Application

Files

DB

Content +Some API Calls

API Calls

Websites

Mobile Apps

Wearable

Page 7: Amazon API Gateway and AWS Lambda: Better Together

Application

Files

DB

API Calls

Websites(JavaScript

Apps)

Mobile Apps

Wearable

JavaScript

API Calls

Page 8: Amazon API Gateway and AWS Lambda: Better Together

Application

Files

DB

API Calls

Websites(JavaScript

Apps)

Mobile Apps

Wearable

Services

API Calls

JavaScript

API Calls

Page 9: Amazon API Gateway and AWS Lambda: Better Together

Application

Files

DB

API Calls

Websites(JavaScript

Apps)

Mobile Apps

Wearable

Services

API Calls

JavaScriptAuthentication& Authorization

Caching & Throttling

Business Logic

API Calls

Page 10: Amazon API Gateway and AWS Lambda: Better Together

Application

DB

API Calls

Websites(JavaScript

Apps)

Mobile Apps

Wearable

Services

API Calls

JavaScript

Files

AmazonS3

AmazonDynamoDB

Authentication & Authorization

AmazonCognito

Business Logic

AWSLambda

Caching & Throttling

Amazon APIGatewayAPI Calls

Page 11: Amazon API Gateway and AWS Lambda: Better Together

How Does It Works?

Page 12: Amazon API Gateway and AWS Lambda: Better Together

X

AuthenticationProviders

End Users

User Credentials

AuthenticationToken

Amazon CognitoIdentity Broker

Identity Pool Id(Token)

Identity IdAWS Temp Credentials

(Depending onAuth / Unauth Role)

Access toAWS Services

(Including AmazonAPI Gateway)

Identity IdAWS Temp Credentials

Amazon S3

AmazonDynamoDB

AmazonMobile Analytics

Amazon CognitoSync Store

K / V

Authentication & Authorization

AmazonCognitoCheck Token

Page 13: Amazon API Gateway and AWS Lambda: Better Together

X

End Users

User Credentials

AuthenticationToken

Amazon CognitoIdentity Broker

Identity Pool Id(Token)

Identity IdAWS Temp Credentials

(Depending onAuth / Unauth Role)

Access toAWS Services

(Including AmazonAPI Gateway)

Identity IdAWS Temp Credentials

Amazon S3

AmazonDynamoDB

AmazonMobile Analytics

Amazon CognitoSync Store

K / V

Custom Authentication

ServiceGet Token

Token Authentication & Authorization

AmazonCognito

Page 14: Amazon API Gateway and AWS Lambda: Better Together

AmazonCloudFront

API Gateway Cache

AmazonCloudWatch

Monitoring & Logs

Endpoints onAmazon EC2 or

AWS Elastic Beanstalk

Internet

Any other publicly accessible endpoint

AWS Lambda Functions

Caching & Throttling

Amazon APIGateway

X

Access toAPI Method

Page 15: Amazon API Gateway and AWS Lambda: Better Together
Page 16: Amazon API Gateway and AWS Lambda: Better Together

Managed Cache to Store API Responses

Reduced Latency and DDoS Protection through Amazon CloudFront

SDK Generation for iOS, Android and JavaScript

HTTP 429 Response for API Throttling (Managed by the SDK)

Swagger Support

Request / Response Data Transformation and API Mocking

Page 17: Amazon API Gateway and AWS Lambda: Better Together

Business Logic

AWSLambda

AWS Lambda Functions

AmazonAPI Gateway

Amazon S3

AmazonDynamoDB

Amazon CognitoSync Store

K / VAmazonSNS

AmazonKinesis

Alexa Skills Kit (ASK)Alexa Voice Service (AVS)

HTTPSInvoke

CustomEvents

HTTPSREST

API Call

Page 18: Amazon API Gateway and AWS Lambda: Better Together

console.log('Loading function');

exports.handler = function(event, context) { console.log('value1 =', event.key1); console.log('value2 =', event.key2); console.log('value3 =', event.key3); // Echo back the first key value context.succeed(event.key1); // context.fail('Something went wrong');};

Page 19: Amazon API Gateway and AWS Lambda: Better Together

Build Back-end Services that Perform at Scale

Respond Quickly to New Information

Run Your Code without Managing Infrastructure

Cost-effective and Efficient

Page 20: Amazon API Gateway and AWS Lambda: Better Together

Amazon API Gateway+

AWS Lambda

Page 21: Amazon API Gateway and AWS Lambda: Better Together

Resource + HTTP Verb ➔ Method

Page 22: Amazon API Gateway and AWS Lambda: Better Together

Resource + HTTP Verb ➔ Method

/books + GET ➔ GetAllBooks

Page 23: Amazon API Gateway and AWS Lambda: Better Together

Resource + HTTP Verb ➔ Method

/books + GET ➔ GetAllBooks

/books + POST ➔ CreateNewBook

Page 24: Amazon API Gateway and AWS Lambda: Better Together

Resource + HTTP Verb ➔ Method

/books + GET ➔ GetAllBooks

/books + POST ➔ CreateNewBook

/books/{id} + GET ➔ GetBookById

/books/{id} + PUT ➔ CreateOrUpdateBookById

/books/{id} + DELETE ➔ DeleteBookById

Page 25: Amazon API Gateway and AWS Lambda: Better Together

Let’s Put Everything Together

Page 26: Amazon API Gateway and AWS Lambda: Better Together

Media Sharing Application

Page 27: Amazon API Gateway and AWS Lambda: Better Together

λ

λ λ

AmazonAPI Gateway

λ

λ

λλ

Bucket Usage Table

Media MetadataTable

User StatTable

User Location

Table

K / V

λ

λ

λ

Amazon CognitoIdentity Broker

Amazon CognitoSync Store

AmazonSNS

AmazonKinesis

Media Bucket

LogTable

Authentication &

AuthorizationUpload Picture / VideoUpdate Bucket UsageCheck Bucket Usage

Delete “Over Quota”

Media

Send Notification to

User / ApplicationExtract Metadata and

Write on DBUpdate

User StatisticsCall REST API

to Get Media Description

Upload Location Info

Update User Location

Look for Users or Media

Near Current Location

Call REST API to Get

User Info

Sync Media and User

RatingWrite

History of ChangesCheck and Update

Ratings

InvokeRead

Write / Send

Page 28: Amazon API Gateway and AWS Lambda: Better Together

λ

λ λ

λ

λ

λλ

λ

λ

λ

Page 29: Amazon API Gateway and AWS Lambda: Better Together

Microservice Architecture

λλ λλ

λλ λλ λ

λ

Page 30: Amazon API Gateway and AWS Lambda: Better Together

Focus on You Idea

Page 31: Amazon API Gateway and AWS Lambda: Better Together

aws.amazon.com/free

Page 32: Amazon API Gateway and AWS Lambda: Better Together

Amazon API Gateway and AWS Lambda:Better Together

Danilo PocciaAWS Technical Evangelist

@danilopdanilop