Kristian Glass - Do I Smell Burning?

Mostly technical things

Three Tips To Get The Most Out Of AWS Elastic Beanstalk

AWS Elastic Beanstalk is one of my favourite Platforms as a Service - essentially it’s Heroku but with more levers.

I’ve used it for tiny personal projects (though nowadays I’d probably use Lambda and a framework like Zappa or similar), and I’ve used it as the production platform handling significant traffic at previous jobs.

I think it’s a massively under-appreciated AWS service. All too often people seem to skip over it in favour of more powerful but more complex services like ECS or EKS, and I think they’re missing a trick.

Here are some tips for getting the most out of Elastic Beanstalk.

Use the Docker platform

Like Heroku, Elastic Beanstalk lets you say “this app is written in $lang, here’s a blob of $lang, please go fetch dependencies and build and run it automagically”.

Don’t do that.

Use the Docker platform and push a Docker image (or a zip file containing a Dockerfile if you’re getting started and happy for it to handle the image build)

You get control of how your app builds, you get more parity between local development and your deployment environment (because it’s Just Docker) and your app is nicely portable if you decide to move elsewhere.

Don’t let it manage your database

Elastic Beanstalk has this thing where it offers to manage an RDS instance for your app for you.

Don’t do it.

It looks neat, it looks convenient, it’s a pain.

You don’t want your database lifecycle coupled to that of your Elastic Beanstalk application.

You want to be able to treat your apps as stateless (or as good as). You probably want to be able to spin up multiple apps backed by the same services (depending on how you do deployments). And finally, frankly, sometimes the AWS internal state management of an Elastic Beanstalk app can get unhappy (like if you hit a resource limit during a deploy) and the easiest fix is to just rebuild the Beanstalk environment, which is much less of a problem if it’s just managing ephemeral app instances and not your database too.

Use CloudFormation

Elastic Beanstalk provides a high enough and powerful enough abstraction layer that you can go a long way by just manually configuring it via the console.

Fundamentally though, Infrastructure as Code is the way forward - configure your system with version-controlled, reviewer, testable code, rather than coordinated poking of things in a web UI.

A bit of YAML with CloudFormation / Sceptre goes a long way, or Terraform if that’s your thing.

Do it.

That said, I would, and have, preferred a manual Elastic Beanstalk setup to the sprawling complexity of a DIY Ansible/Puppet/Chef/bash system that manually manages ASGs and builds AMIs and rotates EC2 instances…

So

I like being able to use good existing solutions for my problems. I think Platforms as a Service solve a lot of my “I just want this app to run somewhere”-shaped problems. I like AWS Elastic Beanstalk as a PaaS, and these things have helped me get the most out of it, and I hope they help you too.

Comments