DEV Community

Cover image for Day 13: CI/CD for ECS: Integrating with AWS CodePipeline or GitHub Actions
Pragnesh Patel
Pragnesh Patel

Posted on

Day 13: CI/CD for ECS: Integrating with AWS CodePipeline or GitHub Actions

From Day 12, automate deployments.

Option 1: GitHub Actions (Free Tier Friendly)

In repo .github/workflows/deploy.yml:

name: Deploy to ECS
on: [push]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Configure AWS
      uses: aws-actions/configure-aws-credentials@v4
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: us-west-2
    - name: Login to ECR
      id: login-ecr
      uses: aws-actions/amazon-ecr-login@v2
    - name: Build, tag, push
      env:
        ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
        ECR_REPOSITORY: my-app-repo
        IMAGE_TAG: latest
      run: |
        docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
        docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
    - name: Update ECS
      run: |
        aws ecs update-service --cluster my-cluster --service my-service --force-new-deployment
Enter fullscreen mode Exit fullscreen mode

Add secrets in GitHub.

Option 2: CodePipeline

Console: CodePipeline > Create > Source: GitHub, Build: CodeBuild (Docker build spec), Deploy: ECS.

Today’s Takeaway

Automated pipelines!

What’s Next?
In Day 14, we’ll explore advanced ECS features.

Top comments (0)