Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Running Containerized Node.js Services on AWS Elastic Beanstalk

201 views

Published on

A talk on why focusing on Good Practices trumps Fancy Technology.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Running Containerized Node.js Services on AWS Elastic Beanstalk

  1. 1. Running Containerized Node.js Services on AWS EB zupzup.org ...or “why are there so many buzzwords in my title?”
  2. 2. Running Serverless Containerized Node.js MicroServices on AWS EB and AWS Lambda, Cross-compiled from Rust zupzup.org It could have been worse...
  3. 3. zupzup.org Why so many Buzzwords? ● Back to simple JavaScript Testing ● An inside look into DOM-diffing algorithms ● Learning JavaScript beyond the Fancy Frameworks ● Running Containerized NodeJS Services on AWS EB ● Ponies
  4. 4. zupzup.org Why so many Buzzwords? ● Back to simple JavaScript Testing ● An inside look into DOM-diffing algorithms ● Learning JavaScript beyond the Fancy Frameworks ● Running Containerized NodeJS Services on AWS EB ● Ponies
  5. 5. zupzup.org Why so many Buzzwords? ● Back to simple JavaScript Testing ● An inside look into DOM-diffing algorithms ● Learning JavaScript beyond the Fancy Frameworks ● Running Containerized NodeJS Services on AWS EB ● Ponies
  6. 6. zupzup.org Why so many Buzzwords? ● Back to simple JavaScript Testing ● An inside look into DOM-diffing algorithms ● Learning JavaScript beyond the Fancy Frameworks ● Running Containerized NodeJS Services on AWS EB ● Ponies
  7. 7. zupzup.org ● Back to simple JavaScript Testing ● An inside look into DOM-diffing algorithms ● Learning JavaScript beyond the Fancy Frameworks ● Running Containerized NodeJS Services on AWS EB ● Ponies Why so many Buzzwords?
  8. 8. zupzup.org This Talk ● ~ 30 minutes ● NOT a demo-talk ● NOT a tutorial ● Concepts, Trade-offs & Impulse ● Q&A afterwards (Open Space)
  9. 9. zupzup.org Overview ● ~3 min intro to Docker (Containers) ● ~3 min intro to AWS & AWS EB ● Steps needed to “Run Containe…on AWS EB” ● Trade-offs ● Node.js for “serious applications” ● Things (Libs etc.) I like for node backend development ○ Finally something useful! ● Conclusion
  10. 10. zupzup.org Containers (Docker) ● Containerization ○ “Putting into an isolated environment, which can run anywhere” ● Initially based on LXC (linux containers - 2008) ○ Awkward to use, not widely spread back then ● Idea of a “portable environment” ○ For the whole development cycle (dev - testing - staging - prod) ○ You can do this with VMs (vagrant etc.)
  11. 11. zupzup.org Docker ● No new ideas? Around since 2008? Why the hype? ○ Docker made it mainstream with usability (tooling) and marketing ● A Linux utility that can create, run and ship containers ○ By now a lot more - huge ecosystem ● Lightweight, self-contained Linux process ○ Runs in isolation using cgroups, namespaces etc. ○ Shares kernel of host system ○ Only 1 process per container
  12. 12. zupzup.org Docker (Useful Properties) ● Lightweight, Low Overhead ● Fast Startup ● Stateless ● Declarative & Layered ● Ecosystem (tooling, integrations) for development cycle
  13. 13. zupzup.org Docker ● ./my-app/Dockerfile ○ Description how to build an image (i.e.: template for a container) ● docker build -t mzupzup/my-app . ● docker run mzupzup/my-app ● docker push mzupzup/my-app ○ https://hub.docker.com/ ○ Or any other registry ● docker pull mzupzup/my-app ● ...
  14. 14. zupzup.org AWS ● Amazon Web Services ● Cloud Computing Provider ● On-Demand Model ○ Pay per use ● 16 Geographical Regions ○ Endless Scaling ● Tons of services (~70)
  15. 15. zupzup.org AWS Don’t try to read this, it’s small on purpose!
  16. 16. zupzup.org AWS ● Widely used ● Good Documentation (mostly) ● Lots of Tooling ● 2017 estimate: ~13 billion in revenue
  17. 17. zupzup.org AWS Elastic Beanstalk ● Orchestration Service ● Application consists of multiple “services” ○ Computation & Storage ○ DB & Cache ○ Loadbalancing ○ Deployment ○ ... ● That’s what EB is here to help you with ● No extra costs, just underlying infrastructure
  18. 18. zupzup.org AWS Elastic Beanstalk (start)
  19. 19. zupzup.org AWS Elastic Beanstalk (~10 m later)
  20. 20. zupzup.org AWS Elastic Beanstalk (Config) ● Logs ● Monitoring ● Auto-Scaling ● Adding a Database ● Deployment Strategies ● … ● Basically, everything you need to ship & scale an Application
  21. 21. zupzup.org Running Containerized node.js Services on AWS EB
  22. 22. zupzup.org Monolith Approach (1 Application, 1 Deployment) Loadbalancer API Service (nodeJS) DB SPA (Re-emb-gular.js) CacheSync Service (nodeJS)
  23. 23. zupzup.org MicroServices approach (multiple Applications) Loadbalancer Sync Service (nodeJS) API Service (nodeJS) DB Cache SPA (Re-emb-gular.js) Loadbalancer DB Loadbalancer Edge Service (nginx)
  24. 24. zupzup.org Example nodeJS Dockerfile
  25. 25. zupzup.org Example SPA Dockerfile
  26. 26. zupzup.org Adding a DB
  27. 27. zupzup.org Env Variables for Secrets REALLY_SECRET_PW 1234 const conn = new DB({ host: process.ENV.DB_HOST, pw: process.ENV.REALLY_SECRET_PW, });
  28. 28. zupzup.org AWS EB CLI (for use in CI for example) eb init / eb create eb deploy -> Dockerrun.aws.json eb status / eb health / eb events / eb logs / eb config eb terminate
  29. 29. zupzup.org Example Dockerrun.aws.json
  30. 30. zupzup.org Running Containerized nodeJS Services on AWS EB
  31. 31. zupzup.org Trade-offs, Setup Time ● Very Quick to get something Running ○ e.g.: dev/testing/staging environments ● Don’t need much expertise initially ○ In Production, this can change very quickly ● Likely to be less work/cost than setting up your own cluster (root server etc.) ● Advanced configuration gets complex very quickly
  32. 32. zupzup.org Trade-offs, Cost (Pay Per Use vs. Monthly) ● Very low use: Yes ○ Testing / staging / CI ○ low traffic systems in general ■ my blog :( ● Avg. & fairly constant traffic: No ○ Monthly billing (e.g.: root-servers) often much cheaper ● Veeery High Use: Yes ○ Probably can’t run your own Datacenter ○ Automatic Scaling kicks in ○ Especially on a global scale (multiple regions)
  33. 33. zupzup.org Good Practices ● Containers (not necessarily Docker) ○ “Portable environment” ● Clean CI / CD pipeline ● Well designed architecture ○ Not necessarily Microservices ○ Clear Service Boundaries
  34. 34. zupzup.org node.js for “serious applications” ● “Serious Application” ○ ~ Relevant, productive, (distributed/moderately complex) system which generates value ● Lots of successful examples ○ Linkedin ○ Walmart ○ Uber ○ Paypal ○ … you’ll find those for ANY language / technology…
  35. 35. zupzup.org ● Event-driven, Non-blocking I/O ○ Which is what most web-apps do - they don’t “think” much ● Fast Setup & Iteration Speed ○ Prototyping & Getting sh*t “done”! ● Huge Ecosystem & Community ○ Finding Developers ○ Has a dark side! ● Low Footprint ○ Nice for distributed systems ○ “Build for Obsolescence” What node seems to be good at
  36. 36. zupzup.org What node seems to be less good at ● CPU-intensive tasks ● Hype / Maturity ● Maintenance and Robustness ○ Dynamic vs. Static ○ Error handling ○ Testing ● Async model not intuitive for many ○ Callback Hell ○ Promise Hell ○ Reactive Hell
  37. 37. zupzup.org Good Practices ● Handle all errors ○ Even (especially!) in {asyncPrimitive}-hell ● Write lots(!) of tests ○ Even if asynchronous integration tests are no fun ● “Soft” type checking where it counts ○ Service Boundaries ● Document your code & processes
  38. 38. zupzup.org Libs I like (right now?) for node.js Backend dev ● hapi.js (web framework) ○ joi (request/response validation) ○ boom (http friendly errors) ○ good (monitoring) ● knex (multi-dialect query builder) ● winston (logging) ● node-config (app configuration) ● mocha/chai (testing) ● the classics ○ moment / async / lodash / bluebird / request
  39. 39. zupzup.org Things I try to avoid ● Dependencies (i.e. complexity) ● Unnecessary build-steps (transpiling etc.) ● Mocks ○ If you mock a promise, chaining a mocked promise … what are you really testing? ○ Isolate the actual logic and test it in isolation ● Really anything that makes testing, monitoring & error handling harder ○ Hard enough to get to a “robust” application as it is
  40. 40. zupzup.org ● Containerization has some cool properties ● Node.js is great for iteration speed and starting out ● AWS EB gets you started quickly & scales well later on ● Depending on your trade-offs & experience, it actually might be a good idea to … … “Run containerized node.js services on AWS EB” … … but it also might not in many cases… Conclusion
  41. 41. zupzup.org Focus more on Good Practices and less on Fancy Technology Conclusion
  42. 42. zupzup.org Resources ● http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_ecs.html ● http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/Welcome.html ● https://www.docker.com/ ● https://nodejs.org/en/ ● https://hapijs.com/ ● http://momentjs.com/ ● http://bluebirdjs.com/docs/getting-started.html ● http://knexjs.org/ ● https://github.com/winstonjs/winston ● https://github.com/request/request ● https://mochajs.org/ ● http://chaijs.com/ ● https://lodash.com/ ● https://github.com/caolan/async ● https://github.com/lorenwest/node-config ● http://www.slideshare.net/AmazonWebServices/aws-elastic-beanstalk-running-microservices-and-docker
  43. 43. zupzup.org Thank you! Mario Zupan Freelance & Open Source Software Developer (starting March 1st) You can hire me! https://zupzup.org/ mario@zupzup.org https://github.com/zupzup/ https://twitter.com/mzupzup meee!!

×