Running
Containerized Node.js Services
on AWS EB
zupzup.org
...or “why are there so many buzzwords in my title?”
Running Serverless
Containerized Node.js MicroServices
on AWS EB and AWS Lambda, Cross-compiled
from Rust
zupzup.org
It could have been worse...
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
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
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
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
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?
zupzup.org
This Talk
● ~ 30 minutes
● NOT a demo-talk
● NOT a tutorial
● Concepts, Trade-offs & Impulse
● Q&A afterwards (Open Space)
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
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.)
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
zupzup.org
Docker (Useful Properties)
● Lightweight, Low Overhead
● Fast Startup
● Stateless
● Declarative & Layered
● Ecosystem (tooling, integrations) for development cycle
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
● ...
zupzup.org
AWS
● Amazon Web Services
● Cloud Computing Provider
● On-Demand Model
○ Pay per use
● 16 Geographical Regions
○ Endless Scaling
● Tons of services (~70)
zupzup.org
AWS
Don’t try to
read this, it’s
small on
purpose!
zupzup.org
AWS
● Widely used
● Good Documentation (mostly)
● Lots of Tooling
● 2017 estimate: ~13 billion in revenue
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
zupzup.org
AWS Elastic Beanstalk (start)
zupzup.org
AWS Elastic Beanstalk (~10 m later)
zupzup.org
AWS Elastic Beanstalk (Config)
● Logs
● Monitoring
● Auto-Scaling
● Adding a Database
● Deployment Strategies
● …
● Basically, everything you need to ship & scale an
Application
zupzup.org
Running Containerized node.js Services on AWS EB
zupzup.org
Monolith Approach (1 Application, 1 Deployment)
Loadbalancer
API Service (nodeJS)
DB
SPA (Re-emb-gular.js)
CacheSync Service (nodeJS)
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)
zupzup.org
Example nodeJS Dockerfile
zupzup.org
Example SPA Dockerfile
zupzup.org
Adding a DB
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,
});
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
zupzup.org
Example Dockerrun.aws.json
zupzup.org
Running Containerized nodeJS Services on AWS EB
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
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)
zupzup.org
Good Practices
● Containers (not necessarily Docker)
○ “Portable environment”
● Clean CI / CD pipeline
● Well designed architecture
○ Not necessarily Microservices
○ Clear Service Boundaries
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…
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
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
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
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
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
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
zupzup.org
Focus more on
Good Practices
and less on Fancy Technology
Conclusion
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
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!!

Running Containerized Node.js Services on AWS Elastic Beanstalk

  • 1.
    Running Containerized Node.js Services onAWS EB zupzup.org ...or “why are there so many buzzwords in my title?”
  • 2.
    Running Serverless Containerized Node.jsMicroServices on AWS EB and AWS Lambda, Cross-compiled from Rust zupzup.org It could have been worse...
  • 3.
    zupzup.org Why so manyBuzzwords? ● 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.
    zupzup.org Why so manyBuzzwords? ● 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.
    zupzup.org Why so manyBuzzwords? ● 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.
    zupzup.org Why so manyBuzzwords? ● 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.
    zupzup.org ● Back tosimple 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.
    zupzup.org This Talk ● ~30 minutes ● NOT a demo-talk ● NOT a tutorial ● Concepts, Trade-offs & Impulse ● Q&A afterwards (Open Space)
  • 9.
    zupzup.org Overview ● ~3 minintro 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.
    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.
    zupzup.org Docker ● No newideas? 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.
    zupzup.org Docker (Useful Properties) ●Lightweight, Low Overhead ● Fast Startup ● Stateless ● Declarative & Layered ● Ecosystem (tooling, integrations) for development cycle
  • 13.
    zupzup.org Docker ● ./my-app/Dockerfile ○ Descriptionhow 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.
    zupzup.org AWS ● Amazon WebServices ● Cloud Computing Provider ● On-Demand Model ○ Pay per use ● 16 Geographical Regions ○ Endless Scaling ● Tons of services (~70)
  • 15.
    zupzup.org AWS Don’t try to readthis, it’s small on purpose!
  • 16.
    zupzup.org AWS ● Widely used ●Good Documentation (mostly) ● Lots of Tooling ● 2017 estimate: ~13 billion in revenue
  • 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.
  • 19.
  • 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.
  • 22.
    zupzup.org Monolith Approach (1Application, 1 Deployment) Loadbalancer API Service (nodeJS) DB SPA (Re-emb-gular.js) CacheSync Service (nodeJS)
  • 23.
    zupzup.org MicroServices approach (multipleApplications) Loadbalancer Sync Service (nodeJS) API Service (nodeJS) DB Cache SPA (Re-emb-gular.js) Loadbalancer DB Loadbalancer Edge Service (nginx)
  • 24.
  • 25.
  • 26.
  • 27.
    zupzup.org Env Variables forSecrets REALLY_SECRET_PW 1234 const conn = new DB({ host: process.ENV.DB_HOST, pw: process.ENV.REALLY_SECRET_PW, });
  • 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.
  • 30.
  • 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.
    zupzup.org Trade-offs, Cost (PayPer 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.
    zupzup.org Good Practices ● Containers(not necessarily Docker) ○ “Portable environment” ● Clean CI / CD pipeline ● Well designed architecture ○ Not necessarily Microservices ○ Clear Service Boundaries
  • 34.
    zupzup.org node.js for “seriousapplications” ● “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.
    zupzup.org ● Event-driven, Non-blockingI/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.
    zupzup.org What node seemsto 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.
    zupzup.org Good Practices ● Handleall 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.
    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.
    zupzup.org Things I tryto 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.
    zupzup.org ● Containerization hassome 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.
    zupzup.org Focus more on GoodPractices and less on Fancy Technology Conclusion
  • 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.
    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!!