Skip to main content
📝 Cloud & DevOps (AWS)

AWS CodeDeploy: Een CI/CD-pipeline instellen voor implementatie op EC2 via GitHub

Stel een CI/CD-pipeline in met AWS CodeDeploy om automatisch te deployen van GitHub naar EC2. Stapsgewijze handleiding met IAM-rollen, appspec en probleemoplossing.

3 min

Leestijd

523

Woorden

Mar 23, 2025

Gepubliceerd

Engr Mejba Ahmed

Geschreven door

Engr Mejba Ahmed

Artikel delen

AWS CodeDeploy: Een CI/CD-pipeline instellen voor implementatie op EC2 via GitHub

AWS CodeDeploy: Een CI/CD-pipeline instellen voor implementatie op EC2 via GitHub

Applicaties handmatig implementeren is omslachtig, foutgevoelig en inefficiënt. AWS CodeDeploy maakt het automatiseren van implementaties eenvoudig, verhoogt de efficiëntie en minimaliseert downtime. In deze handleiding leert u stap voor stap hoe u een robuuste CI/CD-pipeline opzet om uw applicaties rechtstreeks vanuit GitHub naar een Amazon EC2-instantie te implementeren.

Wat u nodig heeft:

  • AWS-account
  • EC2-instantie met Amazon Linux
  • GitHub-repository met uw applicatie
  • AWS CLI geïnstalleerd op uw lokale machine

Stap 1: Uw EC2-instantie voorbereiden

Maak verbinding met uw EC2-instantie via SSH:

ssh -i "your-key.pem" ec2-user@your-ec2-instance-public-ip

Installeer en start de CodeDeploy-agent:

sudo yum update
sudo yum install ruby -y
sudo yum install wget -y

cd /home/ec2-user
wget https://aws-codedeploy-region.s3.region.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto

sudo service codedeploy-agent status

Vervang region door uw AWS-regio, bijv. us-east-1.


Stap 2: Een IAM-rol aanmaken voor CodeDeploy

In de AWS-console:

  • Navigeer naar IAM → RollenRol aanmaken.
  • Kies AWS-service en selecteer CodeDeploy.
  • Koppel beleid: selecteer AWSCodeDeployRole.
  • Geef uw rol een naam (bijv. CodeDeployRole) en maak hem aan.

Stap 3: De CodeDeploy-applicatie instellen

  • Ga naar AWS CodeDeploy → Applicaties → Applicatie aanmaken.
  • Voer een applicatienaam in.
  • Kies computerplatform: EC2/On-premises.

Maak een implementatiegroep aan:

  • Naam van de implementatiegroep (bijv. Production)
  • Selecteer uw IAM-rol (CodeDeployRole)
  • Selecteer EC2-instanties op tag of handmatig
  • Implementatietype: In-place

Stap 4: Uw GitHub-repository voorbereiden

Maak een appspec.yml-bestand aan in de root van uw repository:

version: 0.0
os: linux
files:
  - source: /
    destination: /var/www/html
hooks:
  AfterInstall:
    - location: scripts/install_dependencies.sh
      timeout: 300
      runas: root

Maak de benodigde scripts aan, bijv. scripts/install_dependencies.sh:

#!/bin/bash
sudo yum update -y
sudo yum install -y httpd
sudo service httpd start
sudo chkconfig httpd on

Zorg dat uw scripts uitvoerbaar zijn:

chmod +x scripts/*.sh

Commit en push naar GitHub:

git add .
git commit -m "Added appspec.yml and deployment scripts"
git push origin main

Stap 5: AWS CodeDeploy koppelen aan GitHub

  • Selecteer in de CodeDeploy-console uw applicatie en implementatiegroep.
  • Klik op Implementatie aanmaken.
  • Selecteer GitHub als repositorytype.
  • Verbind met GitHub en autoriseer AWS.
  • Kies uw repository en commit-branch (bijv. main).
  • Klik op Implementeren.

Stap 6: CI/CD automatiseren met GitHub Actions

Maak .github/workflows/deploy.yml aan in uw repository:

name: AWS Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: AWS CodeDeploy
        uses: aws-actions/aws-codedeploy@v1
        with:
          application-name: your-codedeploy-app-name
          deployment-group-name: your-deployment-group
          region: your-region
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

Stel AWS-inloggegevens in als GitHub-secrets:

  • Ga naar GitHub → Instellingen → Secrets en variabelen → Acties → Nieuw repository-secret
  • Voeg AWS_ACCESS_KEY_ID en AWS_SECRET_ACCESS_KEY toe.

Voortaan triggert elke push naar main automatisch een implementatie.


Stap 7: Uw implementatie verifiëren

Bezoek het publieke IP-adres van uw EC2-instantie in een webbrowser:

http://your-ec2-instance-public-ip

U zou uw succesvol geïmplementeerde applicatie moeten zien.


Conclusie

Gefeliciteerd! U heeft met succes een AWS CodeDeploy CI/CD-pipeline opgezet die is geïntegreerd met GitHub voor automatische implementaties op EC2. Deze automatisering stroomlijnt uw implementatieproces aanzienlijk, vermindert downtime en vereenvoudigt updates.

Coffee cup

Vond u dit artikel leuk?

Uw steun helpt mij meer diepgaande technische content, open-source tools en gratis bronnen voor de ontwikkelaarsgemeenschap te maken.

Gerelateerde onderwerpen

Engr Mejba Ahmed

Over de auteur

Engr Mejba Ahmed

Engr. Mejba Ahmed builds AI-powered applications and secure cloud systems for businesses worldwide. With 10+ years shipping production software in Laravel, Python, and AWS, he's helped companies automate workflows, reduce infrastructure costs, and scale without security headaches. He writes about practical AI integration, cloud architecture, and developer productivity.

Discussion

Comments

0

No comments yet

Be the first to share your thoughts

Leave a Comment

Your email won't be published

8  x  4  =  ?

Blijf leren

Gerelateerde artikelen

Alles bekijken

Comments

Leave a Comment

Comments are moderated before appearing.

Learning Resources

Expand Your Knowledge

Accelerate your growth with structured courses, verified certificates, interactive flashcards, and production-ready AI agent skills.

Sample Certificate of Completion

Sample certificate — complete any course to earn yours

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support