running containerized node.js services on aws elastic beanstalk

43
Running Containerized Node.js Services on AWS EB zupzup.org ...or “why are there so many buzzwords in my title?”

Upload: zupzuporg

Post on 22-Jan-2018

107 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Running Containerized Node.js Services on AWS Elastic Beanstalk

Running Containerized Node.js Services

on AWS EB

zupzup.org

...or “why are there so many buzzwords in my title?”

Page 2: Running Containerized Node.js Services on AWS Elastic Beanstalk

Running ServerlessContainerized Node.js MicroServices

on AWS EB and AWS Lambda, Cross-compiled from Rust

zupzup.org

It could have been worse...

Page 3: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgWhy 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

Page 4: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgWhy 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

Page 5: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgWhy 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

Page 6: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgWhy 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

Page 7: Running Containerized Node.js Services on AWS Elastic Beanstalk

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?

Page 8: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgThis Talk● ~ 30 minutes

● NOT a demo-talk

● NOT a tutorial

● Concepts, Trade-offs & Impulse

● Q&A afterwards (Open Space)

Page 9: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgOverview● ~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

Page 10: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgContainers (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.)

Page 11: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgDocker● 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

Page 12: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgDocker (Useful Properties)● Lightweight, Low Overhead

● Fast Startup

● Stateless

● Declarative & Layered

● Ecosystem (tooling, integrations) for development cycle

Page 13: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgDocker● ./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

● ...

Page 14: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgAWS● Amazon Web Services

● Cloud Computing Provider

● On-Demand Model○ Pay per use

● 16 Geographical Regions○ Endless Scaling

● Tons of services (~70)

Page 15: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgAWS

Don’t try to read this, it’s small on purpose!

Page 16: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgAWS● Widely used

● Good Documentation (mostly)

● Lots of Tooling

● 2017 estimate: ~13 billion in revenue

Page 17: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgAWS 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

Page 18: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgAWS Elastic Beanstalk (start)

Page 19: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgAWS Elastic Beanstalk (~10 m later)

Page 20: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgAWS Elastic Beanstalk (Config)● Logs● Monitoring● Auto-Scaling● Adding a Database● Deployment Strategies● …● Basically, everything you need to ship & scale an

Application

Page 21: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.org

Running Containerized node.js Services on AWS EB

Page 22: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgMonolith Approach (1 Application, 1 Deployment)

Loadbalancer

API Service (nodeJS)

DB

SPA (Re-emb-gular.js)

CacheSync Service (nodeJS)

Page 23: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgMicroServices approach (multiple Applications)

Loadbalancer

Sync Service (nodeJS) API Service (nodeJS) DB

Cache

SPA (Re-emb-gular.js)

Loadbalancer

DB

Loadbalancer

Edge Service (nginx)

Page 24: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgExample nodeJS Dockerfile

Page 25: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgExample SPA Dockerfile

Page 26: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgAdding a DB

Page 27: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgEnv Variables for Secrets

REALLY_SECRET_PW 1234

const conn = new DB({ host: process.ENV.DB_HOST,pw: process.ENV.REALLY_SECRET_PW,

});

Page 28: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgAWS 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

Page 29: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgExample Dockerrun.aws.json

Page 30: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.org

Running Containerized nodeJS Services on AWS EB

Page 31: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgTrade-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

Page 32: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgTrade-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)

Page 33: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgGood Practices● Containers (not necessarily Docker)

○ “Portable environment”

● Clean CI / CD pipeline

● Well designed architecture○ Not necessarily Microservices○ Clear Service Boundaries

Page 34: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgnode.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…

Page 35: Running Containerized Node.js Services on AWS Elastic Beanstalk

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

Page 36: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgWhat 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

Page 37: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgGood 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

Page 38: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgLibs 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

Page 39: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgThings 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

Page 40: Running Containerized Node.js Services on AWS Elastic Beanstalk

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

Page 41: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.org

Focus more on

Good Practices

and less on Fancy Technology

Conclusion

Page 42: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgResources● 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

Page 43: Running Containerized Node.js Services on AWS Elastic Beanstalk

zupzup.orgThank you!Mario Zupan

Freelance & Open Source Software Developer

(starting March 1st)

You can hire me!

https://zupzup.org/

[email protected]

https://github.com/zupzup/

https://twitter.com/mzupzup

meee!!