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

Fearless Ops with Stax

Ric Lister
September 05, 2018

Fearless Ops with Stax

How I write cloudformation templates and do Ops without stress or fear.

Ric Lister

September 05, 2018
Tweet

More Decks by Ric Lister

Other Decks in Technology

Transcript

  1. Motivation Too much Ops has: • Stress • Sleepless nights

    • Craziness • Fear! Can we do without them?
  2. What are we afraid of? • Instability • Going slow

    • Mutability: changing things • Pets
  3. Pets Why are pets bad? • Live too long •

    Accumulate magic: config and data • Tempt us to make manual changes • We fear for their health • We don’t trust their replacements
  4. Cattle Embracing cattle gives us the following superpowers: • Automation

    is the norm: autoscaling, deployment • Config must be done as code • Results in repeatability and trust • We can embrace failure and chaos engineering • Automation and code allow multiple copies • Multiple copies means we can move fast
  5. Ops Code as First Class Citizen • Infrastructure must be

    change-controlled and repeatable • Operations source-code is in same git repo as application code • Every release is tracked as a single SHA in Github • Check out a SHA to get a fully self-contained ops+app setup • We use AWS Cloudformation templates to describe all resources
  6. Copying the database around • Every stack has a complete

    database copy • Use SQS and workers to copy data between dynamodb tables • Migrations are performed at the same time as copy • Shoryuken workers for multi-threaded processing github.com/phstc/shoryuken
  7. Sync database changes • Track changes since our bulk copy

    • DynamoDB streams to monitor these changes • New data is continuously migrated • Same migration logic as with bulk copy • No more migrations on release day!
  8. Stax Stax is a simple ruby framework for defining and

    controlling an application using multiple, linked Cloudformation stacks. Makes it easy to create and manipulate a full application for every git branch. Plugins for manipulating specific AWS resources. Plugins for adding non-AWS resources. Pragmatic: Ruby Stack class is designed to be sub-classed and monkey-patched to handle hacks and edge-cases. github.com/rlister/stax
  9. Adding custom commands module Stax class Frontend < Stack ##

    create a new command desc 'dns', 'show DNS entry for this stack' def dns puts stack_output(:DnsRecord) end end end
  10. Extending existing commands Monkey-patching is idiomatic in stax. module Stax

    class Frontend < Stack ## monkey-patch the subclass create method desc 'create', 'create stack' def create super dns end end end
  11. Writing templates Stax can use Cloudformation templates written in: •

    cfer • json • yaml It would be trivial to add any other template generator that emits json or yaml suitable for the Cloudformation API.
  12. Stax generators Stax has rails-like generators to do the heavy-lifting

    of Cloudformation boilerplate. See github.com/rlister/stax-examples.
  13. Stax extensions • stax-examples: example generators for common uses github.com/rlister/stax-examples

    • stax-nag: linting for templates github.com/rlister/stax-nag • stax-stacksets: WIP cloudformation stacksets github.com/rlister/stax-stacksets • stax-datadog: Datadog dashboard creation with stax github.com/rlister/stax-datadog
  14. Principles • Keep it simple • Immutable: nothing is ever

    changed once deployed • Automation: infrastructure, config, and deployment is all automated • Embrace failure • Pragmatism: there are always edge-cases, plan for them