AWS Elastic Beanstalk: Deploying the 2048 Game

AWS Elastic Beanstalk: Deploying the 2048 Game

Β·

8 min read

Introduction:)

πŸš€ Another exciting day in the #90DaysOfDevOps journey! Today, we're going into a new AWS service - AWS Elastic Beanstalk*! 🌱 We'll also be taking a fun step by* uploading the classic 2048 game onto this platform.

What is AWS Elastic Beanstalk?

AWS Elastic Beanstalk is a Platform as a Service (PaaS) provided by Amazon Web Services (AWS) that simplifies the process of deploying and managing web applications. It allows developers to focus on writing code without getting bogged down by the underlying infrastructure.

With Elastic Beanstalk, you can simply upload your code, and it automatically handles the deployment, capacity provisioning, load balancing, and automatic scaling of your application.

Elastic Beanstalk supports a variety of programming languages and frameworks, including Java, Python, Ruby, PHP, Node.js, Go, and Docker. It also supports a variety of AWS services, such as EC2, S3, RDS, and ElastiCache.

Why do we need AWS Elastic Beanstalk?

Imagine you're a part of a big team working on a project. Some team members might be in different cities or even different countries. In the past, it was tricky to share the software you were working on with everyone. But with AWS Elastic Beanstalk, it's like having a magic tool. It lets you easily share your applications with all your team members, no matter where they are. So everyone can work on the same project smoothly, even if they're far apart. It's like a superhighway for sharing and working on software together!

Advantages of AWS Elastic Beanstalk

  1. Highly scalable: Allows flexible scaling up or down of resources based on demand.

  2. Fast and simple to begin: Simplifies application deployment process with networking aspects taken care of by Elastic Beanstalk.

  3. Quick deployment: Enables easy uploading and deployment of applications without worrying about networking concepts.

  4. Supports multi-tenant architecture: Provides virtual environments for separate organizations or divisions within an organization.

  5. Simplifies operations: Makes it easy to maintain and support deployed applications using Elastic Beanstalk services.

  6. Cost efficient: Offers cost optimization compared to deploying on-prem servers.

Components of AWS Elastic Beanstalk

AWS Elastic Beanstalk consists of a few important components which are required while deploying an application.

  • Application: It refers to a unique label which is used as a deployable code for a web application

  • Application Version: This 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: This 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.

    There are two types of environments: web server and worker.

    Web server environments are front-end facing, accessed directly by clients using a URL.

    Worker environments support backend applications or micro apps.

Elastic Beanstalk Environment

AWS Elastic Beanstalk provides two types of environments: web server environments and worker environments. Here's when to use each:

  1. Web Server Environment:

    • Use Case: This environment is suitable for applications that serve web traffic or HTTP requests.

    • Examples:

      • Web applications like websites, APIs, or web services.

      • Applications with a user interface accessed through a browser.

    • Key Features:

      • Automatically configures web servers (e.g., Apache, Nginx).

      • Handles incoming HTTP requests and routes them to the appropriate instance.

    • Configuration:

      • You can configure your web server environment to use specific platforms and choose between various configurations (e.g., load balancing, auto-scaling).
    • Scalability:

      • Easily scales based on web traffic and load.
    • Monitoring:

      • Provides metrics and monitoring specifically tailored for web traffic.
    • Example Use Case:

      • Hosting a website, a RESTful API, or a web application.
  2. Worker Environment:

    • Use Case: This environment is used for background tasks or worker processes that perform tasks independently of web requests.

    • Examples:

      • Batch processing, data analysis, file processing, and other tasks that don't require direct interaction with end users.
    • Key Features:

      • Does not handle incoming HTTP requests; instead, it processes background tasks.

      • Suitable for applications with asynchronous processing requirements.

    • Configuration:

      • Can be configured to process tasks from a work queue (e.g., Amazon SQS).
    • Scalability:

      • Can scale independently of web server environments.
    • Monitoring:

      • Provides metrics for tracking worker process performance.
    • Example Use Case:

      • Processing images, sending emails, performing periodic data cleanups.

Choosing Between the Two Environmnet:

  • Use a Web Server Environment if your application primarily serves web traffic or responds to HTTP requests.

  • Use a Worker Environment if your application requires background processing or asynchronous task handling.

