AWS Elastic Beanstalk is the fully managed service that lets us quickly deploy an application on to AWS and handles everything on its own including infrastructure provisioning. Think of it as a Platform as a Service (PasS) level offering. It allows Developers to take control of the deployment of their code but without spending time worrying about the underlying infrastructure (the “Ops”), thus speeding up their development cycles and providing faster feedback loops.
Elastic Beanstalk is quiet apt for an public facing production deployment application roll outs as it involves features those ensure -
Elastic Beanstalk supports Java, .NET, PHP, Node.js, Python, Ruby, Go, Docker and Multi-Container Docker on familiar servers such as Apache, Nginx, Passenger, and IIS.
There is no additional charge for Elastic Beanstalk – you pay only for the AWS resources needed to store and run your applications.
Elastic Beanstalk reduces management complexity without restricting choice or control. You simply upload your application, and Elastic Beanstalk automatically handles the details of capacity provisioning, load balancing, scaling, and application health monitoring. In order to leverage the full flexibility of the elastic beanstalk and utilising the plethora of settings one can use the AWS Command Line Interface (AWS CLI), or eb, a high-level CLI designed specifically for Elastic Beanstalk.
There are two parts to this -
Infrastructure Deployment for Beanstalk
Spinning up an new elastic beanstalk application manually involves -
As, the above is way too manual , prone to error , inconsistency , involves system admins constant assistance , and not at all DevOps oriented; the need for IaC comes into picture.
Having familiar with the terraforms ability https://www.terraform.io/intro/vs/index.html for provisioning AWS infrastructure , it makes sense to choose it as an goto tool to get the task done.
One can create their own custom terraform modules using the terraform resources -
, or can utilize few pre-build published modules from terraform repositories like -
For an intensive list of all the elastic beanstalk namespaces , ref -
Sample directory structure & code snippet -
After your environment is launched, you can then manage your environment and deploy new application versions. The following diagram illustrates the workflow of Elastic Beanstalk.
To achieve this, we can leverage any of the SCM tools capable to run deployment pipelines, with push-based deployment triggers. Here, I will demonstrate how to use Gitlab -
Firstly, Get the Gitlab Registration Token
Get the Gitlab Runner Registration token by clicking CI/CD in the settings of your Gitlab Repository.
Go to Runners, under specific runners, get the registration token and save it.
• Specify the Gitlab Variables
Click Settings → CICD → Variables, specify variables for the AWS Access/Secret keys for your AWS accounts -
Prepare the Gitlab Runner
Create a config file for the Docker Gitlab Runner using the below command on the EC2 Server:
Verify the docker container
Clone the Gitlab Repository which has the application source code and add the below files for configuring CI/CD:
Sample pipeline code for gitlab-ci.yml -