getting started with aws lambda and the serverless cloud

75
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Dean Bryen- Solutions Architect - AWS - @deanbryen James Hall - Co-Founder - Parallax - @MrRio AWS London Summit, July 7, 2016 Getting Started with AWS Lambda and the Serverless Cloud

Upload: amazon-web-services

Post on 18-Feb-2017

1.122 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Getting Started with AWS Lambda and the Serverless Cloud

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

Dean Bryen- Solutions Architect - AWS - @deanbryen James Hall - Co-Founder - Parallax - @MrRio

AWS London Summit, July 7, 2016

Getting Started with AWS Lambda and the Serverless Cloud

Page 2: Getting Started with AWS Lambda and the Serverless Cloud

What is serverless computing?

• VMs • Machine as the unit of scale • Abstracts the hardware

• Containers • Application as the unit of scale • Abstracts the OS

• Serverless • Functions as the unit of scale • Abstracts the language runtime

ECS

EC2

AWS Lambda

Page 3: Getting Started with AWS Lambda and the Serverless Cloud

How do I choose?

• VMs • “I want to configure machines, storage,

networking, and my OS”

• Containers • “I want to run servers, configure applications,

and control scaling”

• Serverless • “Run my code when it’s needed”

ECS

EC2

AWS Lambda

Page 4: Getting Started with AWS Lambda and the Serverless Cloud

Agenda

Overview Use cases Recent launches and VPC best practices Demo Customer Case Study Q & A

Page 5: Getting Started with AWS Lambda and the Serverless Cloud

AWS Lambda: Serverless computing

Run code without servers. Pay only for the compute time you consume. Be happy.

Triggered by events or called from APIs: • PUT to an Amazon S3 bucket • Updates to Amazon DynamoDB table • Call to an Amazon API Gateway endpoint • Mobile app back-end call • And many more…

Makes it easy to: • Perform real-time data processing • Build scalable back-end services • Glue and choreograph systems

Page 6: Getting Started with AWS Lambda and the Serverless Cloud

Continuous scaling No servers to manage Never pay for idle – no cold servers (only happy accountants)

Benefits of AWS Lambda

Page 7: Getting Started with AWS Lambda and the Serverless Cloud

Pay-per request

• Buy compute time in 100 ms increments for 21 microcents

• Request charge of 20 microcents • No hourly, daily, or monthly

minimums • No per-device fees

Never pay for idle!

Free Tier

1 million requests and 400,000 GBs of compute

every month, every customer

Page 8: Getting Started with AWS Lambda and the Serverless Cloud

Using AWS Lambda

Bring your own code • Node.js, Java, Python • Bring your own libraries (even

native ones)

Simple resource model • Select power rating from 128 MB

to 1.5 GB

• CPU and network allocated proportionately

• Reports actual usage

Flexible authorization • Securely grant access to

resources, including VPCs • Fine-grained control over who

can call your functions

Flexible use • Call or send events • Integrated with other AWS

services • Build whole serverless

ecosystems

Page 9: Getting Started with AWS Lambda and the Serverless Cloud

Using AWS LambdaProgramming model • AWS SDK built in (Python and

Node.js) • Eclipse plugin (Java) • Lambda is the “webserver” • Use processes, threads, /tmp,

sockets normally

Stateless • Persist data using Amazon

DynamoDB, S3, or ElastiCache • No affinity to infrastructure

(can’t “log in to the box”)

Authoring functions • Author directly using the

console WYSIWYG editor • Package code as a .zip and

upload to Lambda or S3 • Plugins for Eclipse and Visual

Studio • Command line tools

Monitoring and logging • Built-in metrics for requests,

errors, latency, and throttles • Built-in logs in Amazon

CloudWatch Logs

Page 10: Getting Started with AWS Lambda and the Serverless Cloud

But what *is* AWS Lambda?

Linux containers as an implementation, not a programming or deployment abstraction

• Process and network isolation, cgroups, seccomp, … The world’s biggest bin-packing algorithm

• High speed, highly distributed work routing and placement Predictive capacity management

• Purpose-built, massively scaled language runtime delivery service

Page 11: Getting Started with AWS Lambda and the Serverless Cloud

Amazon API Gateway: Serverless APIs

