AWS Lambda - A quick introduction #advancedaws

18
@crichardson AWS Lambda A quick introduction Chris Richardson Author of POJOs in Action Founder of the original CloudFoundry.com @crichardson [email protected] http://plainoldobjects.com http://microservices.io

Transcript of AWS Lambda - A quick introduction #advancedaws

Page 1: AWS Lambda - A quick introduction #advancedaws

@crichardson

AWS LambdaA quick introduction

Chris Richardson

Author of POJOs in ActionFounder of the original CloudFoundry.com

@[email protected]://plainoldobjects.comhttp://microservices.io

Page 2: AWS Lambda - A quick introduction #advancedaws

@crichardson

“The Magic Happens at the Intersection of

Functions, Events and Data”

Page 3: AWS Lambda - A quick introduction #advancedaws

@crichardson

AWS Lambda is a PaaS*for

event-driven microservices

* in a restricted kind of way

Page 4: AWS Lambda - A quick introduction #advancedaws

@crichardson

NodeJS functions that consume events

S3

Kinesis

DynamoDB

console.log('Loading event');

exports.handler = function(event, context) { console.log('value1 = ' + event.key1); console.log('value2 = ' + event.key2); console.log('value3 = ' + event.key3); context.done(null, 'Hello World'); };

Events

Pricing (once you have exceeded the free tier)$0.0000002 per request

$0.00001667 for every GB-second

Invoke API

Page 5: AWS Lambda - A quick introduction #advancedaws

@crichardson

NodeJS module

Specify event handler

Resource limits

IAM role for lambda execution

Page 6: AWS Lambda - A quick introduction #advancedaws

@crichardson

Page 7: AWS Lambda - A quick introduction #advancedaws

@crichardson

NodeJS-powered home security

Page 8: AWS Lambda - A quick introduction #advancedaws

@crichardson

NodeJS-powered home security

Upload2S3 UploadQueueProcessor

SQS Queue DynamoDBS3

Log file Upload dir.

IpCamViewerWeb App

FTP server Upload image

Page 9: AWS Lambda - A quick introduction #advancedaws

@crichardson

NodeJS + Lambda

Upload2S3

DynamoDBS3

Log file Upload dir.

IpCamViewerWeb App

FTP server

Page 10: AWS Lambda - A quick introduction #advancedaws

@crichardson

S3 notifications

Lambda to invoke

Invoking IAM role

Triggering events

Page 11: AWS Lambda - A quick introduction #advancedaws

@crichardson

Promise-based event handling code

Asynchronouslyprocess event

Invoke success/error handler when all events have been processed

Page 12: AWS Lambda - A quick introduction #advancedaws

@crichardson

s3ObjectProcessor.process() ultimately invokes AWS SDK

Page 13: AWS Lambda - A quick introduction #advancedaws

@crichardson

Uploading the lambda

Page 14: AWS Lambda - A quick introduction #advancedaws

@crichardson

IAM role policieslambda_exec_rolelambda_invoke_role

Permission to invoke lambda

Permission to access DynamoDB tables

Page 15: AWS Lambda - A quick introduction #advancedaws

@crichardson

aws s3 cp IMG_2824.jpg "s3://imagecamimage-std/partitions/20130217/ipcam/

ipcam99/000DC5D76EFE(ipcam99)_1_20130217052637_1219.jpg" aws s3 cp IMG_2824.jpg \

"s3://imagecamimage-std/partitions/20130217/ipcam/ipcam99/000DC5D76EFE(ipcam99)_1_20130217052637_1219.jpg"

DynamoDB table lambda-imagesbyipcamandtimestamp(ipcam, timestamp)

lambda-ipcambydayandtimebucket(ipcamandday)

Page 16: AWS Lambda - A quick introduction #advancedaws

@crichardson

Cloud Watch logs

Page 17: AWS Lambda - A quick introduction #advancedaws

@crichardson

Final thoughts

Useful for writing “simple” AWS-oriented services

What would be nice:

Ability to specific environment variables for externalized configuration, e.g. names of AWS resources

Page 18: AWS Lambda - A quick introduction #advancedaws

@crichardson

@crichardson [email protected]

http://plainoldobjects.com http://microservices.io