aws lambda: event-driven code in the cloud

30
©2015, Amazon Web Services, Inc. or its affiliates. All rights reserved AWS Lambda: Event-driven Code in the Cloud Dr. Tim Wagner, General Manager AWS Lambda July 1, 2015 | Chicago, IL

Upload: amazon-web-services

Post on 13-Aug-2015

458 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: AWS Lambda: Event-Driven Code in the Cloud

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

AWS Lambda:

Event-driven Code in the Cloud

Dr. Tim Wagner, General Manager AWS Lambda

July 1, 2015 | Chicago, IL

Page 2: AWS Lambda: Event-Driven Code in the Cloud

Event-Driven Compute in the Cloud

• Launched last November at re:Invent– Lambda functions: Stateless, request-driven code execution

– Triggered by events…

• PUT to an Amazon S3 bucket

• Write to an Amazon DynamoDB table

• Record in an Amazon Kinesis stream

– Making it easy to…

• Transform data as it reaches the cloud

• Perform data-driven auditing, analysis, and notification

• Kick off workflows

Page 3: AWS Lambda: Event-Driven Code in the Cloud

Triggers Example: Amazon S3

Amazon S3 Bucket Events AWS Lambda

Original image Thumbnail image

1

2

3

Page 4: AWS Lambda: Event-Driven Code in the Cloud

No infrastructure to manage

• Focus on business logic,

not infrastructure

• Upload your code; AWS

Lambda handles:

• Capacity

• Scaling

• Deployment

• Monitoring

• Logging

• Web service frontend

• Security patching

Page 5: AWS Lambda: Event-Driven Code in the Cloud

Bring your own code

• Create threads and

processes, run batch

scripts or other

executables, and

read/write files in /tmp

• Include any library with

your Lambda function

code, even native

libraries

Page 6: AWS Lambda: Event-Driven Code in the Cloud

Dynamic content generation

based on incoming news text

and images

Real-time log

processing for

prediction analytics

Thumbnailing

installation site photos

for mobile use

Real-time processing and

recording of inbound traffic from

a range of social media

platforms

Large-scale distributed

search across blog

content

Operational

analytics and real-

time troubleshooting

Page 7: AWS Lambda: Event-Driven Code in the Cloud

4/9: Building Backends with Lambda

• GA release

• Request/response

• AWS Mobile SDK

• Easy personalization– …for devices

– …for end users

• New event sources: Amazon SNS and Amazon Cognito

AWS LambdaMobile app

Page 8: AWS Lambda: Event-Driven Code in the Cloud

Sending SNS Messages to AWS Lambda

• Amazon Simple Notification Service (SNS)– Easily target, route, transform, filter, or audit messages

– Trigger an AWS Lambda function by sending it notifications

– Turn Amazon CloudWatch alarms into actions

– GitHub bots!

Lambda functionSNS

Page 9: AWS Lambda: Event-Driven Code in the Cloud

Automatic Scaling

• Lambda scales to match

the event rate

• Don’t worry about over

or under provisioning

• Pay only for what you

use

• New app or successful

app, Lambda matches

your scale

Page 10: AWS Lambda: Event-Driven Code in the Cloud

Fine-grained pricing

• Buy compute time in

100ms increments

• Low request charge

• No hourly, daily, or

monthly minimums

• No per-device fees

Never pay for idle

Free Tier

1M requests and 400,000 GBs of compute

Every month, every customer

Page 11: AWS Lambda: Event-Driven Code in the Cloud

6/15: Java Support

• “java8” as a supported language

• AWS Compute blog post on using Scala (Clojure

blog coming soon)

• Eclipse and maven integration

• POJOs for AWS event sources

• Three programming model options: streams,

POJOs, JSON

Page 12: AWS Lambda: Event-Driven Code in the Cloud

Java Demo: Auto-Compress S3 Files

Page 13: AWS Lambda: Event-Driven Code in the Cloud

Using AWS Lambda

Page 14: AWS Lambda: Event-Driven Code in the Cloud

Writing Lambda Functions

• The basics– Stock node.js or jvm (or call out to Python or a shell script)

