Chandra Meets CodeDeploy: My First AWS Deployment Journey

Chandra Meets CodeDeploy: My First AWS Deployment Journey

Chandra Meets CodeDeploy: My First AWS Deployment Journey ☁️ Exploring how AWS CodeDeploy makes application deployment easier, faster, and more reliable. Introduction In software development, creating an application is only the beginning. After writing code, developers must move it from their computers to a server where users can access it. This process is called deployment. Imagine a student team developing a college placement prediction application. Every time the team improves the machine learning model or updates the website, they need to transfer the new files to the server, configure the application, and restart it. Doing this manually can be time-consuming and may cause errors. This is where AWS CodeDeploy becomes useful. It automates the deployment of application updates to supported computing environments. In this blog, I will explore what AWS CodeDeploy is, how it works, its important features, and how a college student project can benefit from it. What Is AWS CodeDeploy? AWS CodeDeploy is a fully managed deployment service provided by Amazon Web Services (AWS). It helps developers automatically deploy application code, configuration files, scripts, and other application content to computing environments. CodeDeploy supports three major compute platforms: Amazon EC2 and on-premises servers: Deploy applications to cloud-based or supported physical servers. AWS Lambda: Deploy new versions of serverless functions. Amazon ECS: Deploy updated containerized applications. It can retrieve application revisions from sources such as Amazon S3 and supported source-code repositories, depending on the deployment platform. Why Was CodeDeploy Created? Before automated deployment tools became common, developers often copied files manually to servers and executed several commands to update an application. This process could lead to configuration mistakes, inconsistent deployments, and application downtime. AWS CodeDeploy was created to simplify this process. It allows developers to define deployment instructions once and reuse them whenever a new application version is released. Instead of repeatedly performing deployment tasks manually, developers can allow CodeDeploy to install the new version, execute required scripts, monitor the deployment, and report whether it succeeded. How It Works At a high level, CodeDeploy follows a simple pattern: You store your application code in a source location (GitHub, S3, or CodeCommit). You describe the deployment steps in a file called appspec.yml, which lives with your code. CodeDeploy picks up the revision, copies it to your target instances (or updates your Lambda/ECS version), and runs the lifecycle hooks defined in appspec.yml in order — stopping the old version, installing the new one, and starting it back up. If you've attached CloudWatch alarms, CodeDeploy watches them during the rollout and automatically rolls back if something looks unhealthy. Here's a simplified view of that flow: (Diagram: Developer → Source Repo → CodeDeploy reads appspec.yml → Deployment Group runs lifecycle hooks (ApplicationStop → DownloadBundle → BeforeInstall → Install/AfterInstall → ApplicationStart/ValidateService) → CloudWatch monitors health and can trigger rollback.) Key Features Automated, consistent deployments Once configured, deployments happen the same way every time — no manually remembering which command to run on which server. This removes a huge class of human error. Multiple deployment strategies CodeDeploy supports in-place deployments (update the existing instances one at a time or in batches) and blue/green deployments (spin up a new fleet, shift traffic over, and terminate the old one only after the new one is verified). This lets you choose between speed and safety depending on the project. Automatic rollback on failure If a deployment fails a lifecycle event or trips a CloudWatch alarm, CodeDeploy can automatically roll back to the last known good version — something that's genuinely hard to build reliably by hand. Works across compute types The same core service deploys to EC2/on-premises servers, Lambda functions, and ECS containers, so you don't need a completely different tool depending on your architecture. College / Student Use Case Here's where this becomes directly relevant to campus life. At CIT, several departments run small internal web apps — placement portals, event registration pages, club websites (like our Rotaract Club page), or student project demos hosted for review. Right now, most of these are deployed manually: someone logs into a server, pulls the latest code, and restarts it, often right before a demo deadline. A practical use case: our department could host student mini-project demos (like a Flask-based ML model demo) on a small EC2 instance, with CodeDeploy watching the GitHub repository. Every time a student pushes an update before their review, CodeDeploy automatically redeploys the latest version to the demo server — no manual server access needed, and no risk of forgetting a step under deadline pressure. If the new version crashes, CodeDeploy rolls back automatically, so the demo server never goes down entirely. Simple Example A minimal appspec.yml for deploying a small web app to EC2 looks like this: yaml version: 0.0 os: linux files: source: / destination: /var/www/student-project hooks: BeforeInstall: location: scripts/stop_server.sh timeout: 60 AfterInstall: location: scripts/install_dependencies.sh timeout: 180 ApplicationStart: location: scripts/start_server.sh timeout: 60 ValidateService: location: scripts/health_check.sh timeout: 60 And triggering a deployment through the AWS CLI is just: bash aws deploy create-deployment \ --application-name student-demo-app \ --deployment-group-name demo-server-group \ --github-location repository=my-username/student-project,commitId= CodeDeploy then runs each hook script in order and reports success or failure in the console. Key Features of AWS CodeDeploy 1. Automated Deployments CodeDeploy automates the process of transferring and installing application updates. It reduces the need for developers to manually copy files, execute installation commands, and restart services. For example, a team can prepare a new version of a web application and use CodeDeploy to release it to a group of EC2 instances. 2. In-Place and Blue/Green Deployments CodeDeploy supports different deployment strategies. In-place deployment: The existing servers are updated with the new application version. The application may be stopped during the update, depending on the configuration. Blue/green deployment: A new environment is prepared with the updated application. After testing, traffic can be redirected from the old environment to the new one. This can reduce service interruptions and make testing safer. For EC2 deployments, CodeDeploy supports both in-place and blue/green strategies. Lambda and ECS deployments use blue/green deployment methods with traffic-shifting configurations. 3. Deployment Scripts Using AppSpec The AppSpec file is an important part of CodeDeploy. It defines how files should be copied and which scripts should run during different deployment stages. For example, a deployment may need to: Copy application files to a particular folder. Install Python dependencies. Stop an older application process. Start the updated application. Run a validation command. These instructions can be stored in the AppSpec file and reused during future deployments. 4. Monitoring and Rollback Support CodeDeploy provides deployment status information through the AWS Management Console and AWS CLI. Developers can check whether a deployment succeeded, failed, or is still in progress. Deployment configurations can also work with health checks and alarms. In suitable setups, failed deployments can be stopped or rolled back to a previous application version. College/Student Use Case 🎓 Consider a student team at a college developing a Placement Prediction Web Application. The project uses: Python and Flask for the backend. A machine learning model to predict placement outcomes. HTML, CSS, and JavaScript for the frontend. An Amazon EC2 instance to host the application. Initially, the team manually uploads updated Python files and the machine learning model to the EC2 server whenever they make changes. As the project grows, this becomes difficult to manage, especially when several students contribute code. The team can use AWS CodeDeploy to automate the process. Whenever the team prepares a new application version, they can package the Flask application, configuration files, and deployment scripts into a revision. The revision can be uploaded to Amazon S3. CodeDeploy can then deploy the revision to the EC2 instance. For example, when the team improves the prediction model, CodeDeploy can install the updated model and application files, execute the required scripts, and report the deployment result. This approach helps students understand real-world DevOps practices, reduces repetitive manual work, and creates a more organized deployment workflow. Simple Practical Example Let us consider a basic Python Flask application deployed to an Ubuntu EC2 instance. Project Structure my-flask-app/ │ ├── app.py ├── requirements.txt ├── appspec.yml └── scripts/ ├── install_dependencies.sh └── start_application.sh Enter fullscreen mode Exit fullscreen mode 1. Flask Application The app.py file contains a simple web application: from flask import Flask app = Flask(__name__) @app.route("/") def home(): return "Hello from AWS CodeDeploy!" if __name__ == "__main__": app.run(host="0.0.0.0", port=5000) Enter fullscreen mode Exit fullscreen mode 2. AppSpec File The appspec.yml file tells CodeDeploy where to copy the application files and which scripts to execute. version: 0.0 os: linux files: - source: / destination: /home/ubuntu/my-flask-app hooks: AfterInstall: - location: scripts/install_dependencies.sh timeout: 300 runas: ubuntu ApplicationStart: - location: scripts/start_application.sh timeout: 300 runas: ubuntu Enter fullscreen mode Exit fullscreen mode The files section specifies the destination directory. The hooks section defines scripts that run after installation and when the application starts. 3. Deployment Scripts The install_dependencies.sh script can install the Python packages required by the application. #!/bin/bash cd /home/ubuntu/my-flask-app python3 -m pip install -r requirements.txt Enter fullscreen mode Exit fullscreen mode The start_application.sh script can start the Flask application. #!/bin/bash cd /home/ubuntu/my-flask-app nohup python3 app.py > app.log 2>&1 & Enter fullscreen mode Exit fullscreen mode These scripts are only a basic demonstration. In a production environment, a process manager such as systemd should normally be used instead of repeatedly starting background processes with nohup. 4. Deployment Process The student team can follow these steps: Create the application files and deployment scripts. Add the AppSpec file to the project. Package the files into a ZIP archive. Upload the archive to an Amazon S3 bucket. Create a CodeDeploy application using the EC2/On-Premises compute platform. Create a deployment group and identify the target EC2 instance. Install and configure the CodeDeploy agent on the instance. Start a deployment using the AWS Management Console or AWS CLI. Check the deployment status and test the Flask application. The EC2 instance must have the necessary IAM permissions, and the CodeDeploy agent must be correctly installed and running. Advantages of AWS CodeDeploy AWS CodeDeploy offers several advantages: Saves time: Automates repetitive deployment tasks. Reduces manual errors: Uses predefined deployment instructions. Supports different environments: Works with EC2, supported on-premises servers, Lambda, and ECS. Improves release management: Makes it easier to deploy new application versions consistently. Supports safer updates: Blue/green deployment strategies can reduce downtime and allow testing before shifting traffic. Works with scaling infrastructure: Deployments can target multiple instances and integrate with AWS services. Limitations and Things to Consider Although CodeDeploy is useful, it is not a complete replacement for every DevOps tool. Cost CodeDeploy does not charge an additional fee for deployments to Amazon EC2, on-premises instances, AWS Lambda, or Amazon ECS. However, the AWS resources used alongside it may incur charges. For example, students may need to pay for EC2 instances, Amazon S3 storage, data transfer, CloudWatch monitoring, or other services. AWS Free Tier eligibility and pricing conditions should be checked before using resources. Complexity CodeDeploy requires configuration of IAM roles, deployment groups, application revisions, and, for EC2 deployments, the CodeDeploy agent. Beginners may need time to understand these components. Security IAM permissions should follow the principle of least privilege. S3 buckets should be protected, credentials should not be stored inside application files, and deployment scripts should be reviewed before execution. Application Compatibility CodeDeploy automates deployment, but it does not automatically fix bugs in application code, configure every server dependency, or guarantee that an application will work after deployment. Developers must prepare correct scripts and test their applications. Conclusion AWS CodeDeploy is a useful AWS service for automating application deployments. It helps developers move application updates to servers, Lambda functions, or ECS services in a more consistent and controlled manner. For college students, CodeDeploy provides practical experience with cloud computing, DevOps, deployment automation, IAM, and application release management. A student project such as a placement prediction application can benefit from fewer manual deployment steps and a more organized release process. As I explore AWS services, CodeDeploy shows me that building an application is only one part of software engineering. Delivering and maintaining that application reliably is equally important. Chandra's takeaway: CodeDeploy helps turn the process of “I finished my code” into “My updated application is deployed and ready to use.” ☁️ References AWS CodeDeploy: What is CodeDeploy? AWS CodeDeploy: Primary Components AWS CodeDeploy: Deployments on EC2/On-Premises AWS CodeDeploy: AppSpec File Structure AWS CodeDeploy: Official Documentation

Original Source

Read the full article at Dev →

KhanList aggregates and links to publicly available news content. We do not host full articles from third-party sources. Always verify important information with original sources.