aws lambda: how glide uses aws lambda for increased simplicity, scale and speed - pop-up loft tel...

22
AWS Lambda Mo Kamioner, Backend Architect בס”דMarch 13, 2016

Upload: amazon-web-services

Post on 20-Jan-2017

633 views

Category:

Technology


0 download

TRANSCRIPT

AWS LambdaMo Kamioner, Backend Architect

בס”דMarch 13, 2016

Installed on 20M+ devices worldwide

Millions of active users

have sent billions of messages

1PB+ videos stored on S3

10K+ r/w throughput in Dynamo DB

Multi region architecture ensures

sub-second latency

Analytics 1.0

User Redshift

Foreground EC2

Dynamo DB

MySQL

Background EC2 S3 SQS Analytics EC2

Duplicate data (consistency issues)

Difficult to make changes

2+ hours from creation to Redshift

Multiple DB writes per request

Analytics 2.0

User Redshift

Foreground EC2

Dynamo DB Lambda S3 SQS Analytics EC2Kinesis Firehose

Duplicate data (consistency issues) Consistent data (found new bugs)

Difficult to make changes Deploy to Lambda is simple

2+ hours from creation to Redshift 15 minutes max

Multiple DB writes per request One database write

Why Lambda?

• Low maintenance

• Already work in NodeJS

• No database connections (sleek)

• Easily deployable

• Highly scalable

10 Practical Lambda lessons learned

JSLint your code

Douglas Crockfordhttp://www.jslint.com

> jslint badExample.js

badExample.js #1 'notName' was used before it was defined. if (notName === "Mudd") { // Line 5, Pos 5

"use strict";

var name = "Douglas Crockford";

if (notName === "Mudd") { console.log("Your name is Mudd!");}

badExample.js

> jslint goodExample.js

goodExample.js is OK.

"use strict";

var name = "Douglas Crockford";

if (name === "Mudd") { console.log("Your name is Mudd!");}

goodExample.js

Declare variables outside the handler

“Avoid declaring any function variables outside the scope of the handler. Lambda does not guarantee those variables will be refreshed between function invocations”

AWS Lambda Best Practices March 2016

"use strict";

function mapDataLoadOnce(data) { //...}

doInitOnce();

module.exports.handler = function handler(event, context) { function mapDataLoadOnEveryInvocation(data) { //... // `event` and `context` are in scope here }

doInitOnEveryInvocation();

//...

context.succeed("Successfully processed " + event.Records.length + " records.");};

lambda.js

Expect multiple events

Track versions of your code

Screenshot of version tracking

Know when to use the code editor

Keep your functions

light and fast

128 MB is more than you think...

Don’t Ignore Errors

Watch your timeouts

Live demo!

Takeaways

Lambda is simple, scalable and fast

1. JSLint your code2. Declare variables outside the handler3. Expect multiple events4. Track versions of your code5. Know when to use the code editor6. Keep your functions light and fast7. 128 MB is more than you think…8. Stream your data!9. Don’t ignore errors

10. Watch your timeouts

Mo KamionerBackend [email protected] ID: mo

We’re hiring!

http://working.at.glide.rocks