Blue/Green deployments with Elastic Beanstalk - AWS Elastic Beanstalk

Blue/Green deployments with Elastic Beanstalk

Because AWS Elastic Beanstalk performs an in-place update when you update your application versions, your application might become unavailable to users for a short period of time. To avoid this, perform a blue/green deployment. To do this, deploy the new version to a separate environment, and then swap the CNAMEs of the two environments to redirect traffic to the new version instantly.

A blue/green deployment is also required if you want to update an environment to an incompatible platform version. For more information, see Updating your Elastic Beanstalk environment's platform version.

Blue/green deployments require that your environment runs independently of your production database, if your application uses one. If your environment includes a database that Elastic Beanstalk created on your behalf, the database and connection of the environment isn't preserved unless you take specific actions. If you have a database that you want to retain, use one of the Elastic Beanstalk database lifecycle options. You can choose the Retain option to keep the database and environment operational after decoupling the database. For more information see Database lifecycle in the Configuring environments chapter of this guide.

For instructions on how to configure your application to connect to an Amazon RDS instance that's not managed by Elastic Beanstalk, see Using Elastic Beanstalk with Amazon RDS.

To perform a blue/green deployment
  1. Open the Elastic Beanstalk console, and in the Regions list, select your AWS Region.

  2. Clone your current environment, or launch a new environment to run the platform version you want.

  3. Deploy the new application version to the new environment.

  4. Test the new version on the new environment.

  5. On the environment overview page, choose Actions, and then choose Swap environment URLs.

  6. For Environment name, select the current environment.

    
          Swap environment URL page
  7. Choose Swap.

Elastic Beanstalk swaps the CNAME records of the old and new environments, redirecting traffic from the old version to the new version.

After Elastic Beanstalk completes the swap operation, verify that the new environment responds when you try to connect to the old environment URL. However, do not terminate your old environment until the DNS changes are propagated and your old DNS records expire. DNS servers don't always clear old records from their cache based on the time to live (TTL) that you set on your DNS records.