Deploying Highly-Available Dockerized E-commerce website using AWS Elastic Beanstalk
Tags: aws, cloud, docker, vscode
Published: 2023-12-24 21:16:59

Building on the fundamentals covered in my previous article on AWS Elastic Beanstalk, let's now explore the deployment of a highly-available, Dockerized e-commerce application in a custom VPC using AWS Elastic Beanstalk. [https://www.linkedin.com/posts/samuel-ojo-oluwagbenga_unlock-the-power-of-seamless-deployment-with-activity-7144041312550387712-lc8p?utm_source=share&utm_medium=member_desktop]

My Custom VPC will be deployed using terraform (IaC tool) with 2 public and private subnets, an internet gateway and one Nat gateway ( to keep the cost low) in the public subnet.

Focus is not on Terraform deployment, however, you can access the terraform configuration codes and the Dockerfile in the link below.

https://github.com/7hundredtech/Terraform-_-ElasticBeanstalk_Project/tree/main

So lets get started!!!

**Step1: Custom VPC deployed through terraform.**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqb80nnbpg3rwrsixls2.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5vvkb2dfdokwpsanq8dl.png)

**See below from the AWS Management console.**

**VPC**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tpz53qcwku2ygixw4ef.png)

**Internet Gateway**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/36dpdxnt19ut72f9wci3.png)

**Subnets**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nexxermngskqgtpys6ye.png)

**Nat-Gateway**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d3wlepi5eigmgvhlpki6.png)

**Security Group**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gs3mpq7ui6pw432syj6b.png)

**Step 2: Elastic Beanstalk Configuration using the AWS Management Console**

- Navigate to Elastic Beanstalk console and click on create application


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u2r9scnxmklapxwzhtey.png)

**Configure Environment.**

- **Environment tier:** Choose Web server environment
- **Application Name:** Choose application name. I will be using **e-commerce-web**
- **Environment Name:** It will be generate with automatically with your application name, but this can be changed to suit your purpose.
- **Domain:** Leave as default.
- **Environment description:** You can provide any description as required.
- **Platform type:** Select Managed Platform
- **Platform:** Select the platform for running your codes. i will be using Docker.
- **Platform branch** and **version** will be generated automatically.
- **Application code:** Select upload your code. I will be uploading the code for my application from my local machine. Note that it must be a zip file.
- **Version label:** Give your code a version. i will be using Ver01
- **Preset:** Choose high availability because we will be deploying in 2 availability zones.

Click **Next**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/napf8jh45jd5vo1c6rw1.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fhq2tgsjlzh7spkixbae.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8x5vkxeavypqg1pwte59.png)

** Configure service access**

- **Service Role:** Create a new role or use an existing role. I will be using an existing role.
- **Ec2-Key pair:** I wont be using any key pair since i have no intention of logging into the EC2 instances. But if you intend to access the instances, you can create a key pair.
- **Ec2 instance Profile:**I will be using IAM instance profile with managed policies that allow your EC2 instances to perform required operations.

Click **Next**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rzu5deqycpdz99q5z2nm.png)

- **Virtual Private Cloud (vpc):** Select the custom vpc deployed using the terraform code.** dev-vpc**
- **Public IP Address:** Do not activate. we will access our website through the load balancer
- **Instance Subnets:** Select the 2 private subnets from our custom vpc.
- **Database:** We are not connecting to a DB. So do not enable  
Leave other options as default and click on Next


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f0w0wzc687t04o66nvvj.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05z7r2340x9gpkwv1xtk.png)

**Configure instance traffic and scaling**

- **Root Volume (Boot Device):** Leave as default
- **Amazon cloud Monitoring:** Leave as default
- **EC2 Security Group:** Select the security group created with the terraform code.
- **Autoscaling group:** Choose your desired Min and Max number of instances and leave others as options as default
- **Instance type:**Am using t2.micro to keep within the free tier limit.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gu2utf5itdoq3ek0c83t.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/79aygp8edtqri94e2a74.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zopdlqp2ezke3vtjt2uh.png)


**Load Balancer Network Settings**

- **Visibility:** Select Public
- **Load Balancer Subnets:** Select the 2 public subnets from our custom vpc
- **Load Balancer Type:** Select Application Load Balancer .
Leave other options as default and click on Next

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x4i0wzekk5sx749wml8w.png)

**Configure updates, monitoring, and logging**

- Leave all options as default and click Next
- Review your configuration and Click on Submit
- Environment is been launched by Elastic Beanstalk

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tqvg3mky5gbw6mlu1t75.png)

**View events as underlying infrastructure are been deployed using cloud formation **

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/po8x5ma2w3tude6o0z7h.png)

**Environment deployed successfully**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zlhy4k21ov4bt5ekxime.png)

So lets check what Elastic Beanstalk deployed for us.

**EC2 instance for our E-commerce website**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uo3w7f5gv9v0dmyyb9d6.png)


**Autoscaling group**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ju2vi59ym0k22yfe7hf.png)


**Application Load Balancer**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fiiz268w59m4g5e9kh69.png)


**Target Group**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7qir70975fz816pvop7.png)



**Step 3: Accessing our E-commerce website **

Copy and paste the DNS endpoint of the Load balancer in your browser. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ac52tbtb2cbcw4mg6m0.PNG)

The website should display as shown below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lkul3dg62fbot3duanpu.png)

Congratulations!!! We have deployed a highly available e-commerce website using AWS Elastic Beanstalk.

Don't forget to clean up to avoid unexpected bills on your account.

Thanks for Reading.