AWS Lambda: Event-driven Code in the Cloud

29
©2015, Amazon Web Services, Inc. or its affiliates. All rights reserved Mobile Compute with AWS Lambda Dr. Tim Wagner, General Manager AWS Lambda April 9, 2015 | San Francisco, CA

Transcript of AWS Lambda: Event-driven Code in the Cloud

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

Mobile Compute with AWS Lambda

Dr. Tim Wagner, General Manager AWS Lambda

April 9, 2015 | San Francisco, CA

Event-Driven Compute in the Cloud

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

– Triggered by events in other services:

• PUT to an Amazon S3 bucket

• Write to an Amazon DynamoDB table

• Record in an Amazon Kinesis stream

– Makes it easy to…

• Transform data as it reaches the cloud

• Perform data-driven auditing, analysis, and notification

• Kick off workflows

Data Triggers: Amazon S3

Amazon S3 Bucket Events AWS Lambda

Original image Thumbnailed image

1

2

3

Data Triggers: Amazon DynamoDB

AWS LambdaAmazon DynamoDB

Table and Stream

Send Amazon SNS

notifications

Update another table

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

AWS Lambda now Generally Available

Production Release of AWS Lambda

• Larger default limits– 100 concurrent executions

– 1,000 invokes per second

– Increases available via AWS customer service

• Preview label removed– Updated API based on feedback during preview

– Multiple Lambda functions per stream

– Easier to use programming model

Mobile Compute: Building Backends with Lambda

Launching Mobile Compute

• Request/response

• AWS Mobile SDK

• Easy Personalization

…for devices

…for end usersAWS LambdaMobile App

Event-Driven Compute in the Cloud and for Devices

• Request / response– Create instantly scalable backends for mobile apps

– Run stateless computations for web apps without servers

– Build cloud-based IoT ecosystems using C/C++ libraries

– Complements the existing asynchronous functionality

AWS Mobile SDK

• Build high quality mobile apps quickly and easily.

• AWS Lambda now available in:

– AWS mobile SDK for Android

– AWS iOS mobile SDK

Easy Personalization

Which device is she using?

?

Which end user is this?

?

Demo: Building a Mobile Backend with

AWS Lambda

No Infrastructure to Manage

• Focus on business logic,

not infrastructure

• Upload your code; AWS

Lambda handles:

• Capacity

• Scaling

• Deployment

• Monitoring

• Logging

• Web service front end

• Security patching

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

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.

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 GB-s of compute.

Every month, every customer.

Using AWS Lambda

Calling Lambda Functions

• Call from mobile or web apps– Wait for a response or send an event and continue

– AWS SDK, AWS Mobile SDK, REST API, CLI

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

• Process DynamoDB changes or Amazon Kinesis records as events:– Ordered model with multiple records per event

– Unlimited retries (until data expires)

Writing Lambda Functions

• The Basics– Stock node.js

– AWS SDK comes built in and ready to use

– 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

AWS Lambda or Amazon EC2 / Amazon ECS?

AWS Lambda

• Request-driven

• Prioritizes ease of use –one OS, default hardware choice

• AWS owns and manages the infrastructure

• Implicit scaling; just make requests

Amazon EC2 and Amazon ECS

• Infrastructure rental

• Flexible – choose instance type, OS, language, …

• You own and configure the infrastructure

• Scale by provisioning instances or containers

New Features

New AWS Event Sources for 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

Lambda FunctionSNS

New AWS Event Sources for Lambda

• Amazon Cognito– Before: Easily synchronize user data across their devices

– Now: Take action when that data changes

– Examples: Verify and respond to game state updates

Lambda FunctionAmazon Cognito

How can you use these features?

“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”

Amazon Cognito +

Lambda + SNS

“I want to transform

the records in a

click stream or an

IoT data stream”

Amazon Kinesis +

Lambda

New Authorization and Auditing Features

• Easier setup and configuration– No need for invocation roles

– Use resource policies to enable senders to call your function

• Cross-account access support– Securely grant execution access to third parties

– Send events from S3 buckets in a different AWS account

• AWS CloudTrail integration– Track AWS Lambda API calls in AWS CloudTrail logs

– Audit access logs easily with a Lambda function

Improved Metrics and Diagnostics

• Discover and take action when you reach your

concurrent execution limits– New Amazon CloudWatch throttling metric

• Find relevant log entries faster– Sort CloudWatch Logs by time of last entry

– See creation time in log stream names and easily filter on it

– View the target log stream in your Lambda function

Java

• You can already call Java programs from

Lambda functions today…– Java and other languages are automatically included in your

filesystem view…don’t wait to start using them!

– Freezing ensures you don’t pay repeatedly for JVM boot

• We’ll make this even easier with built-in support

for AWS Lambda functions written in Java.

Three Next Steps

1. Go to the AWS Management Console to create and test your

first Lambda function. The first 1M requests each month are on us!

2. Use the AWS Mobile SDK and Lambda to quickly create an

instantly scalable mobile app.

3. Use AWS Lambda to add custom logic to S3, DynamoDB, SNS,

Amazon Kinesis, or Amazon Cognito events…no servers required!

SAN FRANCISCO