Internet

Mobile apps

Websites

Services

AWS Lambda functions

AWS

API Gateway cache

Endpoints on Amazon EC2

Any other publicly accessible endpointAmazon

CloudWatch

Amazon CloudFront

Amazon API Gateway

Page 12: Getting Started with AWS Lambda and the Serverless Cloud

Benefits of Amazon API Gateway

Create a unified API front end for multiple

microservices

DDoS protection and throttling for back-

end systems

Authenticate and authorize requests

Page 13: Getting Started with AWS Lambda and the Serverless Cloud

Microservices and AWS Lambda

AWS Lambda + Amazon API Gateway is the easiest way to create microservices

Event handlers = one function per event type Serverless backends = one function per API / path Data processing = one function per data type

Page 14: Getting Started with AWS Lambda and the Serverless Cloud

AWS Lambda, API Gateway, and AWS IoT regions

Available regions

Page 15: Getting Started with AWS Lambda and the Serverless Cloud

Use cases

Page 16: Getting Started with AWS Lambda and the Serverless Cloud

Lambda: Use cases

Serverless apps and ecosystems

Data processing Back ends

Page 17: Getting Started with AWS Lambda and the Serverless Cloud

Use case: Data processing

Example: Amazon S3 bucket triggers

Amazon S3 bucket events

Original object Compressed object1

2

3

AWS Lambda

Page 18: Getting Started with AWS Lambda and the Serverless Cloud

Why functions are the right answer

Amazon DynamoDB

Call Events

CustomizeAPI

Page 19: Getting Started with AWS Lambda and the Serverless Cloud

Use case: Automatically scalable back ends

1. AWS Mobile SDK + Amazon Cognito for mobile app Or AWS IoT for devices

2. AWS Lambda runs the code 3. Amazon API Gateway (if you want your own endpoint) 4. Amazon DynamoDB holds the data

AWS Lambda Amazon DynamoDB

Page 20: Getting Started with AWS Lambda and the Serverless Cloud

Serverless web app architecture

1. Amazon S3 for serving static content 2. AWS Lambda for dynamic content 3. Amazon API Gateway for https access 4. Amazon DynamoDB for NoSQL data storage

Dynamic content in AWS Lambda

Data stored in Amazon DynamoDB

API GatewayStatic content in Amazon S3

Page 21: Getting Started with AWS Lambda and the Serverless Cloud

Use case: New app ecosystems: Alexa apps + Slack = serverless bots!

Alexa, tell Slack to send, “I’m giving the

demo now.”

Message retrieval through scheduled polling

Kevin says, “Break a leg!”

Message upload (via Slack API)

Team (channel users)

Slack

Page 22: Getting Started with AWS Lambda and the Serverless Cloud

Recent launches andVPC best practices

Page 23: Getting Started with AWS Lambda and the Serverless Cloud

re:Invent 2015• Python • Scheduled functions • Longer running times (5 min.) • Versioning

Recent launches

Since re:Invent• Higher code storage limits (from 5 GB to

75 GB) • Custom VPC • 1-minute schedules • Regional launch: Frankfurt and Sydney • Node.js 4.3.2 • 1-click CORs setup • Stage variables • Custom (Lambda) authorizers • Builtin Swagger import/export • AWS CloudFormation support for API

Gateway and versions

New!

New!

Page 24: Getting Started with AWS Lambda and the Serverless Cloud

AWS Lambda VPC basics

All Lambda functions run in a VPC, all the time You never need to “turn on” security – it’s always on

You can also grant Lambda functions access to resources in your own VPC How: Add VPC subnet IDs and security group IDs to the function config Typical uses: RDB, ElastiCache, private EC2 endpoints Allows access to peered VPCs, VPN endpoints, and private S3 endpoints

Functions configured for VPC access lose internet access… unless you have managed NAT or a NAT instance in the VPC …Even if you have “Auto-assign Public IP” enabled …Even if you have an internet gateway set up in your VPC …Even if your security group allows all outbound traffic

Page 25: Getting Started with AWS Lambda and the Serverless Cloud

AWS Lambda VPC Best practices

VPC is optional – don’t turn in on unless you need it. The ENIs used by Lambda’s VPC feature count against your quota.

