Pro Yearly is on sale from $80 to $50! »

Caching in AWS Lambda

Caching in AWS Lambda

You want to optimize your performance in your AWS Lambda functions and reduce infrastructure costs by avoiding expensive API calls? You should think about caching data in your function! In this talk, I'll show you three different options how to cache data in Lambda: simple caching, custom caching and managed caching.

023594dc361cab87c8e40d03ba0f3b18?s=128

sebastianhesse

December 06, 2018
Tweet

Transcript

  1. None
  2. Available options to cache data in AWS Lambda and how

    to use them. CACHING IN AWS LAMBDA
  3. We´re

  4. Quick recap what AWS Lambda is and how it looks

    like. AWS LAMBDA
  5. SIMPLE AWS LAMBDA FUNCTION: NODEJS

  6. SIMPLE AWS LAMBDA FUNCTION: JAVA

  7. DEPLOYMENT PROCESS Lambda Function Lambda Function </> Code Artifact AWS

    Lambda
  8. REASONS FOR CACHING

  9. BETTER PERFORMANCE Avoid slow API calls or computations. REDUCE COSTS

    Avoid calls which cost you money, e.g. to your database. REASONS
  10. PAY FOR WHAT YOU USE

  11. LAMBDA SCALING GET Name for X GET Name for X

    GET Name for X GET Name for X DynamoDB
  12. TYPICAL CACHING SETUP CACHE Your app DynamoDB

  13. "Tha)'s e-./. I've 3456 t8a9 - h:;<re3 9=m6.." You —

  14. START CODING?!

  15. INFRASTRUCTURE UNCERTAINTIES Functions are only instantiated when needed. Functions might

    be shut down at any time.
  16. CUSTOM Setup a caching instance by your own. CACHING OPTIONS

    MANAGED Use a managed caching service. SIMPLE Cache data only inside Lambda functions.
  17. Understanding the process how a Lambda function is called. LAMBDA

    EXECUTION PROCESS
  18. LAMBDA EXECUTION PROCESS Response Time (ms) 0 250 500 750

    1000 # Number Of Request 1 2 3 4 5 6 7 8 9 10 Cold start
  19. Called by AWS Lambda LAMBDA EXECUTION PROCESS

  20. LAMBDA EXECUTION PROCESS 1.) Only executed at cold start 2.)

    Executed each time
  21. Cache data without using a caching service or library. SIMPLE

    CACHING
  22. SIMPLE CACHING

  23. SIMPLE CACHING

  24. SIMPLE CACHING

  25. SIMPLE CACHING

  26. SIMILAR IN JAVA Field initialization, constructor, etc.

  27. PRO TIP TIME FOR INITIALIZATION IS NOT CHARGED BY AWS.

  28. PRO TIP

  29. PRO TIP

  30. PRO TIP

  31. PRO TIP

  32. PRO TIP

  33. SIMPLE CACHING

  34. AFTER No data synchronization between instances of your Lambda functions.

    BEFORE Low cost caching without performance overhead.
  35. Use a bullet-proof caching library and host it by yourself.

    CUSTOM CACHING SERVICE
  36. CUSTOM CACHING SETUP 1.) GET Name for X CACHE 2.)

    GET Name for X 3.) SET Name for X DynamoDB
  37. "Whe; /4: la@;Ah B; EC2 in.9-nH6 Iit84:9 sJeA=fLM5g a .@On6),

    it's a@)QRat=HBSlL Sa@nHT6d i;94 B deV-:St .uOnX) M5 yo@[ <6fa@\9 V^_." https://docs.aws.amazon.com/vpc/latest/userguide/default-vpc.html —
  38. "By 3ea-:l), re.4:bce. I=t8M5 a V^_ -r6 ;o9 -cH6dsieSX f[QR

    wi)T=n B LahOd- V:5c)i45" https://docs.aws.amazon.com/lambda/latest/dg/vpc.html —
  39. LAMBDA IN VPC ACCESS POSSIBLE, BUT LONGER STARTUP TIMES.

  40. LAMBDA VPC STARTUP VPC Network Hardware Image: https://www.flaticon.com/free-icon/network-interface-card_969356 "A Serverless

    Journey: AWS Lambda Under the Hood" https://www.youtube.com/watch?v=QdzV04T_kec&t=2400
  41. CUSTOM CACHING SETUP VPC Lambda Subnet Cache Subnet Public Subnet

  42. Demo

  43. Use a managed caching service instead of maintaining your own.

    MANAGED CACHING SERVICES
  44. AWS ELASTICACHE REDIS + MEMCACHED

  45. MAINTENANCE AWS is regularly taking care of updates. ADVANTAGES COMPATIBILITY

    Redis and Memcached well supported caching solutions. GET STARTED Easy setup and ready to go.
  46. SIMILAR SETUP LIKE CUSTOM CACHING

  47. Demo

  48. SEBASTIAN HESSE Software Engineer | www.k15t.com | @seeebiii CHARLIE IS

    MY HOMEBOY CHARLIE IS MY HOMEBOY K15t Software Example code @ GitHub: https://github.com/seeebiii/caching-in-aws-lambda
  49. NEW MEETUP SERIES: K15T TEAM TALKS TOPIC: GIT TOGETHER More

    information: https://www.meetup.com/de-DE/K15tTeamTalks/events/256232999/