AWS CodePipeline (CI/CD Pipeline)
CICD Pipeline with CodeCommit CodeBuild and CodeDeploy
CodeDeploy Demo
Welcome to this AWS CodeDeploy step-by-step tutorial. You’ll learn how to deploy a simple index.html file to a Windows EC2 instance using CodeDeploy. This guide covers:
- Preparing your application bundle
- Uploading to Amazon S3
- Configuring IAM roles
- Launching a Windows EC2 instance
- Creating a CodeDeploy application and deployment group
- Performing an in-place deployment
Note
Be sure to clean up AWS resources when you’re finished to avoid unexpected charges.
1. Prepare Application Files
Create a folder named HelloWorldApp
(or any name you choose) and add these three files:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello, World!</title>
<style>
body {
color: #ffffff;
background-color: #10188c;
font-family: Arial, sans-serif;
font-size: 14px;
}
.center { text-align: center; }
</style>
</head>
<body>
<div class="center"><h1>Hello, World!</h1></div>
<div class="center"><h2>You have successfully deployed an application using CodeDeploy</h2></div>
<div class="center">
<p>Next steps? See the
<a href="https://aws.amazon.com/codedeploy">CodeDeploy Documentation</a>.
</p>
</div>
</body>
</html>
appspec.yml
version: 0.0
os: windows
files:
- source: \index.html
destination: c:\inetpub\wwwroot
hooks:
BeforeInstall:
- location: \before-install.bat
timeout: 900
before-install.bat
REM Install Internet Information Services (IIS)
c:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe -Command Import-Module ServerManager
c:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe -Command Install-WindowsFeature web-server
Compress these files into HelloWorldApp.zip
.
2. Upload the ZIP File to S3
- Open the Amazon S3 console.
- Create a new bucket or select an existing one.
- Upload HelloWorldApp.zip.
3. Create IAM Roles
You need two roles: one for the EC2 instance and one for CodeDeploy.
Role Name | Use Case | Attached Policy |
---|---|---|
CodeDeployDemo-EC2-Instance-Profile | EC2 access & S3 permissions | AmazonSSMManagedInstanceCore<br>Inline S3 allow list/get |
CodeDeployDemo-Service-Role | CodeDeploy service access | AWSCodeDeployRole |
- EC2 Instance Role
- Create a new role for EC2 with the AmazonSSMManagedInstanceCore managed policy.
- Add an inline policy to allow S3 read operations:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["s3:Get*", "s3:List*"], "Resource": "*" } ] }
- CodeDeploy Service Role
- Create a role for CodeDeploy and attach AWSCodeDeployRole.
4. Launch a Windows EC2 Instance
- Go to the EC2 console and click Launch Instance.
- Configure:
- Name: CodeDeployDemo
- AMI: Windows Server (latest)
- Instance type: t2.micro (free tier)
- In Network settings, allow HTTP (80) and HTTPS (443).
- Under Advanced details, select the IAM instance profile
CodeDeployDemo-EC2-Instance-Profile
. - Launch (key pair optional if no RDP needed).
Note
Windows AMIs exclude the CodeDeploy agent by default. Install it after launch via AWS Systems Manager or by running the MSI installer from AWS.
5. Create the CodeDeploy Application & Deployment Group
- Open the AWS CodeDeploy console and click Create application.
- Name: CodeDeployDemo
- Compute platform: EC2/On-premises
- Select the application, then choose Create deployment group.
- Name: CodeDeployDemo
- Service role: CodeDeployDemo-Service-Role
- Deployment type: In-place
- Environment configuration:
- Tag Key:
Name
- Tag Value:
CodeDeployDemo
- Tag Key:
- Deployment settings: Now, One at a time, no load balancer
- Click Create deployment group.
6. Deploy the Application
- In the deployment group, select Create deployment.
- Revision type: My application is stored in Amazon S3
- Bucket: your S3 bucket
- Key:
HelloWorldApp.zip
- Keep defaults and click Create deployment.
After a few minutes, you’ll see success:
Summary & Next Steps
You’ve just:
- Created
index.html
,appspec.yml
, and a setup script. - Bundled and uploaded your app to S3.
- Configured IAM roles.
- Launched a Windows EC2 instance with the CodeDeploy agent.
- Set up an application and deployment group in CodeDeploy.
- Deployed your app in-place from S3.
Integrate CodeDeploy into a full CI/CD pipeline next—see the AWS CodePipeline Documentation for details.
Links and References
- AWS CodeDeploy Documentation
- Amazon S3 Documentation
- AWS IAM Documentation
- AWS EC2 Documentation
- AWS Systems Manager
Watch Video
Watch video content
Practice Lab
Practice lab