DevOps with Amazon ECS and GitHub Actions

Listen to this Post

Featured Image
Running containers on AWS without paying for a managed control plane (like EKS) is efficient for variable workloads. AWS Elastic Container Service (ECS) is a great alternative when full Kubernetes isn’t necessary. This article explores integrating ECS with GitHub Actions for seamless CI/CD deployments.

Read the full article here

You Should Know:

1. Setting Up AWS ECS

To deploy containers on ECS, follow these steps:

1. Install AWS CLI & Configure Credentials

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws configure

2. Create an ECS Cluster

aws ecs create-cluster --cluster-name my-ecs-cluster

3. Define a Task Definition

Save as `task-definition.json`:

{
"family": "my-task",
"networkMode": "awsvpc",
"containerDefinitions": [
{
"name": "my-container",
"image": "nginx:latest",
"portMappings": [{"containerPort": 80}]
}
]
}

Register it:

aws ecs register-task-definition --cli-input-json file://task-definition.json

2. GitHub Actions for ECS Deployment

Create `.github/workflows/deploy-ecs.yml`:

name: Deploy to ECS 
on: [bash] 
jobs: 
deploy: 
runs-on: ubuntu-latest 
steps: 
- uses: actions/checkout@v4 
- name: Configure AWS Credentials 
uses: aws-actions/configure-aws-credentials@v2 
with: 
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} 
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 
aws-region: us-east-1 
- name: Deploy to ECS 
run: | 
aws ecs update-service \ 
--cluster my-ecs-cluster \ 
--service my-service \ 
--force-new-deployment 

3. Key AWS ECS Commands

  • List running services:
    aws ecs list-services --cluster my-ecs-cluster 
    
  • Describe a task:
    aws ecs describe-tasks --cluster my-ecs-cluster --tasks <task-id> 
    
  • Stop a task:
    aws ecs stop-task --cluster my-ecs-cluster --task <task-id> 
    

What Undercode Say

AWS ECS simplifies container orchestration without Kubernetes overhead. Integrating GitHub Actions automates deployments, reducing manual intervention. For cost-effective, scalable container workloads, ECS is a strong choice.

Expected Output:

  • ECS cluster running with zero control-plane costs.
  • GitHub Actions triggering automatic ECS updates.
  • Secure AWS credential handling via GitHub Secrets.

Reference: DevOps w/ Amazon ECS and Github Actions

References:

Reported By: Darryl Ruggles – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass βœ…

Join Our Cyber World:

πŸ’¬ Whatsapp | πŸ’¬ Telegram