It's also possible to use a combination of both environments in a single Elastic Beanstalk application to handle different types of workloads. For example, you could have a web server environment for handling user interactions and a worker environment for processing background tasks.

How Elastic Beanstalk Works

  • Developers create an application, selecting a runtime environment and programming language like Java, Docker, Ruby, Go, or Python.

  • After creating the application, developers upload the version of the application to AWS.

  • Once uploaded, developers launch an environment, which automatically runs an EC2 instance in the background and deploys the application within it.

  • Monitoring can be done through the Beanstalk dashboard or CloudWatch logs.

  • To update a version, developers upload a new version and deploy it.


Run the game using Docker

Steps:)

  1. Step 1: Clone the game into your local machine.

     git clone https://github.com/Simbaa815/2048-devops-project.git
    

  2. Step 2: Navigate to the Game Directory

    Use the cd command to navigate to the directory where you cloned the game.

    I already created the Dockerfile.....

     cd 2048-devops-project
    

  3. Step 3: Build the Image

    Run the following command to build the Docker image:

     docker build -t 2048-game .
    

  4. Step 4: Verify the Image

     docker images
    

  5. Step 5: Run a Container from the Image

    You can run a container from the image you just built using the docker run command.

     docker run -d -p 80:80 2048-game
    

  6. Step 6: Verify the container

     docker ps
    

Note: By default, port 80 is open in most environments. This means you usually don't need to add it to your inbound rule.

  1. Step 7: Get the Public IP of your ec2

    • Select the running instance.

    • go to the networking session

    • at that session, you get your public IP

  2. Step 8: Access the Game

    Paste the public IP of your ec2 instance on your favorite web-browser.

The game is properly working, so now we deploy this game on the AWS Elastic Beanstalk.


Hosting 2048 game in AWS Elastic Beanstalk

Steps:)

  1. Login to the AWS Console:

  2. Search for the Elastic Beanstalk Service:

    • In the AWS Management Console, use the search bar at the top and type "Elastic Beanstalk".

    • Click on the Elastic Beanstalk service in the search results.

  3. Create a New Application:

    • In the Elastic Beanstalk dashboard, click "Create Application".

  4. Select Web Server Environment:

    • Choose the type of environment that will host your application.

      Here, we choose the web server application

  5. Name the Application:

    • Provide a name for your application.

  6. Name Environment and Add Description:

    • Assign a name to the environment and include a brief description.

      Also you gave the domain name or leave it blank for autogenerated value

      "I leave it blank here😁"

  7. Choose Docker Platform:

    • Select the Managed Platform and specify Docker as the platform type.

  8. Upload Docker File:

    • Opt for "Upload your code" and upload the Dockerfile you've created.

      This Dockerfile sets up a Ubuntu environment, installs Nginx, downloads the 2048 game, and configures Nginx to serve the game.

        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://github.com/Simbaa815/2048-game/archive/refs/heads/master.zip
        RUN cd /var/www/html/ && unzip master.zip && mv 2048-game-master/* . && rm -rf 2048-game-master master.zip
      
        EXPOSE 80
      
        CMD ["/usr/sbin/nginx", "-c", "/etc/nginx/nginx.conf"]
      

  9. Select Free Tier Eligible Option:

    • Choose the option that falls under the AWS Free Tier to ensure cost-effective deployment.

  10. Configure service access:

  11. Skip to Review:

    • Review the settings and proceed.

  12. Submit:

    • Confirm the deployment.

  13. Initiate Environment Creation:

    • The process of creating the environment will begin.

  14. Load the Domain:

    • After successful environment creation, access your game using the provided domain.s.

Conclusion:)

πŸš€Today's journey introduced us to AWS Elastic Beanstalk, a powerful PaaS by AWS. We simplified web app deployment, even uploading the 2048 game. Elastic Beanstalk handles infrastructure, letting us focus on code.


Thank you for diving into this blog with me! I trust you found the information both helpful and enlightening. To stay updated on the latest in DevOps πŸš€, make sure to follow me. Remember, staying informed means staying ahead in the dynamic world of DevOps!

Feel free to connect with me on:

LinkedIn

Twitter

GitHub

For more updates and engaging discussions on DevOps, let's connect! πŸš€ #DevOpsCommunity

Happy Learning! Keep pushing those boundaries! 😊

Β