Ensure you have enough to match your peak concurrency levels DO NOT delete or rename these ENIs! ☺

Ensure your subnets have enough IPs for those ENIs. Specify at least one subnet in each Availability Zone

Otherwise, Lambda will obey, but can’t be as fault-tolerant.

Page 26: Getting Started with AWS Lambda and the Serverless Cloud

Demo

Page 27: Getting Started with AWS Lambda and the Serverless Cloud

Serverless Web App Architecture

Static Site in S3 www.servicecheck.com

Web Client API Gateway/services

LambdaservicePOST

LambdaserviceGET

DynamoDBservices

Page 28: Getting Started with AWS Lambda and the Serverless Cloud

The serverless compute manifesto

Functions are the unit of deployment and scaling. No machines, VMs, or containers visible in the programming model. Permanent storage lives elsewhere. Scales per request. Users cannot over- or under-provision capacity. Never pay for idle (no cold servers/containers or their costs). Implicitly fault-tolerant because functions can run anywhere. BYOC – Bring your own code. Metrics and logging are a universal right.

Page 29: Getting Started with AWS Lambda and the Serverless Cloud

Join the serverless revolution!

Page 30: Getting Started with AWS Lambda and the Serverless Cloud

@parallax

Hitting 1 million recordings “without servers”James Hall, Director, Parallax

Page 31: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Who we are

We help the world's top companies and most ambitious startups

build brilliant digital products, services and applications.

Page 32: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 33: Getting Started with AWS Lambda and the Serverless Cloud

Enterprise

We designed and built a native mobile application to allow users to find and book cars or vans on the move, get directions, unlock the car door and quickly get going. The initial mobile app built for City Car Club was such as hit that when Enterprise bought the company it was top of their list to rebrand.

@parallax Serverless Applications on AWS

Page 34: Getting Started with AWS Lambda and the Serverless Cloud

Gravit

Gravit is a professional web-based design app that gives designers and non-designers the tools to create and share great looking work. It’s been featured in Forbes, TechCrunch, Smashing Magazine and countless other publications.

@parallax Serverless Applications on AWS

Page 35: Getting Started with AWS Lambda and the Serverless Cloud

British Airways

We built a bespoke application to power large amounts of LED advertising billboards. The software allows advertisers to easily manage their advertising and see reports.

@parallax

Page 36: Getting Started with AWS Lambda and the Serverless Cloud

One Column

[email protected] 226477

Subtitle

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has a the industry's standard dummy text ever since the 1500s,

when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.

Here is an example:

- Bullet Point one - Bullet Point one - Bullet Point one

It was popularised in the 1960s with the release of Letraset sheets containing

Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

@parallax

Page 37: Getting Started with AWS Lambda and the Serverless Cloud

“Everybody loved the idea, some little geniuses created this app where you can record your part.”

@parallax Serverless Applications on AWS

David Guetta

Page 38: Getting Started with AWS Lambda and the Serverless Cloud
Page 39: Getting Started with AWS Lambda and the Serverless Cloud

“The longer I spent watching the intro video, the more

it looked like David sort of didn't want to be there. He

was shifting around on his chair like a man who'd just

nicked a Mars bar.”

– VICE

Page 40: Getting Started with AWS Lambda and the Serverless Cloud

@parallax

Page 41: Getting Started with AWS Lambda and the Serverless Cloud

Traditional Architecture

@parallax@parallax

Page 42: Getting Started with AWS Lambda and the Serverless Cloud

@parallax

Traditional Architecture

Serverless Applications on AWS

Page 43: Getting Started with AWS Lambda and the Serverless Cloud

£ £ £ £ £ £ £

@parallax

Traditional Architecture

Serverless Applications on AWS

Page 44: Getting Started with AWS Lambda and the Serverless Cloud

With AWS Serverless

@parallax@parallax Serverless Applications on AWS

Page 45: Getting Started with AWS Lambda and the Serverless Cloud

@parallax

Without “Servers”

Serverless Applications on AWS

Page 46: Getting Started with AWS Lambda and the Serverless Cloud

Serverless Framework

@parallax@parallax Serverless Applications on AWS

Page 47: Getting Started with AWS Lambda and the Serverless Cloud

