Amazon API Gateway and AWS Lambda:Better Together
Danilo PocciaAWS Technical Evangelist
@danilopdanilop
You Want to BuildYour Brand New Application
Application+
Data
Application+
Data
Websites
Mobile Apps
Wearable
Application Data
Websites
Mobile Apps
Wearable
Application
Files
DB
Content +Some API Calls
API Calls
Websites
Mobile Apps
Wearable
Application
Files
DB
API Calls
Websites(JavaScript
Apps)
Mobile Apps
Wearable
JavaScript
API Calls
Application
Files
DB
API Calls
Websites(JavaScript
Apps)
Mobile Apps
Wearable
Services
API Calls
JavaScript
API Calls
Application
Files
DB
API Calls
Websites(JavaScript
Apps)
Mobile Apps
Wearable
Services
API Calls
JavaScriptAuthentication& Authorization
Caching & Throttling
Business Logic
API Calls
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
How Does It Works?
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
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
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
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
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
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');};
Build Back-end Services that Perform at Scale
Respond Quickly to New Information
Run Your Code without Managing Infrastructure
Cost-effective and Efficient
Amazon API Gateway+
AWS Lambda
Resource + HTTP Verb ➔ Method
Resource + HTTP Verb ➔ Method
/books + GET ➔ GetAllBooks
Resource + HTTP Verb ➔ Method
/books + GET ➔ GetAllBooks
/books + POST ➔ CreateNewBook
Resource + HTTP Verb ➔ Method
/books + GET ➔ GetAllBooks
/books + POST ➔ CreateNewBook
/books/{id} + GET ➔ GetBookById
/books/{id} + PUT ➔ CreateOrUpdateBookById
/books/{id} + DELETE ➔ DeleteBookById
Let’s Put Everything Together
Media Sharing Application
λ
λ λ
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
λ
λ λ
λ
λ
λλ
λ
λ
λ
Microservice Architecture
λλ λλ
λλ λλ λ
λ
Focus on You Idea
aws.amazon.com/free
Amazon API Gateway and AWS Lambda:Better Together
Danilo PocciaAWS Technical Evangelist
@danilopdanilop