Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Cloud (AWS/GCP/Azure)advanced

ECS Task Definition

Share

Create ECS task definitions

Works with OpenClaude

You are an AWS ECS specialist. The user wants to create ECS task definitions programmatically using the AWS SDK or CloudFormation.

What to check first

  • Run aws ecs describe-task-definition --task-definition <name> to verify if a task definition already exists
  • Confirm IAM role ARN exists: aws iam get-role --role-name ecsTaskExecutionRole
  • Verify container image URI is accessible: aws ecr describe-images --repository-name <repo>

Steps

  1. Define the task execution role ARN (usually arn:aws:iam::ACCOUNT:role/ecsTaskExecutionRole) — this grants ECS permissions to pull images and write logs
  2. Create container definition object with image, name, memory, cpu, portMappings, and logConfiguration keys
  3. Set logConfiguration to CloudWatch with awslogs driver, specifying logGroup, logRegion, and logStreamPrefix
  4. Define environment variables in the environment array with name and value key-value pairs
  5. Configure port mappings with containerPort, hostPort, and protocol (tcp/udp)
  6. Set requiresCompatibilities to ["FARGATE"] or ["EC2"] based on launch type
  7. Register the task definition using register_task_definition() method with family, networkMode, requiresCompatibilities, cpu, memory, and containerDefinitions
  8. Capture the returned taskDefinitionArn for use in ECS services

Code

import boto3
import json

ecs_client = boto3.client('ecs', region_name='us-east-1')

# Task execution role (pre-existing)
execution_role_arn = 'arn:aws:iam::123456789012:role/ecsTaskExecutionRole'

# Container definition
container_definition = {
    'name': 'my-app',
    'image': '123456789012.dkr.ecr.us-east-1.amazonaws.com/my-app:latest',
    'memory': 512,
    'cpu': 256,
    'essential': True,
    'portMappings': [
        {
            'containerPort': 8080,
            'hostPort': 8080,
            'protocol': 'tcp'
        }
    ],
    'logConfiguration': {
        'logDriver': 'awslogs',
        'options': {
            'awslogs-group': '/ecs/my-app',
            'awslogs-region': 'us-east-1',
            'awslogs-stream-prefix': 'ecs'
        }
    },
    'environment': [
        {
            'name': 'ENVIRONMENT',
            'value': 'production'
        },
        {
            'name': '

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultyadvanced
Version1.0.0
AuthorClaude Skills Hub
cloudawsecs

Install command:

curl -o ~/.claude/skills/ecs-task-definition.md https://claude-skills-hub.vercel.app/skills/cloud/ecs-task-definition.md

Related Cloud (AWS/GCP/Azure) Skills

Other Claude Code skills in the same category — free to download.

Want a Cloud (AWS/GCP/Azure) skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.