There are circumstances like deploying a critical code change into production or running an AB test when running the same application with different code versions is a need. Is this possible when your application is running in Elastic Beanstalk? By default, not, but there is a work around that we’ll describe below.
The classic way to run a service in Beanstalk is a fleet with one or more hosts behind a load balancer. But the load balancer doesn’t know (and must not know) what is running on hosts it manages. We’ll use this detail in our approach. Basically, we build a new environment – let’s name it environment B and deploy on it the newest code version. After that, the only thing left is to add the hosts from that environment in the load balancer of the former environment (main environment, named environment A).
This approach comes with several minuses and the biggest is the operational load. Every time you want to deploy a new version on environment B you have to remove hosts from load balancer, perform the deployment and bring back hosts into load balancer. Also, if any host is replaced, it must be added manually into that environment – a possible work around here is a deployment script to automatically add the hosts in a load balancer specified as environment variable once the deployment is done. Ideally, setup and configuration parameters for environment B should be identical with environment A and it should contain one host. In that way, it is very simple to monitor it and if something very bad reached production, the impact is small. We said monitoring is simple because you always know on which host the deployment is happening and you can connect on it and check logs, host status, etc.
As of today, probably some small features are missing to have 2 different Elastic Beanstalk environments that run for long time periods under the same Load Balancer, but approach we described could be adopted for short periods if the context really requires it.
As always, don’t hesitate to send us your comments and ideas on this topic!