• Pay-per-use Pricing • No servers to manage • Run nano/microservices

(or monoliths!)

@parallax Serverless Applications on AWS

Page 48: Getting Started with AWS Lambda and the Serverless Cloud

How it works

@parallax@parallax Serverless Applications on AWS

Page 49: Getting Started with AWS Lambda and the Serverless Cloud

@parallax

Page lifecycle

Serverless Applications on AWS

1. User visits

HTTPSGET /

S3 with CloudFront

2. CSS & JS

HTTPSGET*.js*.css

S3 with CloudFront

index.html

3. Lang detect

API Gateway w/Lambda

HTTPSGET/users/country

HTTPSPOST/users/update

4. User fills details

API Gateway w/Lambda

Page 50: Getting Started with AWS Lambda and the Serverless Cloud

@parallax

Page lifecycle

Serverless Applications on AWS

5.

5. FB Login (optional)

HTTPSGET api.facebook.com

Hits Facebook Hosted Endpointvia Facebook Javascript SDK

6. YouTube

HTTPSGETyoutube.com

YouTube iframe

{“email”: “xyz”,“profile_id”: 123}

7. Start recording

API Gateway w/Lambda

Responds with S3 upload token

HTTPSGET/recordings/token

Uploads directly to S3 bucket over HTTPS using token

6.

7. 8.

HTTPSPOSTbucket.s3.amazon/UID/recording-X.mp3

8. Upload recording

Page 51: Getting Started with AWS Lambda and the Serverless Cloud

@parallax

Page lifecycle

Serverless Applications on AWS

9. Submit details

API Gateway w/Lambda

10. Artwork gen

HTTPSPOST/users/generate_artwork

API Gateway w/Lambda.Create image, put on S3, return S3 image URL

11. Artwork display

CloudFront w/ S3

HTTPSGET/domain.com/UID.png

AddThis.js is populated with the share texts, and includes the S3 URL

HTTPGETaddthis.com/file.js

HTTPSPOST/users/update

{ url: “domain.com/UID.png” }

10. 11.

12. Social share 13. Social share

HTTPSGEThttps://twitter.com/intent/tweet?text=XYZ

12. 13.

Directly hits the social media service

Page 52: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 53: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 54: Getting Started with AWS Lambda and the Serverless Cloud

Chelsea FC / Delta

@parallax@parallax Serverless Applications on AWS

Page 55: Getting Started with AWS Lambda and the Serverless Cloud

@parallax

Page 56: Getting Started with AWS Lambda and the Serverless Cloud

Deployment

@parallax@parallax Serverless Applications on AWS

Page 57: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 58: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 59: Getting Started with AWS Lambda and the Serverless Cloud

The Future? GraphQL

@parallax@parallax Serverless Applications on AWS

Page 60: Getting Started with AWS Lambda and the Serverless Cloud

@parallax@parallax

Page 61: Getting Started with AWS Lambda and the Serverless Cloud

@parallax@parallax

{ user(id: 3500401) { id, name, isViewerFriend, profilePicture(size: 50) { uri, width, height } }}

Page 62: Getting Started with AWS Lambda and the Serverless Cloud

@parallax@parallax

{ "user" : { "id": 3500401, "name": "Jing Chen", "isViewerFriend": true, "profilePicture": { "uri": "http://someurl.cdn/pic.jpg", "width": 50, "height": 50 } }}

Page 63: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Some sequences may have been shortened.

Page 64: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 65: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 66: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 67: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 68: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 69: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 70: Getting Started with AWS Lambda and the Serverless Cloud

Build small apps to help your DevOps

@parallax@parallax Serverless Applications on AWS

Page 71: Getting Started with AWS Lambda and the Serverless Cloud

One more thing

@parallax@parallax Serverless Applications on AWS

Page 72: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 73: Getting Started with AWS Lambda and the Serverless Cloud

@parallax Serverless Applications on AWS

Page 74: Getting Started with AWS Lambda and the Serverless Cloud

About us

Who we are

We’re a bunch of technologists and

creatives based in Leeds and London.

We help the world's top companies and

most ambitious startups build brilliant

digital products, services and

applications.

Page 75: Getting Started with AWS Lambda and the Serverless Cloud

Thank You Questions?