For the tech and e-commerce companies to win the race between competitors while releasing new features of their products before their competitors is very important. Releasing fast without decreasing the quality of the product makes some difference among the competitors. Therefore testing before release has a critical importance in product quality. The ability to run these tests in parallel also very critical for fast release. In this article we will share our experiences on creating a dynamic test environments on AWS.

Image for post

Before the operation, we isolated production, staging and test environments by using sub accounts. Infrastructure as a code perspective took place in whole process. We used Terraform and Ansible for the provisioning processes. And for the orchestration processes we used Jenkins by writing a Groovy Script. For some of the Cron Stages we used Lambda service by writing Python Script. The other services that we used on AWS are; S3, EC2, RDS, ELB, Lambda, Route 53.

Image for post
Image for post
General Architect

First thing that wanted us and we should solve is to run the test with realistic data. We solve it by returning prod environment database’s daily backups periodically to the relevant test environments incrementally. This process is done via Lambda service by writing a Pyhton Script.

Secondly we have provisioned API and Web servers along with ELB dynamically. Here we created a dynamic test environment with Terraform template by choosing required releases and components on Jenkins(choosed by the user). And of course we tagged Branch & App name and tag id as a name.

On the third place, we created templates by separating application configs which is environment based. We used Ansible via Jinja template for these configs.

On the fourth place, we sent the package that we created to S3 bucket after we edited the code. And then we discovered the environment to deploy by the tag and deployed it.

On the fifth place, we took the environment that we created behind the ELB. After that we set DNS record on route 53 with branch and application names. Then we send it to the related ELB target.

And finally we should terminate the environments that we created. We have developed some methods for this operation. One of them is terminating the unused environments by triggering Lambda function via Python script that we wrote. And for the other method, we trigger the same function on Jenkins and terminate the environment manually.

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store