What is AWS Elastic Beanstalk?
AWS Elastic Beanstalk is a Platform as a Service (PaaS) solution provided by Amazon Web Services (AWS) that simplifies the deployment and management of web applications. It supports multiple programming languages and runtime environments such as Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker. AWS Elastic Beanstalk allows developers to focus on their applications while AWS handles the underlying infrastructure and operational tasks.
Components of AWS Elastic Beanstalk
Application Version: Represents a specific iteration or release of an application's codebase.
Environment Tier: Defines the infrastructure resources allocated for an environment (e.g., web server environment, worker environment).
Environment: Represents a collection of AWS resources running an application version.
Configuration Template: Defines the settings for an environment, including instance types, scaling options, and more.
Advantages of AWS Elastic Beanstalk
Highly scalable
Fast and simple to begin
Quick deployment
Supports multi-tenant architecture
Simplifies operations
Cost efficient
Elastic Beanstalk Environment
Web Server Environment: Web server environments are suitable for hosting web applications that handle incoming HTTP requests.
Components:
Auto Scaling Group: Web server environments typically include an Auto Scaling group of EC2 instances. This allows the environment to automatically scale the number of instances based on demand.
Elastic Load Balancer (ELB): An ELB is used to distribute incoming traffic among the instances in the Auto Scaling group. This enhances the availability and fault tolerance of the application.
Web Server: The web server environment is configured to handle incoming HTTP requests and respond to client requests.
Worker Environment: The Worker environments are suitable for applications that perform background processing or handle tasks independently of incoming HTTP requests.
Components:
Auto Scaling Group: Similar to web server environments, worker environments include an Auto Scaling group of EC2 instances. However, these instances are configured to perform background processing tasks.
Message Queue (Optional): Worker environments often use message queues, such as Amazon SQS, to distribute tasks among worker instances. This allows for asynchronous and distributed processing.
Worker Process: Worker environments are configured to run background processes or tasks independently of the web server. They are not directly involved in handling HTTP requests.
Choosing between a web server environment and a worker environment depends on your application's nature and the workload it needs to handle.
In some cases, applications may use a combination of web server and worker environments to handle different aspects of their functionality.
Deploying the 2048 game using Docker and the AWS Elastic Beanstalk.
The Github Repo for the 2048 Game project to be deployed, can be found here.
Containerization of the 2048 Web Application using Docker.
Create an EC2 Instance on AWS and connect to it using SSH
Then, install Docker and Docker runtime on the EC2 instance.
Use the below command to check the status of the docker after installation.
sudo systemctl status docker
Create a folder named "2048", and it is in this folder you will create your Dockerfile.
mkdir 2048
cd 2048
vim Dockerfile
Use the Vim editor to create and write in your "Dockerfile". Save and exit the editor.
FROM ubuntu:22.04
RUN apt-get update
RUN apt-get install -y nginx zip curl
RUN echo "daemon off;">>/etc/nginx/nginx.conf
RUN curl -o /var/www/html/master.zip -L https://codeload.github.com/jabir000/2048/zip/master
RUN cd /var/www/html/ && unzip master.zip && mv 2048-master/* . && rm -rf 2048-master master.zip
EXPOSE 80
CMD ["/usr/sbin/nginx", "-c", "/etc/nginx/nginx.conf"]
Build the Image: Run the following command to build the Docker image
docker build -t "your_docker_image" .
Use the below command to verify the Image:
sudo docker images
Run a Container from the Image using the below command:
sudo docker run -d -p 80:80 "your_image_id"
Use the below command to verify the Container:
sudo docker ps
You can then access your game by pasting the public IP address of your EC2 instance in your browser.
The 2048 game was successfully deployed using Docker.
Deploying the 2048 game using AWS Elastic Beanstalk
- Open the AWS Management Console and go to the Elastic Beanstalk service.
- Click on "Create Application"
- Configure environment: Choose "web server environment" under the Environment tier. Provide a name for your application and provide the Environment description.
Choose "Managed platform" as the Platform type. Choose "Docker" as the platform.
Under the Application code, choose "Upload your code"
- Upload the ZIP archive containing your application code. Provide a version label and upload the Dockerfile you created.
For the Configuration presets, choose "Single instance (free tier eligible)"
Configure service access: Select the “use an existing service role”, then go on to create an EC2 Instance profile in the IAM console with the required permissions for AWS Elastic Beanstalk as listed below.
a. AWSElasticBeanstalkWebTier
b. AWSElasticBeanstalkWorkerTier
c. AWSElasticBeanstalkMulticontainerDocker
Do not use the default VPC, create your custom VPC with the necessary inbound rules on the security group allowing HTTP/HTTPS traffic.
Choose the custom VPC you created and a Public subnet for the instance settings.
Then skip to Review: Review your configuration and Click on "Submit"
Wait for Deployment: Elastic Beanstalk will automatically handle the deployment. Monitor the progress in the AWS Management Console.
Access the Deployed Application: Once the deployment is complete, access the game application through the provided domain.
Thank you.