@deftai/directive-content 0.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/deft/SKILL.md +6 -0
- package/.agents/skills/deft-directive-article-review/SKILL.md +11 -0
- package/.agents/skills/deft-directive-build/SKILL.md +10 -0
- package/.agents/skills/deft-directive-cost/SKILL.md +12 -0
- package/.agents/skills/deft-directive-debug/SKILL.md +13 -0
- package/.agents/skills/deft-directive-gh-arch/SKILL.md +11 -0
- package/.agents/skills/deft-directive-gh-slice/SKILL.md +10 -0
- package/.agents/skills/deft-directive-glossary/SKILL.md +10 -0
- package/.agents/skills/deft-directive-interview/SKILL.md +9 -0
- package/.agents/skills/deft-directive-pre-pr/SKILL.md +9 -0
- package/.agents/skills/deft-directive-refinement/SKILL.md +10 -0
- package/.agents/skills/deft-directive-release/SKILL.md +12 -0
- package/.agents/skills/deft-directive-review-cycle/SKILL.md +10 -0
- package/.agents/skills/deft-directive-setup/SKILL.md +10 -0
- package/.agents/skills/deft-directive-swarm/SKILL.md +10 -0
- package/.agents/skills/deft-directive-sync/SKILL.md +9 -0
- package/.agents/skills/deft-directive-triage/SKILL.md +9 -0
- package/.agents/skills/deft-directive-write-skill/SKILL.md +9 -0
- package/LICENSE.md +22 -0
- package/QUICK-START.md +167 -0
- package/UPGRADING.md +517 -0
- package/coding/build-output.md +28 -0
- package/coding/coding.md +235 -0
- package/coding/debugging.md +110 -0
- package/coding/holzmann.md +96 -0
- package/coding/hygiene.md +127 -0
- package/coding/security.md +158 -0
- package/coding/testing.md +162 -0
- package/coding/toolchain.md +44 -0
- package/commands.md +300 -0
- package/context/context.md +57 -0
- package/context/deterministic-split.md +67 -0
- package/context/examples.md +26 -0
- package/context/fractal-summaries.md +69 -0
- package/context/long-horizon.md +46 -0
- package/context/spec-deltas.md +177 -0
- package/context/tool-design.md +34 -0
- package/context/working-memory.md +62 -0
- package/contracts/boundary-maps.md +65 -0
- package/contracts/deterministic-questions.md +59 -0
- package/contracts/hierarchy.md +77 -0
- package/conventions/content-manifest.json +399 -0
- package/conventions/machine-generated-banner.md +130 -0
- package/conventions/references.md +120 -0
- package/conventions/rule-ownership.json +382 -0
- package/conventions/task-caching.md +43 -0
- package/conventions/vbrief-filenames.md +70 -0
- package/deployments/README.md +37 -0
- package/deployments/agentuity/README.md +138 -0
- package/deployments/agentuity/via-cli.md +380 -0
- package/deployments/agentuity/via-cloud.md +425 -0
- package/deployments/agentuity/via-github-actions.md +664 -0
- package/deployments/agentuity/via-gravity-network.md +606 -0
- package/deployments/agentuity/via-vpc.md +607 -0
- package/deployments/aws/README.md +38 -0
- package/deployments/aws/via-app-runner.md +612 -0
- package/deployments/aws/via-ecs-fargate.md +561 -0
- package/deployments/aws/via-elastic-beanstalk.md +628 -0
- package/deployments/aws/via-lambda.md +649 -0
- package/deployments/azure/README.md +37 -0
- package/deployments/azure/via-aks.md +390 -0
- package/deployments/azure/via-app-service.md +564 -0
- package/deployments/azure/via-container-apps.md +599 -0
- package/deployments/azure/via-functions.md +552 -0
- package/deployments/cloud-gov/README.md +63 -0
- package/deployments/cloud-gov/agents/compliance-docs.md +154 -0
- package/deployments/cloud-gov/agents.md +39 -0
- package/deployments/cloud-gov/cicd.md +64 -0
- package/deployments/cloud-gov/deployment.md +150 -0
- package/deployments/cloud-gov/logging.md +43 -0
- package/deployments/cloud-gov/manifest.md +121 -0
- package/deployments/cloud-gov/overview.md +58 -0
- package/deployments/cloud-gov/security.md +46 -0
- package/deployments/cloud-gov/services.md +72 -0
- package/deployments/cloud-gov/upstream/README.md +18 -0
- package/deployments/cloudflare/README.md +33 -0
- package/deployments/cloudflare/via-dashboard.md +83 -0
- package/deployments/cloudflare/via-git.md +90 -0
- package/deployments/cloudflare/via-github-actions.md +185 -0
- package/deployments/cloudflare/via-terraform.md +157 -0
- package/deployments/cloudflare/via-wrangler.md +165 -0
- package/deployments/fly-io/README.md +37 -0
- package/deployments/fly-io/via-dockerfile.md +648 -0
- package/deployments/fly-io/via-flyctl.md +653 -0
- package/deployments/fly-io/via-github-actions.md +695 -0
- package/deployments/fly-io/via-multi-region.md +598 -0
- package/deployments/google/README.md +34 -0
- package/deployments/google/via-app-engine.md +42 -0
- package/deployments/google/via-cloud-functions.md +23 -0
- package/deployments/google/via-cloud-run.md +330 -0
- package/deployments/google/via-gke.md +23 -0
- package/deployments/netlify/README.md +99 -0
- package/deployments/netlify/via-cli.md +17 -0
- package/deployments/netlify/via-functions.md +19 -0
- package/deployments/netlify/via-git.md +25 -0
- package/deployments/vercel/README.md +90 -0
- package/deployments/vercel/via-api.md +16 -0
- package/deployments/vercel/via-cli.md +17 -0
- package/deployments/vercel/via-git.md +24 -0
- package/docs/BROWNFIELD.md +179 -0
- package/docs/getting-started.md +137 -0
- package/docs/good-agents-md.md +137 -0
- package/events/README.md +89 -0
- package/events/event-record.schema.json +26 -0
- package/events/registry.json +166 -0
- package/events/registry.schema.json +71 -0
- package/glossary.md +145 -0
- package/incidents/README.md +81 -0
- package/incidents/_template.md +38 -0
- package/interfaces/cli.md +104 -0
- package/interfaces/rest.md +212 -0
- package/interfaces/tui.md +242 -0
- package/interfaces/web.md +123 -0
- package/languages/6502-DASM.md +132 -0
- package/languages/c.md +235 -0
- package/languages/commands.md +23 -0
- package/languages/cpp.md +132 -0
- package/languages/csharp.md +259 -0
- package/languages/dart.md +183 -0
- package/languages/delphi.md +218 -0
- package/languages/elixir.md +208 -0
- package/languages/go.md +78 -0
- package/languages/java.md +278 -0
- package/languages/javascript.md +163 -0
- package/languages/julia.md +175 -0
- package/languages/kotlin.md +193 -0
- package/languages/markdown.md +168 -0
- package/languages/mermaid.md +146 -0
- package/languages/officejs.md +392 -0
- package/languages/python.md +209 -0
- package/languages/r.md +163 -0
- package/languages/rust.md +216 -0
- package/languages/sql.md +216 -0
- package/languages/swift.md +153 -0
- package/languages/typescript.md +132 -0
- package/languages/vba.md +279 -0
- package/languages/vhdl.md +180 -0
- package/languages/visual-basic.md +151 -0
- package/languages/zig.md +196 -0
- package/meta/SOUL.md +27 -0
- package/meta/code-field.md +44 -0
- package/meta/morals.md +40 -0
- package/meta/philosophy.md +39 -0
- package/meta/project.md +49 -0
- package/meta/ralph.md +223 -0
- package/meta/security.md +80 -0
- package/meta/versioning.md +326 -0
- package/package.json +22 -0
- package/packs/lessons/lessons-pack-0.1.json +553 -0
- package/packs/patterns/patterns-pack-0.1.json +57 -0
- package/packs/rules/rules-pack-0.1.json +4767 -0
- package/packs/skills/skills-pack-0.1.json +262 -0
- package/packs/strategies/strategies-pack-0.1.json +167 -0
- package/packs/swarm-spec/swarm-spec-pack-0.1.json +17 -0
- package/patterns/executor-layer-credentials.md +227 -0
- package/patterns/llm-app.md +156 -0
- package/patterns/multi-agent.md +278 -0
- package/patterns/prompt-assembly-layer-ordering.md +154 -0
- package/patterns/role-as-overlay.md +179 -0
- package/platforms/2600.md +137 -0
- package/platforms/unity.md +329 -0
- package/references/composer-skill-porting.md +152 -0
- package/references/cost-models.md +163 -0
- package/references/ip-risk.md +246 -0
- package/references/plain-english-ux.md +275 -0
- package/resilience/context-pruning.md +67 -0
- package/resilience/continue-here.md +62 -0
- package/scm/changelog.md +276 -0
- package/scm/git.md +139 -0
- package/scm/github.md +265 -0
- package/secrets/.gitkeep +0 -0
- package/skills/deft-build/SKILL.md +20 -0
- package/skills/deft-directive-article-review/SKILL.md +156 -0
- package/skills/deft-directive-build/SKILL.md +302 -0
- package/skills/deft-directive-cost/SKILL.md +201 -0
- package/skills/deft-directive-debug/SKILL.md +140 -0
- package/skills/deft-directive-decompose/SKILL.md +96 -0
- package/skills/deft-directive-gh-arch/SKILL.md +160 -0
- package/skills/deft-directive-gh-slice/SKILL.md +199 -0
- package/skills/deft-directive-glossary/SKILL.md +118 -0
- package/skills/deft-directive-interview/SKILL.md +528 -0
- package/skills/deft-directive-pre-pr/SKILL.md +131 -0
- package/skills/deft-directive-probe/SKILL.md +127 -0
- package/skills/deft-directive-refinement/SKILL.md +403 -0
- package/skills/deft-directive-release/SKILL.md +266 -0
- package/skills/deft-directive-review-cycle/SKILL.md +401 -0
- package/skills/deft-directive-setup/SKILL.md +717 -0
- package/skills/deft-directive-swarm/SKILL.md +989 -0
- package/skills/deft-directive-sync/SKILL.md +288 -0
- package/skills/deft-directive-triage/SKILL.md +137 -0
- package/skills/deft-directive-write-skill/SKILL.md +169 -0
- package/skills/deft-interview/SKILL.md +16 -0
- package/skills/deft-pre-pr/SKILL.md +16 -0
- package/skills/deft-review-cycle/SKILL.md +16 -0
- package/skills/deft-roadmap-refresh/SKILL.md +16 -0
- package/skills/deft-setup/SKILL.md +20 -0
- package/skills/deft-swarm/SKILL.md +16 -0
- package/skills/deft-sync/SKILL.md +16 -0
- package/strategies/README.md +83 -0
- package/strategies/artifact-guards.md +85 -0
- package/strategies/bdd.md +115 -0
- package/strategies/brownfield.md +7 -0
- package/strategies/discuss.md +129 -0
- package/strategies/emit-hints.md +69 -0
- package/strategies/enterprise.md +193 -0
- package/strategies/interview.md +551 -0
- package/strategies/map.md +179 -0
- package/strategies/probe.md +151 -0
- package/strategies/rapid.md +155 -0
- package/strategies/research.md +155 -0
- package/strategies/roadmap.md +9 -0
- package/strategies/speckit.md +437 -0
- package/strategies/v0-20-contract.md +134 -0
- package/strategies/yolo.md +169 -0
- package/swarm/swarm.md +300 -0
- package/templates/COST-ESTIMATE.md +114 -0
- package/templates/PULL_REQUEST_TEMPLATE.md +35 -0
- package/templates/agent-prompt-preamble.md +409 -0
- package/templates/agents-entry.md +211 -0
- package/templates/agents-entry.placeholders.md +75 -0
- package/templates/embed.go +20 -0
- package/templates/embed_test.go +36 -0
- package/templates/make-spec-example.md +9 -0
- package/templates/make-spec.md +246 -0
- package/templates/project.md.template +52 -0
- package/templates/specification.md +1 -0
- package/templates/swarm-greptile-poller-prompt.md +556 -0
- package/templates/user.md.template +31 -0
- package/tools/RWLDL.md +80 -0
- package/tools/greptile.md +141 -0
- package/tools/installer.md +23 -0
- package/tools/taskfile-migration.md +32 -0
- package/tools/taskfile.md +185 -0
- package/tools/telemetry.md +285 -0
- package/vbrief/schemas/cache-meta.schema.json +137 -0
- package/vbrief/schemas/candidates.schema.json +130 -0
- package/vbrief/schemas/codebase-map.schema.json +213 -0
- package/vbrief/schemas/lessons-pack.schema.json +134 -0
- package/vbrief/schemas/patterns-pack.schema.json +84 -0
- package/vbrief/schemas/rules-pack.schema.json +105 -0
- package/vbrief/schemas/skills-pack.schema.json +94 -0
- package/vbrief/schemas/slices.schema.json +87 -0
- package/vbrief/schemas/strategies-pack.schema.json +89 -0
- package/vbrief/schemas/swarm-spec-pack.schema.json +84 -0
- package/vbrief/schemas/vbrief-core.schema.json +1022 -0
- package/vbrief/vbrief.md +684 -0
- package/verification/integration.md +76 -0
- package/verification/plan-checking.md +85 -0
- package/verification/uat.md +60 -0
- package/verification/verification.md +117 -0
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
# Deploy via ECS Fargate
|
|
2
|
+
|
|
3
|
+
Deploy containerized applications using Amazon ECS (Elastic Container Service) with Fargate. Managed container orchestration without server management.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
ECS Fargate provides serverless container compute:
|
|
8
|
+
- **No Infrastructure Management**: No EC2 instances to manage
|
|
9
|
+
- **Task Definitions**: Define containers declaratively
|
|
10
|
+
- **Service Auto-scaling**: Scale based on metrics
|
|
11
|
+
- **Load Balancer Integration**: ALB/NLB built-in
|
|
12
|
+
- **VPC Networking**: Full networking control
|
|
13
|
+
|
|
14
|
+
## Prerequisites
|
|
15
|
+
|
|
16
|
+
- AWS account with IAM permissions
|
|
17
|
+
- Docker image in ECR or public registry
|
|
18
|
+
- AWS CLI installed
|
|
19
|
+
- ECS CLI (optional but recommended)
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### 1. Create ECR Repository and Push Image
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Create repository
|
|
27
|
+
aws ecr create-repository --repository-name my-app
|
|
28
|
+
|
|
29
|
+
# Login to ECR
|
|
30
|
+
aws ecr get-login-password --region us-east-1 | \
|
|
31
|
+
docker login --username AWS --password-stdin \
|
|
32
|
+
ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com
|
|
33
|
+
|
|
34
|
+
# Build and push
|
|
35
|
+
docker build -t my-app .
|
|
36
|
+
docker tag my-app:latest ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/my-app:latest
|
|
37
|
+
docker push ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/my-app:latest
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Create Task Definition
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"family": "my-app",
|
|
45
|
+
"networkMode": "awsvpc",
|
|
46
|
+
"requiresCompatibilities": ["FARGATE"],
|
|
47
|
+
"cpu": "256",
|
|
48
|
+
"memory": "512",
|
|
49
|
+
"containerDefinitions": [
|
|
50
|
+
{
|
|
51
|
+
"name": "app",
|
|
52
|
+
"image": "ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/my-app:latest",
|
|
53
|
+
"portMappings": [
|
|
54
|
+
{
|
|
55
|
+
"containerPort": 8080,
|
|
56
|
+
"protocol": "tcp"
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
"environment": [
|
|
60
|
+
{
|
|
61
|
+
"name": "APP_ENV",
|
|
62
|
+
"value": "production"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"logConfiguration": {
|
|
66
|
+
"logDriver": "awslogs",
|
|
67
|
+
"options": {
|
|
68
|
+
"awslogs-group": "/ecs/my-app",
|
|
69
|
+
"awslogs-region": "us-east-1",
|
|
70
|
+
"awslogs-stream-prefix": "ecs"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"executionRoleArn": "arn:aws:iam::ACCOUNT_ID:role/ecsTaskExecutionRole",
|
|
76
|
+
"taskRoleArn": "arn:aws:iam::ACCOUNT_ID:role/ecsTaskRole"
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Register task definition
|
|
82
|
+
aws ecs register-task-definition --cli-input-json file://task-definition.json
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 3. Create ECS Cluster
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
aws ecs create-cluster --cluster-name my-cluster
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 4. Create Service with Load Balancer
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
aws ecs create-service \
|
|
95
|
+
--cluster my-cluster \
|
|
96
|
+
--service-name my-app \
|
|
97
|
+
--task-definition my-app:1 \
|
|
98
|
+
--desired-count 2 \
|
|
99
|
+
--launch-type FARGATE \
|
|
100
|
+
--network-configuration "awsvpcConfiguration={
|
|
101
|
+
subnets=[subnet-xxx,subnet-yyy],
|
|
102
|
+
securityGroups=[sg-xxx],
|
|
103
|
+
assignPublicIp=ENABLED
|
|
104
|
+
}" \
|
|
105
|
+
--load-balancers "targetGroupArn=arn:aws:elasticloadbalancing:...,containerName=app,containerPort=8080"
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Task Definition Patterns
|
|
109
|
+
|
|
110
|
+
### Basic Web Application
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"family": "web-app",
|
|
115
|
+
"networkMode": "awsvpc",
|
|
116
|
+
"requiresCompatibilities": ["FARGATE"],
|
|
117
|
+
"cpu": "1024",
|
|
118
|
+
"memory": "2048",
|
|
119
|
+
"containerDefinitions": [
|
|
120
|
+
{
|
|
121
|
+
"name": "nginx",
|
|
122
|
+
"image": "nginx:latest",
|
|
123
|
+
"portMappings": [
|
|
124
|
+
{
|
|
125
|
+
"containerPort": 80
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
"dependsOn": [
|
|
129
|
+
{
|
|
130
|
+
"containerName": "app",
|
|
131
|
+
"condition": "START"
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"name": "app",
|
|
137
|
+
"image": "my-app:latest",
|
|
138
|
+
"portMappings": [
|
|
139
|
+
{
|
|
140
|
+
"containerPort": 8080
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
"environment": [
|
|
144
|
+
{"name": "PORT", "value": "8080"}
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### With Secrets from Secrets Manager
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"containerDefinitions": [
|
|
156
|
+
{
|
|
157
|
+
"name": "app",
|
|
158
|
+
"image": "my-app:latest",
|
|
159
|
+
"secrets": [
|
|
160
|
+
{
|
|
161
|
+
"name": "DB_PASSWORD",
|
|
162
|
+
"valueFrom": "arn:aws:secretsmanager:region:account:secret:db-password-xxx"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"name": "API_KEY",
|
|
166
|
+
"valueFrom": "arn:aws:ssm:region:account:parameter/api-key"
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
],
|
|
171
|
+
"executionRoleArn": "arn:aws:iam::account:role/ecsTaskExecutionRole"
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### With EFS Volumes
|
|
176
|
+
|
|
177
|
+
```json
|
|
178
|
+
{
|
|
179
|
+
"family": "app-with-storage",
|
|
180
|
+
"volumes": [
|
|
181
|
+
{
|
|
182
|
+
"name": "shared-data",
|
|
183
|
+
"efsVolumeConfiguration": {
|
|
184
|
+
"fileSystemId": "fs-xxxxx",
|
|
185
|
+
"transitEncryption": "ENABLED",
|
|
186
|
+
"authorizationConfig": {
|
|
187
|
+
"accessPointId": "fsap-xxxxx"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
"containerDefinitions": [
|
|
193
|
+
{
|
|
194
|
+
"name": "app",
|
|
195
|
+
"mountPoints": [
|
|
196
|
+
{
|
|
197
|
+
"sourceVolume": "shared-data",
|
|
198
|
+
"containerPath": "/data",
|
|
199
|
+
"readOnly": false
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
]
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Service Configuration
|
|
208
|
+
|
|
209
|
+
### Auto-scaling
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# Register scalable target
|
|
213
|
+
aws application-autoscaling register-scalable-target \
|
|
214
|
+
--service-namespace ecs \
|
|
215
|
+
--resource-id service/my-cluster/my-app \
|
|
216
|
+
--scalable-dimension ecs:service:DesiredCount \
|
|
217
|
+
--min-capacity 2 \
|
|
218
|
+
--max-capacity 10
|
|
219
|
+
|
|
220
|
+
# CPU-based scaling
|
|
221
|
+
aws application-autoscaling put-scaling-policy \
|
|
222
|
+
--service-namespace ecs \
|
|
223
|
+
--scalable-dimension ecs:service:DesiredCount \
|
|
224
|
+
--resource-id service/my-cluster/my-app \
|
|
225
|
+
--policy-name cpu-scaling \
|
|
226
|
+
--policy-type TargetTrackingScaling \
|
|
227
|
+
--target-tracking-scaling-policy-configuration '{
|
|
228
|
+
"TargetValue": 75.0,
|
|
229
|
+
"PredefinedMetricSpecification": {
|
|
230
|
+
"PredefinedMetricType": "ECSServiceAverageCPUUtilization"
|
|
231
|
+
},
|
|
232
|
+
"ScaleInCooldown": 300,
|
|
233
|
+
"ScaleOutCooldown": 60
|
|
234
|
+
}'
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Load Balancer Integration
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
# Create Application Load Balancer
|
|
241
|
+
aws elbv2 create-load-balancer \
|
|
242
|
+
--name my-alb \
|
|
243
|
+
--subnets subnet-xxx subnet-yyy \
|
|
244
|
+
--security-groups sg-xxx \
|
|
245
|
+
--scheme internet-facing \
|
|
246
|
+
--type application
|
|
247
|
+
|
|
248
|
+
# Create target group
|
|
249
|
+
aws elbv2 create-target-group \
|
|
250
|
+
--name my-targets \
|
|
251
|
+
--protocol HTTP \
|
|
252
|
+
--port 80 \
|
|
253
|
+
--vpc-id vpc-xxx \
|
|
254
|
+
--target-type ip \
|
|
255
|
+
--health-check-path /health
|
|
256
|
+
|
|
257
|
+
# Create listener
|
|
258
|
+
aws elbv2 create-listener \
|
|
259
|
+
--load-balancer-arn arn:aws:elasticloadbalancing:... \
|
|
260
|
+
--protocol HTTP \
|
|
261
|
+
--port 80 \
|
|
262
|
+
--default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:...
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Infrastructure as Code
|
|
266
|
+
|
|
267
|
+
### CloudFormation Template
|
|
268
|
+
|
|
269
|
+
```yaml
|
|
270
|
+
# ecs-stack.yaml
|
|
271
|
+
Resources:
|
|
272
|
+
ECSCluster:
|
|
273
|
+
Type: AWS::ECS::Cluster
|
|
274
|
+
Properties:
|
|
275
|
+
ClusterName: my-cluster
|
|
276
|
+
|
|
277
|
+
TaskDefinition:
|
|
278
|
+
Type: AWS::ECS::TaskDefinition
|
|
279
|
+
Properties:
|
|
280
|
+
Family: my-app
|
|
281
|
+
NetworkMode: awsvpc
|
|
282
|
+
RequiresCompatibilities:
|
|
283
|
+
- FARGATE
|
|
284
|
+
Cpu: '256'
|
|
285
|
+
Memory: '512'
|
|
286
|
+
ContainerDefinitions:
|
|
287
|
+
- Name: app
|
|
288
|
+
Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/my-app:latest
|
|
289
|
+
PortMappings:
|
|
290
|
+
- ContainerPort: 8080
|
|
291
|
+
LogConfiguration:
|
|
292
|
+
LogDriver: awslogs
|
|
293
|
+
Options:
|
|
294
|
+
awslogs-group: !Ref LogGroup
|
|
295
|
+
awslogs-region: !Ref AWS::Region
|
|
296
|
+
awslogs-stream-prefix: ecs
|
|
297
|
+
ExecutionRoleArn: !GetAtt ExecutionRole.Arn
|
|
298
|
+
TaskRoleArn: !GetAtt TaskRole.Arn
|
|
299
|
+
|
|
300
|
+
Service:
|
|
301
|
+
Type: AWS::ECS::Service
|
|
302
|
+
DependsOn: LoadBalancerListener
|
|
303
|
+
Properties:
|
|
304
|
+
ServiceName: my-app
|
|
305
|
+
Cluster: !Ref ECSCluster
|
|
306
|
+
TaskDefinition: !Ref TaskDefinition
|
|
307
|
+
DesiredCount: 2
|
|
308
|
+
LaunchType: FARGATE
|
|
309
|
+
NetworkConfiguration:
|
|
310
|
+
AwsvpcConfiguration:
|
|
311
|
+
Subnets:
|
|
312
|
+
- !Ref PrivateSubnet1
|
|
313
|
+
- !Ref PrivateSubnet2
|
|
314
|
+
SecurityGroups:
|
|
315
|
+
- !Ref ContainerSecurityGroup
|
|
316
|
+
LoadBalancers:
|
|
317
|
+
- ContainerName: app
|
|
318
|
+
ContainerPort: 8080
|
|
319
|
+
TargetGroupArn: !Ref TargetGroup
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Terraform
|
|
323
|
+
|
|
324
|
+
```hcl
|
|
325
|
+
# main.tf
|
|
326
|
+
resource "aws_ecs_cluster" "main" {
|
|
327
|
+
name = "my-cluster"
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
resource "aws_ecs_task_definition" "app" {
|
|
331
|
+
family = "my-app"
|
|
332
|
+
network_mode = "awsvpc"
|
|
333
|
+
requires_compatibilities = ["FARGATE"]
|
|
334
|
+
cpu = 256
|
|
335
|
+
memory = 512
|
|
336
|
+
execution_role_arn = aws_iam_role.execution.arn
|
|
337
|
+
task_role_arn = aws_iam_role.task.arn
|
|
338
|
+
|
|
339
|
+
container_definitions = jsonencode([
|
|
340
|
+
{
|
|
341
|
+
name = "app"
|
|
342
|
+
image = "${data.aws_caller_identity.current.account_id}.dkr.ecr.us-east-1.amazonaws.com/my-app:latest"
|
|
343
|
+
portMappings = [
|
|
344
|
+
{
|
|
345
|
+
containerPort = 8080
|
|
346
|
+
protocol = "tcp"
|
|
347
|
+
}
|
|
348
|
+
]
|
|
349
|
+
logConfiguration = {
|
|
350
|
+
logDriver = "awslogs"
|
|
351
|
+
options = {
|
|
352
|
+
"awslogs-group" = aws_cloudwatch_log_group.app.name
|
|
353
|
+
"awslogs-region" = "us-east-1"
|
|
354
|
+
"awslogs-stream-prefix" = "ecs"
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
])
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
resource "aws_ecs_service" "app" {
|
|
362
|
+
name = "my-app"
|
|
363
|
+
cluster = aws_ecs_cluster.main.id
|
|
364
|
+
task_definition = aws_ecs_task_definition.app.arn
|
|
365
|
+
desired_count = 2
|
|
366
|
+
launch_type = "FARGATE"
|
|
367
|
+
|
|
368
|
+
network_configuration {
|
|
369
|
+
subnets = [aws_subnet.private1.id, aws_subnet.private2.id]
|
|
370
|
+
security_groups = [aws_security_group.ecs_tasks.id]
|
|
371
|
+
assign_public_ip = false
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
load_balancer {
|
|
375
|
+
target_group_arn = aws_lb_target_group.app.arn
|
|
376
|
+
container_name = "app"
|
|
377
|
+
container_port = 8080
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
## CI/CD Integration
|
|
383
|
+
|
|
384
|
+
### GitHub Actions
|
|
385
|
+
|
|
386
|
+
```yaml
|
|
387
|
+
# .github/workflows/deploy.yml
|
|
388
|
+
name: Deploy to ECS
|
|
389
|
+
|
|
390
|
+
on:
|
|
391
|
+
push:
|
|
392
|
+
branches: [main]
|
|
393
|
+
|
|
394
|
+
env:
|
|
395
|
+
AWS_REGION: us-east-1
|
|
396
|
+
ECR_REPOSITORY: my-app
|
|
397
|
+
ECS_SERVICE: my-app
|
|
398
|
+
ECS_CLUSTER: my-cluster
|
|
399
|
+
CONTAINER_NAME: app
|
|
400
|
+
|
|
401
|
+
jobs:
|
|
402
|
+
deploy:
|
|
403
|
+
runs-on: ubuntu-latest
|
|
404
|
+
|
|
405
|
+
steps:
|
|
406
|
+
- uses: actions/checkout@v3
|
|
407
|
+
|
|
408
|
+
- uses: aws-actions/configure-aws-credentials@v2
|
|
409
|
+
with:
|
|
410
|
+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
411
|
+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
412
|
+
aws-region: ${{ env.AWS_REGION }}
|
|
413
|
+
|
|
414
|
+
- name: Login to ECR
|
|
415
|
+
id: login-ecr
|
|
416
|
+
uses: aws-actions/amazon-ecr-login@v1
|
|
417
|
+
|
|
418
|
+
- name: Build and push image
|
|
419
|
+
id: build-image
|
|
420
|
+
env:
|
|
421
|
+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
|
|
422
|
+
IMAGE_TAG: ${{ github.sha }}
|
|
423
|
+
run: |
|
|
424
|
+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
|
|
425
|
+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
|
426
|
+
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
|
|
427
|
+
|
|
428
|
+
- name: Update task definition
|
|
429
|
+
id: task-def
|
|
430
|
+
uses: aws-actions/amazon-ecs-render-task-definition@v1
|
|
431
|
+
with:
|
|
432
|
+
task-definition: task-definition.json
|
|
433
|
+
container-name: ${{ env.CONTAINER_NAME }}
|
|
434
|
+
image: ${{ steps.build-image.outputs.image }}
|
|
435
|
+
|
|
436
|
+
- name: Deploy to ECS
|
|
437
|
+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
|
|
438
|
+
with:
|
|
439
|
+
task-definition: ${{ steps.task-def.outputs.task-definition }}
|
|
440
|
+
service: ${{ env.ECS_SERVICE }}
|
|
441
|
+
cluster: ${{ env.ECS_CLUSTER }}
|
|
442
|
+
wait-for-service-stability: true
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
## Monitoring & Logging
|
|
446
|
+
|
|
447
|
+
### CloudWatch Container Insights
|
|
448
|
+
|
|
449
|
+
```bash
|
|
450
|
+
# Enable Container Insights
|
|
451
|
+
aws ecs update-cluster-settings \
|
|
452
|
+
--cluster my-cluster \
|
|
453
|
+
--settings name=containerInsights,value=enabled
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
### Custom Metrics with FireLens
|
|
457
|
+
|
|
458
|
+
```json
|
|
459
|
+
{
|
|
460
|
+
"containerDefinitions": [
|
|
461
|
+
{
|
|
462
|
+
"name": "log_router",
|
|
463
|
+
"image": "amazon/aws-for-fluent-bit:latest",
|
|
464
|
+
"firelensConfiguration": {
|
|
465
|
+
"type": "fluentbit"
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
"name": "app",
|
|
470
|
+
"logConfiguration": {
|
|
471
|
+
"logDriver": "awsfirelens",
|
|
472
|
+
"options": {
|
|
473
|
+
"Name": "cloudwatch",
|
|
474
|
+
"region": "us-east-1",
|
|
475
|
+
"log_group_name": "/ecs/my-app",
|
|
476
|
+
"auto_create_group": "true"
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
]
|
|
481
|
+
}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
## Best Practices
|
|
485
|
+
|
|
486
|
+
1. **Use Private Subnets**: Run tasks in private subnets with NAT Gateway
|
|
487
|
+
2. **Least Privilege IAM**: Separate execution and task roles
|
|
488
|
+
3. **Resource Limits**: Set appropriate CPU/memory reservations
|
|
489
|
+
4. **Health Checks**: Configure ALB health checks
|
|
490
|
+
5. **Auto-scaling**: Set up target tracking policies
|
|
491
|
+
6. **Secrets Management**: Use Secrets Manager, not environment variables
|
|
492
|
+
7. **Logging**: Use CloudWatch Logs or FireLens
|
|
493
|
+
8. **Tagging**: Tag all resources for cost tracking
|
|
494
|
+
9. **Blue/Green Deployments**: Use CodeDeploy for zero-downtime
|
|
495
|
+
10. **Cost Optimization**: Use Fargate Spot for non-critical workloads
|
|
496
|
+
|
|
497
|
+
## Fargate Spot
|
|
498
|
+
|
|
499
|
+
```json
|
|
500
|
+
{
|
|
501
|
+
"capacityProviderStrategy": [
|
|
502
|
+
{
|
|
503
|
+
"capacityProvider": "FARGATE_SPOT",
|
|
504
|
+
"weight": 4,
|
|
505
|
+
"base": 0
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
"capacityProvider": "FARGATE",
|
|
509
|
+
"weight": 1,
|
|
510
|
+
"base": 2
|
|
511
|
+
}
|
|
512
|
+
]
|
|
513
|
+
}
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
## Troubleshooting
|
|
517
|
+
|
|
518
|
+
### Tasks Won't Start
|
|
519
|
+
|
|
520
|
+
```bash
|
|
521
|
+
# Check service events
|
|
522
|
+
aws ecs describe-services \
|
|
523
|
+
--cluster my-cluster \
|
|
524
|
+
--services my-app \
|
|
525
|
+
| jq '.services[0].events[:5]'
|
|
526
|
+
|
|
527
|
+
# Check task status
|
|
528
|
+
aws ecs list-tasks --cluster my-cluster --service-name my-app
|
|
529
|
+
aws ecs describe-tasks --cluster my-cluster --tasks TASK_ARN
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
### Common Issues
|
|
533
|
+
|
|
534
|
+
**CannotPullContainerError**
|
|
535
|
+
- Check ECR permissions in execution role
|
|
536
|
+
- Verify image exists and tag is correct
|
|
537
|
+
|
|
538
|
+
**Resource Initialization Error**
|
|
539
|
+
- Check VPC configuration (subnets, security groups)
|
|
540
|
+
- Ensure NAT Gateway or VPC endpoints for private subnets
|
|
541
|
+
|
|
542
|
+
**Health Check Failures**
|
|
543
|
+
- Verify target group health check path
|
|
544
|
+
- Check security group allows ALB → task traffic
|
|
545
|
+
- Ensure app responds on correct port
|
|
546
|
+
|
|
547
|
+
## Cost Optimization
|
|
548
|
+
|
|
549
|
+
```bash
|
|
550
|
+
# Use Fargate Spot (up to 70% savings)
|
|
551
|
+
# Right-size CPU/memory
|
|
552
|
+
# Use auto-scaling to minimize idle capacity
|
|
553
|
+
# Consider EC2 launch type for predictable, always-on workloads
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
## References
|
|
557
|
+
|
|
558
|
+
- [AWS ECS Documentation](https://docs.aws.amazon.com/ecs/)
|
|
559
|
+
- [Fargate Documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html)
|
|
560
|
+
- [Task Definition Parameters](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html)
|
|
561
|
+
- [ECS Best Practices](https://docs.aws.amazon.com/AmazonECS/latest/bestpracticesguide/)
|