aws - lambda and api

31
© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Presenter: Vyom Nagrani, Sr. Product Manager, AWS Lambda Q&A Moderator: Ajay Nair, Sr. Product Manager, AWS Lambda August 18 th , 2015 Best Practices: Building Serverless Backends with AWS Lambda and Amazon API Gateway

Upload: epics-qt-collaboration

Post on 11-Apr-2017

739 views

Category:

Engineering


24 download

TRANSCRIPT

Page 1: AWS - Lambda and API

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

Presenter: Vyom Nagrani, Sr. Product Manager, AWS LambdaQ&A Moderator: Ajay Nair, Sr. Product Manager, AWS Lambda

August 18th, 2015

Best Practices: Building Serverless Backends with AWS Lambda and Amazon API Gateway

Page 2: AWS - Lambda and API

Amazon API Gateway: Build, Deploy, and Manage APIs

SDK Generation for iOS, Android and JavaScript

Create and distribute API Keys to developers

Leverage AWS Sigv4 to authorize access to APIs

Swagger support

Utilizes AWS Lambda

Request / Response data transformation

Page 3: AWS - Lambda and API

Benefits of API Gateway for creating RESTful endpoints for deploying services

Manage deployments to multiple versions and

environments

Define and host APIs

Leverage Identity and Access Management to authorize access to your

cloud resources

Leverage AWS Auth

DDoS protection and request throttling to

safeguard your backend

Manage network traffic1 2 3

Page 4: AWS - Lambda and API

AWS Lambda: A compute service that runs your code in response to events

Lambda functions: Stateless, trigger-based code execution

Triggered by events:• Direct Sync and Async invocations • Put to an Amazon S3 bucket• API Gateway call• And many more …

Makes it easy to• Build back-end services that perform at scale • Perform data-driven auditing, analysis, and notification

Page 5: AWS - Lambda and API

High performance at any scale; Cost-effective and efficient

No Infrastructure to manage

Pay only for what you use: Lambda automatically matches capacity to

your request rate. Purchase compute in 100ms increments.

Bring Your Own Code

“Productivity focused compute platform to build powerful, dynamic, modular applications in the cloud”

Run code in a choice of standard languages. Use threads, processes,

files, and shell scripts normally.

Focus on business logic, not infrastructure. You upload code; AWS

Lambda handles everything else.

Benefits of AWS Lambda for building a server-less data processing engine

1 2 3

Page 6: AWS - Lambda and API

API Gateway + Lambda = Frontend + Backend !

Internet

Mobile Apps

Websites

Services

API Gateway

AWS

API Gateway Cache

Endpoints on Amazon EC2

Any other publicly accessible endpoint

Amazon CloudWatch Monitoring

Amazon CloudFront

AWS Lambda functions

Page 7: AWS - Lambda and API

Walkthrough of a simple CRUD backend with a RESTful API endpoint using AWS Lambda

Amazon API Gateway

AWS Lambda Amazon DynamoDB

API call from client app

Request/Response CRUD Operations

Page 8: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 9: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 10: AWS - Lambda and API

CRUD operations with DynamoDB

‘echo’ and ‘pong’ for testing

Error handling for incorrect inputs

Remove operation code from event

Page 11: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 12: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 13: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 14: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 15: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 16: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 17: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 18: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 19: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 20: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 21: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 22: AWS - Lambda and API

AWS Console walkthrough of a simple CRUD backend with a RESTful API endpoint using Lambda

Page 23: AWS - Lambda and API

Demo site: A simple CRUD backend with a RESTful API endpoint using Amazon API Gateway and AWS Lambda

http://squirrelbin.com/

Page 24: AWS - Lambda and API

Attaching Lambda functions to RESTful HTTP Endpoints

• 1:1 Mapping: Every API call triggers a stateless Lambda function

• Add caching to API calls to return a cached response instead for duplicate requests

• API Gateway concepts: An API is defined as a set of resources and methods

• Resource: A logical entity that can be accessed within an API

• Method: The combination of a resource path and an HTTP verb such as GET/POST

• Automatic Scaling: Both API Gateway and Lambda scale automatically with calls

• Safety throttle of 100 concurrent Lambda functions, can be increased by AWS Support Center

• User defined standard-rate limit and a burst-rate limit per second for each API method

Page 25: AWS - Lambda and API

Best practices for creating Lambda functions

• Memory: CPU proportional to the memory configured

• 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, but the

Gateway generated SDKs retry throttled requests

• Permission model: API Gateway synchronously triggers Lambda, so assign API

Gateway a resource policy to invoke Lambda.

Page 26: AWS - Lambda and API

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 27: AWS - Lambda and API

Using API Gateway Input/Output Transforms

Filter output results• Remove private or unnecessary data• Filter dataset size to improve API

performance

GET to POST• Read all query string parameters from your

GET request, and create a body to make a POST to your backend

JSON to XML• Receive JSON input and transform it to XML

for your backend• Receive JSON from a Lambda function and

transform it to XML

Page 28: AWS - Lambda and API

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

COMING SOON!

Page 29: AWS - Lambda and API

Three Next Steps

1. Create and test your first API. With a few clicks in the AWS Management Console, you can create an API that acts as a “front door” for applications to access data, business logic, or functionality from your back-end services.

2. Create and test your first Lambda function. With AWS Lambda, there are no new languages, tools, or frameworks to learn. You can use any third party library, even native ones.

3. Select Lambda as your backend for your API … This gives you an endpoint for your function which can respond to REST calls like GET, PUT and POST without managing any servers.

Page 30: AWS - Lambda and API

Thank you!

Visit http://aws.amazon.com/api-gateway, the AWS blog, and the API Gateway forum to learn more and get started using API Gateway.

Visit http://aws.amazon.com/lambda, the AWS Compute blog, and the Lambda forum to learn more and get started using Lambda.

Page 31: AWS - Lambda and API

AWS re:Invent 2015 – October 6-9AWS re:Invent is the largest annual gathering of the global cloud community. Whether you are an existing customer or new to the cloud, AWS re:Invent will provide you with the knowledge and skills to refine your cloud strategy, improve developer productivity, increase application performance and security, and reduce infrastructure costs.

Though AWS re:Invent tickets are sold out, you can still register to view the Live Stream Broadcasts of the keynote addresses and select technical sessions on October 7 and October 8. Register now.

Details:Wednesday, October 79:00am - 10:30am PT: Andrew Jassy, Sr. Vice President, AWS11:00am - 5:15pm PT: 5 of the most popular breakout sessions (to be announced)

Thursday, October 89:00am - 10:30am PT: Dr. Werner Vogels, CTO, Amazon11:00am - 6:15pm PT: 6 of the most popular breakout sessions (to be announced)

Register now for the Live Stream Broadcast by submitting your email where prompted on the AWS re:Invent home page.

Stay Connected: Follow event activities on Twitter @awsreinvent (#reinvent), or like us on Facebook.