What is CodeDeploy?
• AWS CodeDeploy is a fully managed deployment automation service.
• It can deploy to:
• Amazon EC2 instances
• On-premises servers
• Lambda functions
• Amazon ECS services
• It supports code stored in S3, GitHub, Bitbucket, or CodeCommit.
• You don’t need to change your existing code — CodeDeploy manages the deployment steps for you.
Tasks for Day 52
Task 01 — Learn & Prep
A. Read about appspec.yml file:
• This file defines how CodeDeploy should copy, install, and run your application.
- Typical structure
version: 0.0
os: linux
files:
- source: /index.html
destination: /usr/share/nginx/html/
hooks:
AfterInstall:
- location: scripts/restart_nginx.sh
timeout: 300
runas: root
- It tells CodeDeploy what files to deploy and what commands to run at each stage.
B. Prepare EC2 instance:
• Launch an EC2 instance (Amazon Linux 2 recommended).
• Install Nginx:
sudo yum update -y
sudo amazon-linux-extras install nginx1 -y
sudo systemctl start nginx
sudo systemctl enable nginx
C. Install CodeDeploy agent:
sudo yum update -y
sudo yum install ruby wget -y
cd /home/ec2-user
wget https://aws-codedeploy-<region>.s3.<region>.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
sudo systemctl start codedeploy-agent
sudo systemctl enable codedeploy-agent
Task 02 — Deployment
A. In your CodeCommit repo, add an appspec.yml file (like above).
B. Create a simple deployment script (optional, e.g., scripts/restart_nginx.sh):
#!/bin/bash
systemctl restart nginx
C. Push changes
git add appspec.yml scripts/
git commit -m "Add appspec.yml for CodeDeploy"
git push origin main
S. In AWS Console → CodeDeploy:
Create an Application (EC2/On-premises type).
Create a Deployment Group (choose your EC2 instance + service role).
- 5. Create a Deployment (point it to your CodeCommit repo + branch). CodeDeploy will copy index.html to /usr/share/nginx/html/ and restart nginx.
- Test in browser: http:// → You should see your index.html page.
Top comments (0)