jpskill.com
🛠️ 開発・MCP コミュニティ

aws-ecs

Amazon ECSを使って、コンテナ化されたアプリケーションを簡単に実行でき、サーバーレス環境のFargateや柔軟なEC2上で、ロードバランシングや自動スケーリングなどの設定を行い、本番環境に対応したシステムを構築するSkill。

📜 元の英語説明(参考)

Run containerized applications with Amazon ECS. Define tasks and services, deploy on Fargate for serverless containers or EC2 for full control. Configure load balancing, auto-scaling, and service discovery for production workloads.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Amazon ECSを使って、コンテナ化されたアプリケーションを簡単に実行でき、サーバーレス環境のFargateや柔軟なEC2上で、ロードバランシングや自動スケーリングなどの設定を行い、本番環境に対応したシステムを構築するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o aws-ecs.zip https://jpskill.com/download/14667.zip && unzip -o aws-ecs.zip && rm aws-ecs.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/14667.zip -OutFile "$d\aws-ecs.zip"; Expand-Archive "$d\aws-ecs.zip" -DestinationPath $d -Force; ri "$d\aws-ecs.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して aws-ecs.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → aws-ecs フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

AWS ECS

Amazon Elastic Container Service (ECS) は、フルマネージドなコンテナオーケストレーションサービスです。Fargate (サーバーレス) または自己管理の EC2 インスタンス上で、AWS との緊密な統合により Docker コンテナを実行できます。

主要な概念

  • Cluster — タスクとサービスを論理的にグループ化したもの
  • Task Definition — コンテナの設計図 (イメージ、CPU、メモリ、ポート、環境変数)
  • Task — タスク定義の実行中のインスタンス
  • Service — タスクの希望数を維持し、ALB と統合
  • Fargate — コンテナ向けのサーバーレスコンピューティング。EC2 の管理は不要
  • ECR — Docker イメージを格納するための Elastic Container Registry

クラスターのセットアップ

# Fargate クラスターの作成
aws ecs create-cluster --cluster-name app-prod --capacity-providers FARGATE FARGATE_SPOT

タスク定義

// task-definition.json — Web アプリケーションのタスク
{
  "family": "web-app",
  "networkMode": "awsvpc",
  "requiresCompatibilities": ["FARGATE"],
  "cpu": "512",
  "memory": "1024",
  "executionRoleArn": "arn:aws:iam::123456789:role/ecsTaskExecutionRole",
  "taskRoleArn": "arn:aws:iam::123456789:role/ecsTaskRole",
  "containerDefinitions": [
    {
      "name": "web",
      "image": "123456789.dkr.ecr.us-east-1.amazonaws.com/web-app:latest",
      "portMappings": [{"containerPort": 8080, "protocol": "tcp"}],
      "environment": [
        {"name": "NODE_ENV", "value": "production"}
      ],
      "secrets": [
        {"name": "DATABASE_URL", "valueFrom": "arn:aws:secretsmanager:us-east-1:123456789:secret:db-url"}
      ],
      "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "/ecs/web-app",
          "awslogs-region": "us-east-1",
          "awslogs-stream-prefix": "web"
        }
      },
      "healthCheck": {
        "command": ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"],
        "interval": 30,
        "timeout": 5,
        "retries": 3
      }
    }
  ]
}
# タスク定義の登録
aws ecs register-task-definition --cli-input-json file://task-definition.json

サービス

# ALB と Fargate を使用したサービスの作成
aws ecs create-service \
  --cluster app-prod \
  --service-name web-app \
  --task-definition web-app:1 \
  --desired-count 3 \
  --launch-type FARGATE \
  --network-configuration '{
    "awsvpcConfiguration": {
      "subnets": ["subnet-aaa", "subnet-bbb"],
      "securityGroups": ["sg-0123456789abcdef0"],
      "assignPublicIp": "DISABLED"
    }
  }' \
  --load-balancers '[{
    "targetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:123456789:targetgroup/web-tg/abc123",
    "containerName": "web",
    "containerPort": 8080
  }]' \
  --deployment-configuration '{
    "maximumPercent": 200,
    "minimumHealthyPercent": 100,
    "deploymentCircuitBreaker": {"enable": true, "rollback": true}
  }'
