In this Create and Deploy applications using CodeDeploy and CodePipeline with Amazon S3 bucket versioning enabled -
In the 1st article, We will create, SSH into EC2 Instance and Install CodeDeploy Agent. Then Create a S3 bucket with versioning enabled, upload App_Linux.zip
Let’s get started!
Please visit my GitHub Repository for CI-CD/Docker/ECS/ECR articles on various topics being updated on constant basis.
Objectives:
1. Sign in to AWS Management Console
2. Launch an EC2 instance, Connect (SSH) to EC2 Instance thru Putty
3. Install CodeDeploy Agent
4. Create S3 Bucket, upload App_Linux.zip
and Copy the Object's key
Pre-requisites:
- AWS user account with admin access, not a root account.
- AWS CLI.
Resources Used:
Steps for implementation to this project
1. Sign in to AWS Management Console
- Log into the AWS Management Console, AWS Region as US East (N. Virginia) us-east-1.
2. Launch an EC2 instance, Connect (SSH) to EC2 Instance thru Putty
Launch an EC2 instance
Go to EC2 Dashboard, Launch instance, my-ec2, Select t2.micro. NVirKey, default vpc, subnets - no preference, Auto-assign public IP - enable, Create Security group, CodePipeline-SG, SSH with 0.0.0.0/0, Add security group rule, HTTP, 80, 0.0.0.0/0
Attach Role - Role-EC2Instance with attched policyAmazonEC2RoleforAWSCodeDeploy
Launch instance
- Connect (SSH) to EC2 Instance thru Putty
3. Install CodeDeploy Agent
-
Switch to root user
yum update -y
-
Before Installing CodeDeploy Agent, Install the prerequisite i.e. ruby and wget
yum install ruby wget -y
-
Download the CodeDeploy agent's installer
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
-
Change the permission of the installer
chmod +x ./install
-
Install the latest version of the CodeDeploy agent
sudo ./install auto
-
Check status
service codedeploy-agent status
- Note: If the output is "The AWS CodeDeploy agent is running as PID 3523" or any other PID. It means codedeploy agent is running fine.
If the output says, "error: No AWS CodeDeploy agent running", then start the agent by running the below command and check the status again.
Start the agent
service codedeploy-agent start
-
check the status
service codedeploy-agent status
4. Create S3 Bucket, upload App_Linux.zip
and Copy the Object's key
On S3 Console, Create bucket, codecommit-bucket12, Uncheck Block all public access, Bucket Versioning - Enable
Create bucket
Click the bucket, Upload, Addfiles, App_Linux.zip, Upload
App_Linux.zip - has the following files
appspec.yaml
version: 0.0
os: linux
files:
- source: /index.html
destination: /var/www/html/
hooks:
BeforeInstall:
- location: scripts/install_dependencies
timeout: 300
runas: root
- location: scripts/start_server
timeout: 300
runas: root
ApplicationStop:
- location: scripts/stop_server
timeout: 300
runas: root
- index.html
<!doctype html>
<html>
<body>
<h1>This is my Codepipeline from S3 bucket! </h1>
</body>
</html>
- scripts folder has 3 files
install_dependencies
#!/bin/bash
yum install -y httpd
start_server
#!/bin/bash
service httpd start
stop_server
#!/bin/bash
service httpd stop
- Copy the object Key, and save it to notepad
What we have done so far
- We have successfully created, SSH into EC2 Instance and Installed CodeDeploy Agent. Then Created a S3 bucket with versioning enabled, uploaded App_Linux.zip
Top comments (0)