aws lambda: event-driven code in the cloud

Post on 13-Aug-2015

458 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

©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

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

Triggers Example: Amazon S3

Amazon S3 Bucket Events AWS Lambda

Original image Thumbnail image

1

2

3

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

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

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

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

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

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

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

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

Java Demo: Auto-Compress S3 Files

Using AWS Lambda

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

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

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

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

6/25: Compute for Connected Devices

• Alexa Skills Kit – build

voice-enabled apps

• Uses AWS Lambda

as a connected

device/IoT platform

Alexa Workflow

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

Echo Demo: Voice-Controlled Slack Channel

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

AWS Lambda Regions

AWS Lambda

region

NEW: Tokyo

launched 6/29

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

We’ve been busy.

Now, it’s your turn.

Go to the AWS Lambda console,

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

Don’t stop yet! Add an event

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

Build the world’s easiest mobile

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

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!)

CHICAGO

top related