# サービスの更新 (新しいイメージのデプロイ)
aws ecs update-service \
  --cluster app-prod \
  --service web-app \
  --task-definition web-app:2 \
  --force-new-deployment
# サービスのスケール
aws ecs update-service \
  --cluster app-prod \
  --service web-app \
  --desired-count 5

自動スケーリング

# スケーラブルターゲットの登録
aws application-autoscaling register-scalable-target \
  --service-namespace ecs \
  --resource-id service/app-prod/web-app \
  --scalable-dimension ecs:service:DesiredCount \
  --min-capacity 2 \
  --max-capacity 20
# CPU に基づくターゲット追跡
aws application-autoscaling put-scaling-policy \
  --service-namespace ecs \
  --resource-id service/app-prod/web-app \
  --scalable-dimension ecs:service:DesiredCount \
  --policy-name cpu-scaling \
  --policy-type TargetTrackingScaling \
  --target-tracking-scaling-policy-configuration '{
    "PredefinedMetricSpecification": {"PredefinedMetricType": "ECSServiceAverageCPUUtilization"},
    "TargetValue": 70.0,
    "ScaleInCooldown": 300,
    "ScaleOutCooldown": 60
  }'

ECR (コンテナレジストリ)

# リポジトリの作成
aws ecr create-repository --repository-name web-app --image-scanning-configuration scanOnPush=true
# ログイン、ビルド、プッシュ
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 123456789.dkr.ecr.us-east-1.amazonaws.com
docker build -t web-app .
docker tag web-app:latest 123456789.dkr.ecr.us-east-1.amazonaws.com/web-app:latest
docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/web-app:latest

1 回限りのタスクの実行

# マイグレーションタスクの実行
aws ecs run-task \
  --cluster app-prod \
  --task-definition db-migrate:1 \
  --launch-type FARGATE \
  --network-configuration '{
    "awsvpcConfiguration": {
      "subnets": ["subnet-aaa"],
      "securityGroups": ["sg-0123456789abcdef0"],
      "assignPublicIp": "DISABLED"
    }
  }' \
  --overrides '{
    "containerOverrides": [{"name": "migrate", "command": ["npm", "run", "migrate"]}]
  }'

モニタリング

# 実行中のタスクの一覧表示
aws ecs list-tasks --cluster app-prod --service-name web-app --desired-status RUNNING
# タスクログの表示
aws logs tail /ecs/web-app --follow --since 1h

ベストプラクティス

  • インスタンス管理を不要にするため、ほとんどのワークロードに Fargate を使用する
  • シークレットは環境変数ではなく、Secrets Manager または Parameter Store に格納する
  • デプロイメントサーキットブレーカーを有効にして、失敗したデプロイを自動的にロールバックする
  • CloudWatch での一元的なロギングには、awslogs ドライバーを使用する
  • タスク定義とターゲットグループの両方でヘルスチェックを設定する
  • 重要度の低いバックグラウンドワーカーには Fargate Spot を使用する (最大 70% のコスト削減)
  • 本番環境ではイメージタグを固定する。再現性を高めるために latest は避ける
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

AWS ECS

Amazon Elastic Container Service (ECS) is a fully managed container orchestration service. Run Docker containers on Fargate (serverless) or self-managed EC2 instances with deep AWS integration.

Core Concepts

  • Cluster — logical grouping of tasks and services
  • Task Definition — blueprint for containers (image, CPU, memory, ports, env vars)
  • Task — a running instance of a task definition
  • Service — maintains desired count of tasks, integrates with ALB
  • Fargate — serverless compute for containers, no EC2 management
  • ECR — Elastic Container Registry for storing Docker images

Cluster Setup

# Create a Fargate cluster
aws ecs create-cluster --cluster-name app-prod --capacity-providers FARGATE FARGATE_SPOT

Task Definitions

