$npx -y skills add giuseppe-trisciuoglio/developer-kit --skill aws-cloudformation-task-ecs-deploy-ghProvides patterns to deploy ECS tasks and services with GitHub Actions CI/CD. Use when building Docker images, pushing to ECR, updating ECS task definitions, deploying ECS services, integrating with CloudFormation stacks, configuring AWS OIDC authentication for GitHub Actions, an
| 1 | # AWS CloudFormation Task ECS Deploy with GitHub Actions |
| 2 | |
| 3 | Comprehensive skill for deploying ECS containers using GitHub Actions CI/CD pipelines with CloudFormation infrastructure management. |
| 4 | |
| 5 | ## Overview |
| 6 | |
| 7 | Deploy containerized applications to Amazon ECS using GitHub Actions workflows. This skill covers the complete deployment pipeline: authentication with AWS (OIDC recommended), building Docker images, pushing to Amazon ECR, updating task definitions, and deploying ECS services. Integrate with CloudFormation for infrastructure-as-code management and implement production-grade deployment strategies. |
| 8 | |
| 9 | ## When to Use |
| 10 | |
| 11 | - Deploying Docker containers to Amazon ECS with GitHub Actions |
| 12 | - Setting up CI/CD pipelines for ECS using CloudFormation |
| 13 | - Configuring AWS OIDC authentication for GitHub Actions |
| 14 | - Building Docker images and pushing to Amazon ECR |
| 15 | - Updating ECS task definitions dynamically in CI/CD |
| 16 | - Implementing blue/green or rolling deployments for ECS |
| 17 | - Managing CloudFormation stacks from GitHub Actions |
| 18 | |
| 19 | ## Instructions |
| 20 | |
| 21 | Follow these steps to set up ECS deployment with GitHub Actions: |
| 22 | |
| 23 | 1. **Configure AWS Authentication**: Set up OIDC provider for GitHub Actions |
| 24 | 2. **Create IAM Roles**: Define roles for deployment actions |
| 25 | 3. **Set Up ECR Repository**: Create repository with image scanning |
| 26 | 4. **Create ECS Cluster**: Define cluster infrastructure |
| 27 | 5. **Configure Task Definition**: Set up task and container definitions |
| 28 | 6. **Set Up ECS Service**: Configure service with deployment strategy |
| 29 | 7. **Create GitHub Workflow**: Define CI/CD pipeline steps |
| 30 | 8. **Configure Secrets**: Store credentials securely in GitHub Secrets |
| 31 | |
| 32 | ## Quick Start |
| 33 | |
| 34 | ### Basic Deployment Workflow |
| 35 | |
| 36 | ```yaml |
| 37 | name: Deploy to ECS |
| 38 | on: |
| 39 | push: |
| 40 | branches: [main] |
| 41 | |
| 42 | jobs: |
| 43 | deploy: |
| 44 | runs-on: ubuntu-latest |
| 45 | permissions: |
| 46 | id-token: write |
| 47 | contents: read |
| 48 | steps: |
| 49 | - uses: actions/checkout@v4 |
| 50 | |
| 51 | - name: Configure AWS credentials |
| 52 | uses: aws-actions/configure-aws-credentials@v4 |
| 53 | with: |
| 54 | role-to-assume: arn:aws:iam::123456789012:role/github-actions-ecs-role |
| 55 | aws-region: us-east-1 |
| 56 | |
| 57 | - name: Login to ECR |
| 58 | uses: aws-actions/amazon-ecr-login@v2 |
| 59 | |
| 60 | - name: Build and push image |
| 61 | env: |
| 62 | ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 63 | ECR_REPOSITORY: my-app |
| 64 | IMAGE_TAG: ${{ github.sha }} |
| 65 | run: | |
| 66 | docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . |
| 67 | docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
| 68 | |
| 69 | - name: Verify image push |
| 70 | run: | |
| 71 | docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
| 72 | echo "Image $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG verified" |
| 73 | |
| 74 | - name: Update task definition |
| 75 | uses: aws-actions/amazon-ecs-render-task-definition@v1 |
| 76 | id: render-task |
| 77 | with: |
| 78 | task-definition: task-definition.json |
| 79 | container-name: my-app |
| 80 | image: ${{ steps.login-ecr.outputs.registry }}/my-app:${{ github.sha }} |
| 81 | |
| 82 | - name: Validate task definition |
| 83 | run: | |
| 84 | # Validate JSON syntax |
| 85 | cat ${{ steps.render-task.outputs.task-definition }} | jq empty && echo "Task definition JSON is valid" |
| 86 | # Verify container image matches expected |
| 87 | CONTAINER_IMAGE=$(cat ${{ steps.render-task.outputs.task-definition }} | jq -r '.containerDefinitions[0].image') |
| 88 | EXPECTED_IMAGE="${{ steps.login-ecr.outputs.registry }}/my-app:${{ github.sha }}" |
| 89 | if [ "$CONTAINER_IMAGE" = "$EXPECTED_IMAGE" ]; then |
| 90 | echo "Container image matches expected: $CONTAINER_IMAGE" |
| 91 | else |
| 92 | echo "ERROR: Container image mismatch. Expected: $EXPECTED_IMAGE, Got: $CONTAINER_IMAGE" |
| 93 | exit 1 |
| 94 | fi |
| 95 | |
| 96 | - name: Deploy to ECS |
| 97 | uses: aws-actions/amazon-ecs-deploy-task-definition@v1 |
| 98 | with: |
| 99 | task-definition: ${{ steps.render-task.outputs.task-definition }} |
| 100 | service: my-service |
| 101 | cluster: my-cluster |
| 102 | wait-for-service-stability: true |
| 103 | ``` |
| 104 | |
| 105 | See [references/workflow-examples.md](references/workflow-examples.md) for complete workflow examples including multi-environment and blue/green deployments. |
| 106 | |
| 107 | ## Examples |
| 108 | |
| 109 | ### Multi-Environment Deployment |
| 110 | |
| 111 | ```yaml |
| 112 | jobs: |
| 113 | deploy: |
| 114 | strategy: |
| 115 | matrix: |
| 116 | environment: [dev, staging, prod] |
| 117 | s |