In modern DevOps practices, ensuring that configuration files are updated and consistent across all instances is crucial for maintaining application performance and reliability. AWS CodeDeploy provides a robust solution to automate the deployment of applications, including configuration files, to EC2 instances. This guide will walk you through setting up CodeDeploy jobs to push configuration files to Windows EC2 instances in private subnets.
Prerequisites
Before you begin, ensure you have the following prerequisites:
- AWS Account: An active AWS account.
- EC2 Instances: Windows EC2 instances running in private subnets.
- IAM Roles: Appropriate IAM roles for CodeDeploy and EC2 instances.
- AWS CLI: Installed and configured AWS CLI on your local machine.
- CodeDeploy Agent: Installed on your Windows EC2 instances.
Step 1: Create an Application in CodeDeploy
- Log in to the AWS Management Console.
- Navigate to the CodeDeploy service.
- Click on Create application.
- Provide a name for your application.
- Select the Compute platform as EC2/On-Premises.
- Click on Create application.
Step 2: Create a Deployment Group
- Within your new application, click on Create Deployment Group.
- Provide a name for the deployment group.
- Select a service role that CodeDeploy will assume during the deployment process. Ensure this role has the necessary permissions.
- In the Deployment type, select In-place.
- Choose the Amazon EC2 instances by specifying tags, Auto Scaling groups, or manually.
- Specify a Deployment configuration (e.g., CodeDeployDefault.OneAtATime).
- Configure Load Balancer settings if applicable.
- Click on Create Deployment Group.
Step 3: Create an AppSpec File
The AppSpec file defines how CodeDeploy manages each instance during the deployment. Create a file named appspec.yml with the following content:
version: 0.0
os: windows
files:
– source: /path/to/local/config/files
destination: C:\path\to\destination\folder
hooks:
AfterInstall:
– location: scripts/AfterInstall.ps1
timeout: 300
runas: Administrator
ApplicationStart:
– location: scripts/ApplicationStart.ps1
timeout: 300
runas: Administrator
Step 4: Bundle Your Application and Upload to S3
- Zip your configuration files and the AppSpec file.
- Upload the zip file to an S3 bucket.
Step 5: Create a Deployment
- In the CodeDeploy console, go to your application.
- Click on Create Deployment.
- Select the deployment group created earlier.
- In the Revision type, choose My application is stored in Amazon S3.
- Specify the S3 bucket and the zip file containing your application.
- Click on Create Deployment.
Step 6: Monitor the Deployment
- In the CodeDeploy console, navigate to Deployments.
- Select your deployment to view details and monitor the progress.
- Verify that the configuration files are pushed to your Windows EC2 instances in the specified directory.
Conclusion
Following these steps, you can easily set up AWS CodeDeploy jobs to push configuration files to Windows EC2 instances in private subnets. This automation ensures that your instances are always up-to-date with the latest configuration, improving the reliability and performance of your applications.