// task-definition.json — web application task
{
  "family": "web-app",
  "networkMode": "awsvpc",
  "requiresCompatibilities": ["FARGATE"],
  "cpu": "512",
  "memory": "1024",
  "executionRoleArn": "arn:aws:iam::123456789:role/ecsTaskExecutionRole",
  "taskRoleArn": "arn:aws:iam::123456789:role/ecsTaskRole",
  "containerDefinitions": [
    {
      "name": "web",
      "image": "123456789.dkr.ecr.us-east-1.amazonaws.com/web-app:latest",
      "portMappings": [{"containerPort": 8080, "protocol": "tcp"}],
      "environment": [
        {"name": "NODE_ENV", "value": "production"}
      ],
      "secrets": [
        {"name": "DATABASE_URL", "valueFrom": "arn:aws:secretsmanager:us-east-1:123456789:secret:db-url"}
      ],
      "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "/ecs/web-app",
          "awslogs-region": "us-east-1",
          "awslogs-stream-prefix": "web"
        }
      },
      "healthCheck": {
        "command": ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"],
        "interval": 30,
        "timeout": 5,
        "retries": 3
      }
    }
  ]
}
# Register task definition
aws ecs register-task-definition --cli-input-json file://task-definition.json

Services

# Create a service with ALB and Fargate
aws ecs create-service \
  --cluster app-prod \
  --service-name web-app \
  --task-definition web-app:1 \
  --desired-count 3 \
  --launch-type FARGATE \
  --network-configuration '{
    "awsvpcConfiguration": {
      "subnets": ["subnet-aaa", "subnet-bbb"],
      "securityGroups": ["sg-0123456789abcdef0"],
      "assignPublicIp": "DISABLED"
    }
  }' \
  --load-balancers '[{
    "targetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:123456789:targetgroup/web-tg/abc123",
    "containerName": "web",
    "containerPort": 8080
  }]' \
  --deployment-configuration '{
    "maximumPercent": 200,
    "minimumHealthyPercent": 100,
    "deploymentCircuitBreaker": {"enable": true, "rollback": true}
  }'
# Update service (deploy new image)
aws ecs update-service \
  --cluster app-prod \
  --service web-app \
  --task-definition web-app:2 \
  --force-new-deployment
# Scale service
aws ecs update-service \
  --cluster app-prod \
  --service web-app \
  --desired-count 5

Auto Scaling

# Register scalable target
aws application-autoscaling register-scalable-target \
  --service-namespace ecs \
  --resource-id service/app-prod/web-app \
  --scalable-dimension ecs:service:DesiredCount \
  --min-capacity 2 \
  --max-capacity 20
# Target tracking on CPU
aws application-autoscaling put-scaling-policy \
  --service-namespace ecs \
  --resource-id service/app-prod/web-app \
  --scalable-dimension ecs:service:DesiredCount \
  --policy-name cpu-scaling \
  --policy-type TargetTrackingScaling \
  --target-tracking-scaling-policy-configuration '{
    "PredefinedMetricSpecification": {"PredefinedMetricType": "ECSServiceAverageCPUUtilization"},
    "TargetValue": 70.0,
    "ScaleInCooldown": 300,
    "ScaleOutCooldown": 60
  }'

ECR (Container Registry)

# Create repository
aws ecr create-repository --repository-name web-app --image-scanning-configuration scanOnPush=true
# Login, build, push
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 123456789.dkr.ecr.us-east-1.amazonaws.com
docker build -t web-app .
docker tag web-app:latest 123456789.dkr.ecr.us-east-1.amazonaws.com/web-app:latest
docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/web-app:latest

Running One-Off Tasks

# Run a migration task
aws ecs run-task \
  --cluster app-prod \
  --task-definition db-migrate:1 \
  --launch-type FARGATE \
  --network-configuration '{
    "awsvpcConfiguration": {
      "subnets": ["subnet-aaa"],
      "securityGroups": ["sg-0123456789abcdef0"],
      "assignPublicIp": "DISABLED"
    }
  }' \
  --overrides '{
    "containerOverrides": [{"name": "migrate", "command": ["npm", "run", "migrate"]}]
  }'

Monitoring

# List running tasks
aws ecs list-tasks --cluster app-prod --service-name web-app --desired-status RUNNING
# View task logs
aws logs tail /ecs/web-app --follow --since 1h

Best Practices

  • Use Fargate for most workloads to eliminate instance management
  • Store secrets in Secrets Manager or Parameter Store, not environment variables
  • Enable deployment circuit breaker to auto-rollback failed deployments
  • Use awslogs driver for centralized logging in CloudWatch
  • Set health checks in both the task definition and target group
  • Use Fargate Spot for non-critical background workers (up to 70% savings)
  • Pin image tags in production; avoid latest for reproducibility