Transcript
Page 1: Getting Started with AWS Lambda & Serverless Cloud

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

Ian Massingham Technical Evangelist, Amazon Web Services

Getting Started with AWS Lambda and the Serverless Cloud

Page 2: Getting Started with AWS Lambda & 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

EC2

ECS

AWS Lambda

Page 3: Getting Started with AWS Lambda & 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”

EC2

ECS

AWS Lambda

Page 4: Getting Started with AWS Lambda & 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 back ends one function per API / path • Data processing one function per data type

Page 5: Getting Started with AWS Lambda & Serverless Cloud

Agenda

Overview Use cases Recent launches and best practices Demo Q & A

Page 6: Getting Started with AWS Lambda & 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 7: Getting Started with AWS Lambda & Serverless Cloud

Continuous scaling No servers to manage

Never pay for idle – no cold servers

(only happy accountants)

Benefits of AWS Lambda

Page 8: Getting Started with AWS Lambda & Serverless Cloud

Pay-per request

• Buy compute time in 100 ms increments

• Low request charge • 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 9: Getting Started with AWS Lambda & 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 10: Getting Started with AWS Lambda & Serverless Cloud

Using AWS Lambda

Programming model • AWS SDK built in (Python

and Node.js) • Lambda is the front end • 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 11: Getting Started with AWS Lambda & 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

Swagger interpreter (API Gateway)

Page 12: Getting Started with AWS Lambda & 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 13: Getting Started with AWS Lambda & 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 14: Getting Started with AWS Lambda & Serverless Cloud

Use cases

Page 15: Getting Started with AWS Lambda & Serverless Cloud

Lambda: Use cases

Serverless app ecosystems

Data processing Back ends

Page 16: Getting Started with AWS Lambda & Serverless Cloud

§

Example: Amazon S3 bucket triggers

Amazon S3 bucket events

Original object Compressed object1

2

3

AWS Lambda

Page 17: Getting Started with AWS Lambda & Serverless Cloud

Why functions are the right answer

Amazon DynamoDB

Call Events

CustomizeA

PI

Page 18: Getting Started with AWS Lambda & 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 19: Getting Started with AWS Lambda & 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 20: Getting Started with AWS Lambda & Serverless Cloud

Recent launches andbest practices

Page 21: Getting Started with AWS Lambda & Serverless Cloud

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

Recent launches

2016• Higher code storage limits (from

5 GB to 75 GB per region) • VPC • New regions! • Node.js 4.3.2 • Swagger API import • 1-minute schedules New!

Page 22: Getting Started with AWS Lambda & Serverless Cloud

Function schedules: The how-to guide

✓ How can I keep a function warm (no cold starts)? Schedule it!

✓ How can I poll a queue (like SQS)? Schedule a function to read the queue.

✓ How can I get more timers? Have one scheduled function async invoke other functions.

✓ How can I get granularity finer than 1 minute? Run a background timer in your scheduled function.

Page 23: Getting Started with AWS Lambda & Serverless Cloud

Function versioning: The how-to guide

✓ How can I get mutable configuration info? Read it (e.g. from DynamoDB) during function initialization. Wrap your config in a function and call it from your published code.

✓ How do I “roll back” in AWS Lambda? Using aliases, just switch what the alias points to. (As a collection, add API Gateway stages or CloudFormation.)

✓ How do I do blue/green deployments? AWS Lambda handles fleet deployments, but if you want to shape traffic, put a second “traffic cop” function in front.

✓ How can I lock a client/device onto an old version? Point them directly to that version’s ARN.

Page 24: Getting Started with AWS Lambda & 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 & Serverless Cloud

AWS Lambda VPC feature: 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 (we’ll consolidate where we can). 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 & Serverless Cloud

Demo

Page 27: Getting Started with AWS Lambda & 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 28: Getting Started with AWS Lambda & 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 & Serverless Cloud

Join the serverless revolution!

Page 30: Getting Started with AWS Lambda & Serverless Cloud

Product manager or business analyst? Check out aws.amazon.com/lambda for scenarios and customer stories.

0.

Page 31: Getting Started with AWS Lambda & Serverless Cloud

Developer? Go to the AWS Lambda console, create a function, and run it. (The first million invokes are on us!)

1.

Page 32: Getting Started with AWS Lambda & Serverless Cloud

Congrats, you’re a Lambda function expert! Add an event source or an HTTP endpoint.2.

Page 33: Getting Started with AWS Lambda & Serverless Cloud

Build a mobile, voice, or IoT back end with a few lines of code.3.

Page 34: Getting Started with AWS Lambda & Serverless Cloud

Q & AFollow AWS Lambda and

Amazon API Gateway! aws.amazon.com/blogs/computeaws.amazon.com/lambdaAWS Lambda forum t: @IanMmmm

Page 35: Getting Started with AWS Lambda & Serverless Cloud

Follow AWS Lambda and Amazon API Gateway!

aws.amazon.com/blogs/computeaws.amazon.com/lambdaAWS Lambda forum t: @IanMmmm


Top Related