– AWS SDK: built-in for node, deployed automatically in Eclipse+Java

– Call directly or wire up events: Lambda handles inbound traffic

• Stateless– Use S3, DynamoDB, or other Internet storage for persistent data

– Don’t expect affinity to the infrastructure (you can’t “log in to the box”)

• Familiar– Use processes, threads, /tmp, sockets, …

– Bring your own libraries, even native ones

Page 15: AWS Lambda: Event-Driven Code in the Cloud

Retry Policies

• Synchronous calls– Client controls retry behavior

• Events sent from Amazon S3 or SNS:– One event per Lambda invocation, 3 attempts

• DynamoDB and Amazon Kinesis records:– Ordered model with multiple records per event

– Unlimited retries (until data expires)

– Shards processed in parallel

Page 16: AWS Lambda: Event-Driven Code in the Cloud

Lambda Use Cases

“I want to send

customized

messages to

different users”

SNS + Lambda

“I want to send an

offer when a user

runs out of lives in

my game”

Cognito + Lambda

+ SNS

“I want to transform

the records in a

click stream or an

IoT data stream”

Kinesis + Lambda

Page 17: AWS Lambda: Event-Driven Code in the Cloud

Lambda Use Cases

“I want to take

action on a GitHub

pull”

GitHub + SNS +

Lambda

“I want to scan files

added to an S3

bucket and index

them”

S3 + Lambda +

DynamoDB

“I want to audit all

AWS API usage”

CloudTrail + S3 +

Lambda

Page 18: AWS Lambda: Event-Driven Code in the Cloud

6/25: Compute for Connected Devices

• Alexa Skills Kit – build

voice-enabled apps

• Uses AWS Lambda

as a connected

device/IoT platform

Page 19: AWS Lambda: Event-Driven Code in the Cloud

Alexa Workflow

Page 20: AWS Lambda: Event-Driven Code in the Cloud

Slack Demo Architecture

Alexa, tell Slack to

send, “I’m giving the

demo now.”

Message retrieval

(via SQS queue)

Kevin says,

“Break a leg!”

Message upload

(via Slack API)

Team

(channel users)

Slack

Page 21: AWS Lambda: Event-Driven Code in the Cloud

Echo Demo: Voice-Controlled Slack Channel

Page 22: AWS Lambda: Event-Driven Code in the Cloud

From Demo to Production with Lambda

Eliminating the distance between

“Works on my box” and “Ship it to customers!”

Never pay

for idle

Built-in

web server

Auto patch

Auto deploy

Auto scaleBuilt-in

monitoring

Built-in

logging

Page 23: AWS Lambda: Event-Driven Code in the Cloud

AWS Lambda Regions

AWS Lambda

region

NEW: Tokyo

launched 6/29

Page 24: AWS Lambda: Event-Driven Code in the Cloud

But Wait, There’s More!

• CloudTrail support for AWS Lambda APIs

• CloudFormation stacks can include Lambda functions– …and custom actions can run as Lambda functions

• Mobile SDK support for Lambda APIs

• Cross-account access

• Built-in simplified database backend

• Create or update functions from Amazon S3

• Searching, time sorting, and integrated view for logs

Page 25: AWS Lambda: Event-Driven Code in the Cloud

We’ve been busy.

Now, it’s your turn.

Page 26: AWS Lambda: Event-Driven Code in the Cloud

Go to the AWS Lambda console,

create a function, and run it(The first million invokes are on us!)

Page 27: AWS Lambda: Event-Driven Code in the Cloud

Don’t stop yet! Add an event

source to your function(S3, SNS, Kinesis, Echo, DynamoDB, …)

Page 28: AWS Lambda: Event-Driven Code in the Cloud

Build the world’s easiest mobile

backend(Hint: Start with the built-in CRUD sample!)

Page 29: AWS Lambda: Event-Driven Code in the Cloud

Follow AWS Lambda!aws.amazon.com/blogs/compute

aws.amazon.com/lambda

AWS Lambda Forum

Your feedback is important to AWSPlease complete the session evaluation and tell us what you think.

(I read every comment!)

Page 30: AWS Lambda: Event-Driven Code in the Cloud

CHICAGO