Skip to main content

Exercises and Projects


1 - Hands-on exercises

Exercise 1: CodeCommit

Objective: Create and configure a CodeCommit repository.

# Tâches :
# 1. Créer un repository "my-app"
# 2. Configurer l'authentification HTTPS
# 3. Cloner et pousser du code
# 4. Créer une branche "develop"
# 5. Créer une Pull Request
Solution
# 1. Créer le repo
aws codecommit create-repository --repository-name my-app

# 2. Configurer Git credentials (via IAM Console)
git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true

# 3. Cloner et pousser
git clone https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/my-app
cd my-app
echo "# My App" > README.md
git add .
git commit -m "Initial commit"
git push origin main

# 4. Créer develop
git checkout -b develop
git push origin develop

# 5. PR via CLI
aws codecommit create-pull-request \
--title "Merge develop to main" \
--targets repositoryName=my-app,sourceReference=develop,destinationReference=main

Exercise 2: CodeBuild

Objective: Create a CodeBuild project with a buildspec.yml.

Create a buildspec.yml that:

  1. Installs Node.js 18
  2. Runs npm install
  3. Runs the tests
  4. Builds the application
  5. Generates a coverage report
Solution
# buildspec.yml
version: 0.2

phases:
install:
runtime-versions:
nodejs: 18
commands:
- echo "Installing dependencies..."

pre_build:
commands:
- npm ci
- npm run lint

build:
commands:
- npm run build
- npm test -- --coverage

post_build:
commands:
- echo "Build completed on $(date)"

artifacts:
files:
- dist/**/*
- package.json
discard-paths: no

reports:
coverage:
files:
- 'coverage/cobertura-coverage.xml'
file-format: COBERTURAXML

cache:
paths:
- node_modules/**/*

Exercise 3: ECR and Docker

Objective: Push a Docker image to ECR.

# Tâches :
# 1. Créer un repository ECR
# 2. Build une image Docker
# 3. Tag et push vers ECR
# 4. Configurer une lifecycle policy
Solution
# 1. Créer le repo
aws ecr create-repository \
--repository-name my-app \
--image-scanning-configuration scanOnPush=true

# 2 & 3. Build, tag et push
ECR_REPO=123456789.dkr.ecr.eu-west-1.amazonaws.com/my-app

aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_REPO

docker build -t my-app:latest .
docker tag my-app:latest $ECR_REPO:latest
docker push $ECR_REPO:latest

# 4. Lifecycle policy
aws ecr put-lifecycle-policy \
--repository-name my-app \
--lifecycle-policy-text '{
"rules": [{
"rulePriority": 1,
"description": "Keep last 10",
"selection": {
"tagStatus": "any",
"countType": "imageCountMoreThan",
"countNumber": 10
},
"action": {"type": "expire"}
}]
}'

Exercise 4: CodePipeline

Objective: Create a simple pipeline with 3 stages.

Solution (CloudFormation)
AWSTemplateFormatVersion: '2010-09-09'

Resources:
Pipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
Name: simple-pipeline
RoleArn: !GetAtt PipelineRole.Arn
ArtifactStore:
Type: S3
Location: !Ref ArtifactBucket

Stages:
- Name: Source
Actions:
- Name: Source
ActionTypeId:
Category: Source
Owner: AWS
Provider: CodeCommit
Version: '1'
Configuration:
RepositoryName: my-app
BranchName: main
OutputArtifacts:
- Name: SourceArtifact

- Name: Build
Actions:
- Name: Build
ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: '1'
Configuration:
ProjectName: !Ref BuildProject
InputArtifacts:
- Name: SourceArtifact
OutputArtifacts:
- Name: BuildArtifact

- Name: Deploy
Actions:
- Name: Deploy
ActionTypeId:
Category: Deploy
Owner: AWS
Provider: S3
Version: '1'
Configuration:
BucketName: !Ref DeployBucket
Extract: 'true'
InputArtifacts:
- Name: BuildArtifact

2 - Complete project: Web Application

Description

Deploy a complete web application with:

  • Source code in CodeCommit
  • Build and tests with CodeBuild
  • Docker images in ECR
  • ECS deployment with CodeDeploy
  • Pipeline orchestrated by CodePipeline

Architecture

Project structure

my-web-app/
├── src/
│ └── app.js
├── tests/
│ └── app.test.js
├── Dockerfile
├── buildspec.yml
├── appspec.yml
├── taskdef.json
└── infrastructure/
└── pipeline.yaml

Key files

# Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY src/ ./src/
EXPOSE 3000
CMD ["node", "src/app.js"]
# buildspec.yml
version: 0.2

env:
variables:
ECR_REPO: 123456789.dkr.ecr.eu-west-1.amazonaws.com/my-web-app

phases:
pre_build:
commands:
- aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_REPO
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:-latest}

build:
commands:
- npm ci
- npm test
- docker build -t $ECR_REPO:$IMAGE_TAG .

post_build:
commands:
- docker push $ECR_REPO:$IMAGE_TAG
- printf '{"ImageURI":"%s"}' $ECR_REPO:$IMAGE_TAG > imageDetail.json

artifacts:
files:
- imageDetail.json
- appspec.yml
- taskdef.json

Deployment

# 1. Déployer l'infrastructure
aws cloudformation deploy \
--template-file infrastructure/pipeline.yaml \
--stack-name my-web-app-pipeline \
--capabilities CAPABILITY_IAM

# 2. Pousser le code
git push origin main

# 3. Le pipeline se déclenche automatiquement

# 4. Surveiller
aws codepipeline get-pipeline-execution \
--pipeline-name my-web-app-pipeline \
--pipeline-execution-id <execution-id>

3 - Review quiz

  1. What is the difference between CodeBuild and CodeDeploy?

  2. How do you secure secrets in a buildspec.yml?

  3. What is an artifact in CodePipeline?

  4. How do you trigger a pipeline automatically?

  5. Which deployment strategy allows an instant rollback?

Answers
  1. CodeBuild compiles the code and creates artifacts. CodeDeploy deploys the artifacts to the targets.

  2. Use secrets-manager: or parameter-store: in the env section of the buildspec.

  3. Files passed between stages (source code, build output, etc.).

  4. Via webhooks (GitHub), CloudWatch Events/EventBridge, or PollForSourceChanges.

  5. Blue/Green deployment allows an instant rollback by rerouting the traffic.


4 - AWS DevOps Professional certification

Domains covered

DomainWeight
SDLC Automation22%
Configuration Management & IaC17%
Monitoring and Logging15%
Policies and Standards10%
Incident and Event Response18%
High Availability and Fault Tolerance18%

Resources


Course summary

Congratulations! You have completed the AWS DevOps course.

You now have a firm grasp of:

  • CodeCommit for source control
  • CodeBuild for builds and tests
  • CodeDeploy for deployments
  • CodePipeline for orchestration
  • ECR for Docker images
  • CloudWatch and X-Ray for monitoring
  • The security and architecture best practices

Next steps

  • Practice with real projects
  • Take the AWS DevOps Professional certification
  • Explore AWS CDK for IaC
  • Study EKS for Kubernetes on AWS

← Back to the table of contents