Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AWS Lambda Crash Course

Randall Hunt
December 05, 2014

AWS Lambda Crash Course

A quick intro to AWS Lambda and how to write and play with functions.

Randall Hunt

December 05, 2014

Transcript

17 slides
  1. Agenda • What Is Lambda? • Lambda Console • Lambda

    CLI • APOD Function • Tips and Tricks
  2. What Is AWS Lambda? • A zero-administration compute platform •

    “Just the code” without needing to define the underlying compute resources or OS • Asynchronous functions • Event driven from other services • …Or triggered externally and even chained
  3. Just Two Policies • Invocation Role: really only needs lambda's

    invoke-async permissions • Execution Role: depends on the function
  4. Pricing • You have a discrete task that uses a

    finite # of resouces: RAM + Time. • Workers pick up and complete tasks. • First 1 million requests are free • $0.20 per 1 million requests thereafter • 400,000 GB-Seconds of free compute time per month • $0.00001667 per GB-second after
  5. Limits • Invocation Limits: • 1024 processes or threads •

    1024 file descriptors • Asynchronous (not good for when you need immediate response)
  6. APOD Twitter • User signs up to have their twitter

    background/ image changed to the astronomy picture of the day. • We gather their OAuth token and store in a database • We loop through the tokens with workers and post the updates
  7. Traditional Infrastructure • New picture uploaded to S3 • Create

    SQS queue • Create EC2 Workers • Write fault tolerant logic to connect all of it.
  8. AWS Lambda Infrastructure • Write a lambda function that responds

    to an S3 upload • Write a lambda function that responds to a new user being added in DynamoDB
  9. Tips and Tricks • Node.js is asynchronous: http://callbackhell.com • Use

    a library like async or nesting to make sure your context.done() calls don't cause things to finish too early. • External modules need to be compiled with the same version of libc that's on the Lambda boxes (use Amazon Linux AMI and you should be fine) • console.log() is great for debugging but finding CloudWatch logs is a pain
  10. Tips and Tricks • For sharing functions you need 3

    things: • package.json listing modules needed • event.json listing sample event • execution policy you expect
  11. CLI Tricks aws lambda upload-function \ --function-name twitterUpdate \ --function-zip

    tmp.zip \ --runtime "nodejs" \ --role "arn:aws:iam:::role/lambda_exec_role" \ --handler "index.handler" \ --mode "event" \ --timeout 30
  12. FAQ • More languages coming? • More invocation possibilities on

    the way? • More event sources on the way? • Limits?

More Decks by Randall Hunt

Other Decks in Programming