CodeDeploy Hands On
Stephaneβs walkthrough exposes a critical architectural truth: CodeDeploy doesn't just copy files blind; it relies on strict cryptographic IAM trust boundaries, background operating system runtime dependencies, and precise metadata filters to locate your virtual machines.
Hands Onβ
π 1. Forging the Dual IAM Security Pillarsβ
Before you touch a single server or deployment console, you must build the underlying identity handshake gates, chief:
- The Service Control Gate (Role A): Open the IAM Console βββΊ go to Roles βββΊ hit Create role.
- Select AWS service βββΊ choose CodeDeploy βββΊ select the use case variant matching CodeDeploy (Standard/EC2).

- Name the role explicitly:
CodeDeployServiceRoleForEC2and click create. (This grants the background CodeDeploy orchestrator permission to inspect your infrastructure boundaries.)
- Select AWS service βββΊ choose CodeDeploy βββΊ select the use case variant matching CodeDeploy (Standard/EC2).
- The Host Storage Fetch Gate (Role B): Hit Create role yet again βββΊ select AWS service βββΊ choose EC2.
- Under the permissions search bar, look for and attach
AmazonS3ReadOnlyAccessto the role. - Name this role:
EC2RoleForCodeDeployand click create. (This allows your virtual machines to securely reach out and pull deployment zips straight down from your S3 back-buckets!)
- Under the permissions search bar, look for and attach
ποΈ 2. Provisioning the Target Infrastructure Fleetβ
- Launch the Virtual Box: Navigate straight to the Amazon EC2 console dashboard βββΊ click Launch instance.
- Set the Host Specs: Name it
DemoWebServerβββΊ keep the baseline OS pinned to standard Amazon Linux βββΊ leave the instance size configuration on t3.micro. - Open the Network Inbound Perimeters: Under Network Settings, check the box to Allow SSH traffic AND check the box to Allow HTTP traffic from the internet.
- Launch the Node: Click Launch instance (add a key pair if you have it handy or you can use CloudShell to connect later).

- π¨ THE CRITICAL METADATA TAG AND SECURITY PATCH: To ensure CodeDeploy can find and operate this node, you must perform two rapid administrative tweaks inside your active instances view panel:
- Attach the Storage Fetch Identity: Check the box next to your instance βββΊ click Actions βββΊ Security βββΊ Modify IAM role βββΊ drop down the list, select
EC2RoleForCodeDeploy, and hit Save. - Attach the Group Target Tag: Click on your running instance details βββΊ go to the Tags tab βββΊ hit Manage tags βββΊ append a custom tracking tag: Set the Key to
Environmentand set the Value strictly toDevelopmentβββΊ hit Save.
- Attach the Storage Fetch Identity: Check the box next to your instance βββΊ click Actions βββΊ Security βββΊ Modify IAM role βββΊ drop down the list, select
π οΈ 3. Bootstrapping the Host Engine (The CodeDeploy Agent)β
-
Establish a Live Terminal Line: Click into your active
DemoWebServerinstance dashboard layout βββΊ hit the top-level Connect button βββΊ select the EC2 Instance Connect tab βββΊ click Connect to pop open a live web terminal session. -
Execute the Bootstrap Instructions: Run these sequential Linux scripts down the wire to spin up the background runtime dependencies:
# Installing CodeDeploy Agentsudo yum updatesudo yum install ruby# Download the agent (replace the region)wget https://aws-codedeploy-eu-west-3.s3.eu-west-3.amazonaws.com/latest/installchmod +x ./installsudo ./install autosudo service codedeploy-agent status -
The Succeeded Check: The terminal will flash a bright active status payload showing a tracking Process ID (PID). Your server is officially armed and listening for cloud deployment runs.

π 4. Staging the Deployment Blueprints inside Amazon S3β
-
Create the Deployment Silo: Open the Amazon S3 console βββΊ click Create bucket βββΊ give it a globally unique descriptor like
rendy-code-deploy-demo-bucket. Critical Rule: Ensure your S3 bucket matches the exact identical AWS Region housing your EC2 and CodeDeploy environments, or the network handshake fails. -
Upload the Application Revision Bundle: Drop your compiled application zip archive (e.g., SampleApp_linux.zip) straight into the bucket.
-
The AppSpec Custom Hook Blueprint π: Under the hood, your unzipped application revision folder contains a mission-critical tracking file at its absolute root named
appspec.yml. This file dictates the exact directory file copies and handles custom shell script triggers inside sequential Lifecycle Event Hooks:BeforeInstall: Spins up custom scripts to pre-install dependencies (like configuring an Apachehttpdweb server engine).Install: CodeDeploy maps and copies files out of your zip artifact straight down into the target host directory path (e.g.,/var/www/html).ApplicationStart: Triggers scripts to execute a graceful boot loop on your service stack.ApplicationStop: Fires scripts to gracefully stop your service stack before a new deployment run.
Full lifecycle hook documentation is available here: CodeDeploy Lifecycle Event Hooks.
-
Grab the Data Pointer: Click on your uploaded zip object inside the S3 dashboard and copy its unique S3 URI path string to your clipboard.
ποΈ 5. Creating the CodeDeploy Control Groupβ
- Initialize the Application App Scope: Head back over to the CodeDeploy console workspace βββΊ click Applications βββΊ hit Create application βββΊ name it
DemoApplicationβββΊ set the Compute Platform dropdown parameter strictly toEC2/on-premises.

- Forge the Target Deployment Group: Click into your newly created application profile βββΊ click Create deployment group:
- Name the group target:
DevelopmentInstances. - Set the Service Role dropdown to your pre-staged:
CodeDeployServiceRoleForEC2. - Set the Deployment Type selection to:
In-place.

- Under Environment Configuration, check the box for
Amazon EC2 instances. - The Metadata Filtering Step: Under the tag group parameters, set the Key to
Environmentand set the Value toDevelopment. The console will instantly scan your active cloud fleet and update its readouts to state:1 unique matched instance found.

- Set Agent Installation options to: Never.
- Set Deployment Configuration options to:
CodeDeployDefault.AllAtOnce. - Uncheck the box to Enable Load Balancing (since we are proxying straight to a single standalone server for this sandbox testing run) βββΊ click Create deployment group.

- Name the group target:
π 6. Triggering the Deployment Rocket Launchβ
- Fire the Code Payload: Inside your active deployment group view panel, look to the actions row on the top right and click Create deployment.
- Reference the Target Build Archive: Keep the settings pointed to your
DevelopmentInstancesgroup βββΊ set the Revision Type dropdown to My application is stored in Amazon S3 βββΊ paste your copied S3 URI path string right into the tracking target box βββΊ click Create deployment.

- The Live Diagnostics Rollout: The deployment transitions instantly to an active execution timeline. Click View events to watch the background CodeDeploy agent systematically grab your zip bundle, fire your installation lifecycle hook scripts, drop the files, and boot your Apache server.

- The Victory Lap Check π: Copy the raw public IP address of your EC2 instance node from the dashboard, paste it into a fresh browser URL line prefixing it with a raw
http://call, and hit enter. The page loads instantly with a glorious banner text stating: "Congratulations! This application was deployed using AWS CodeDeploy".

π 7. Absolute Final Clean-Up Reminderβ
Do not forget to head right back over to your Amazon EC2 dashboard console, select your running DemoWebServer test box, hit instance state, and click Terminate instance. This instantly wipes out the virtual box and stops all background AWS compute billing meters completely.