Deploying a "Hello World" Application to AWS Elastic Beanstalk
Published: 2024-06-17 23:36:11

**Introduction**
AWS Elastic Beanstalk as an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS. This post will demonstrate how to deploy your application in AWS Elastic Beanstalk.  

**Prerequisites**

- AWS account
- Basic knowledge of web application development
- Familiarity with AWS services is helpful but not required

## Step 1: Creating a Simple Web Application

**Initial Setup**
- Choose a programming language and framework. For this example, let's use Python with Flask.
- Create a new directory for your project and navigate into it.
- Initialize a new Python virtual environment and activate it (optional but recommended).

**Application Code**
- Create a file named application.py and add the following Flask application code:

```
from flask import Flask

application = Flask(__name__)

@application.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    application.run()
```
- Create a requirements.txt file specifying Flask:

```
Flask==1.1.2
```

**Local Testing (Optional)**
- Run the application locally to ensure it works.
- Open a browser and navigate to http://localhost:5000 to see the "Hello, World!" message.


## Step 2: Preparing the Application for Deployment
- Zip the application.py and requirements.txt files together.

```
zip myapp.zip application.py requirements.txt
```

## Step 3: Creating an Elastic Beanstalk Environment
- Log in to the AWS Management Console.
- Navigate to the Elastic Beanstalk service and click "Create New Application".
- Enter an application name and description.
- Create a new environment within this application – choose the Web server environment.

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


- Select the Python platform and choose the appropriate version.

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

## Step 4: Uploading and Deploying the Application
- When prompted to upload your code, choose the "Upload your code" option and upload the myapp.zip file.

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

- Configure more options if needed, or simply click "Create environment".

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

## Step 5: Configuring Service Access
- For Elastic Beanstalk selecting role is crucial. For this lab purpose let's chose existing service role and existing EC2 instance profile.

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

## Step 6: Environment Configuration and Launch
- For rest of the optional parameters, keep it as is.

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

- AWS Elastic Beanstalk will now create your environment and deploy the application.

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

- This process might take a few minutes.

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


## Step 7: Accessing the Deployed Application
- Once the environment is ready, click the provided URL to access your application.

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


- You should see the "Hello, World!" message served from AWS Elastic Beanstalk.

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


## Step 8: Clean Up
- To avoid incurring charges, delete the Elastic Beanstalk environment and application.

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


## Conclusion
Congratulations! You've just taken a significant step into the world of web application deployment using AWS Elastic Beanstalk. By following the steps outlined in this post, you have learned how to deploy a "Hello World" application.

As you become more comfortable with AWS Elastic Beanstalk, I encourage you to explore its advanced features, experiment with different configurations, and consider how you can integrate other AWS services to enhance your application's functionality and performance.

Now that you have the basics down, the sky is the limit. Keep learning, keep experimenting, and most importantly, have fun building!


## Additional Resources
To further your knowledge and skills in AWS Elastic Beanstalk and related AWS services, here are some additional resources you may find useful:

[AWS Elastic Beanstalk Developer Guide](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/): The official Elastic Beanstalk documentation provides detailed information on how to use and configure the service.
[AWS Elastic Beanstalk Sample Applications](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/samples.html): Explore sample applications provided by AWS that you can deploy and study.
[AWS Training and Certification](https://www.aws.training/): AWS offers various training courses and certifications that can help you deepen your understanding of AWS services.
[AWS Developer Forums](https://forums.aws.amazon.com/forum.jspa?forumID=86): Elastic Beanstalk: Join the community forum to ask questions, share experiences, and get insights from other AWS developers.
[Flask Documentation](https://flask.palletsprojects.com/en/latest/): The official documentation for Flask is an excellent resource for learning more about building web applications with this micro web framework.