-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
1314 lines (1146 loc) · 50.2 KB
/
Copy pathTaskfile.yml
File metadata and controls
1314 lines (1146 loc) · 50.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# https://taskfile.dev
version: '3'
dotenv: ['.env']
set: [pipefail]
includes:
internal:
taskfile: ./Taskfile.internal.yml
optional: true
vars:
# Environment selection and validation happen in scripts/utils/with-env.sh
# against the resolved $ENVIRONMENT (the shell value), never the Task
# {{.ENVIRONMENT}} template — which goes stale under a per-command
# `ENVIRONMENT=<env> task …` override.
# AWS identity (AWS_PROFILE, AWS_ACCOUNT_ID) comes from .env, resolved and
# account-guarded by scripts/utils/with-env.sh, which mutating tasks `source`
# at the top of their command block. When AWS_ACCOUNT_ID is set, every deploy
# asserts the live account matches before running; leave it unset to skip the
# guard.
tasks:
# ════════════════════════════════════════════════════════════════
# Full lifecycle
# ════════════════════════════════════════════════════════════════
deploy:
desc: Full deployment (backend + frontend + Cognito callback fixup)
aliases: [d]
cmds:
- task: deploy:backend
- task: deploy:frontend
# Second deploy:infra pass feeds the CloudFront URL back into Cognito
# callback URLs. This intentionally re-runs deploy:infra (run: always).
- task: deploy:infra
- |
export TF_DATA_DIR=".terraform/${ENVIRONMENT}"
FRONTEND_URL=$(terraform -chdir=terraform output -raw frontend_url 2>/dev/null || true)
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✓ Full deployment complete"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "Next steps:"
echo " task deploy:user Create a sign-in user (interactive)"
if [ -n "$FRONTEND_URL" ]; then
echo " Log in: ${FRONTEND_URL}"
else
echo " task dev Run the SPA locally at http://localhost:5173"
fi
echo ""
echo " task status (optional) endpoints + deployment status"
deploy:backend:
desc: Deploy backend infrastructure, agents, memory, KBs, and seed data
# Env validation is owned by with-env.sh (sourced by the mutating subtasks
# below — tf-bootstrap, deploy:infra). A bad ENVIRONMENT fails loudly there.
cmds:
- task: check:prereqs
- task: check:aws
- task: deploy:tf-bootstrap
vars:
NON_INTERACTIVE: "true"
- task: deploy:memory
- task: deploy:knowledge-bases
- task: deploy:agents
- task: build:layers
- task: deploy:infra
- task: deploy:agent-permissions
- task: deploy:seed
- |
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✓ Backend deployed"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
destroy:
desc: Full teardown (removes all AWS resources)
# Env validation is owned by with-env.sh (sourced by destroy:infra:run). A
# bad ENVIRONMENT fails loudly there before anything is destroyed.
prompt: ⚠️ This will DELETE all infrastructure, agents, and data. Continue?
cmds:
- task: check:aws
# Call internal :run tasks directly to skip sub-task prompts.
# The parent prompt above is the single confirmation gate.
- task: destroy:infra:run
- task: destroy:logs:run
- task: destroy:knowledge-bases:run
- task: destroy:memory:run
- task: destroy:agents:run
- task: destroy:ssm:run
- |
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✓ Full teardown complete"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "Destroyed: infrastructure, knowledge bases, memory, agents, SSM parameters, logs"
echo "Preserved: Terraform backend (S3 state bucket, DynamoDB lock table)"
echo ""
echo "To redeploy: task deploy"
# ════════════════════════════════════════════════════════════════
# Checks
# ════════════════════════════════════════════════════════════════
check:prereqs:
desc: Validate all prerequisites are installed
run: once
silent: true
cmds:
- |
echo "Checking prerequisites..."
echo ""
MISSING=0
# Python
if command -v python3 &>/dev/null; then
echo "✓ Python $(python3 --version 2>&1 | awk '{print $2}')"
else
echo "✗ Python 3.13+ — https://www.python.org/downloads/"
MISSING=1
fi
# uv
if command -v uv &>/dev/null; then
echo "✓ uv $(uv --version 2>&1 | awk '{print $2}')"
else
echo "✗ uv — https://docs.astral.sh/uv/getting-started/installation/"
MISSING=1
fi
# AgentCore CLI
if command -v agentcore &>/dev/null; then
echo "✓ agentcore CLI"
else
echo "✗ agentcore CLI — uv tool install bedrock-agentcore-starter-toolkit"
MISSING=1
fi
# Terraform
if command -v terraform &>/dev/null; then
echo "✓ Terraform $(terraform version -json 2>/dev/null | python3 -c 'import sys,json; print(json.load(sys.stdin)["terraform_version"])' 2>/dev/null || echo '(version unknown)')"
else
echo "✗ Terraform 1.5+ — https://developer.hashicorp.com/terraform/install"
MISSING=1
fi
# AWS CLI
if command -v aws &>/dev/null; then
echo "✓ AWS CLI $(aws --version 2>&1 | awk '{print $1}' | cut -d/ -f2)"
else
echo "✗ AWS CLI — https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html"
MISSING=1
fi
# Node.js
if command -v node &>/dev/null; then
echo "✓ Node.js $(node --version)"
else
echo "✗ Node.js 18+ — https://nodejs.org/"
MISSING=1
fi
echo ""
if [ "$MISSING" -eq 1 ]; then
echo "❌ Some prerequisites are missing. Install them and try again."
exit 1
fi
echo "All prerequisites installed ✓"
check:aws:
desc: Validate AWS credentials are configured
run: once
silent: true
cmds:
- |
echo "Checking AWS credentials..."
if ! aws sts get-caller-identity --region {{.AWS_REGION}} &>/dev/null; then
echo ""
echo "❌ AWS credentials not configured or expired."
echo ""
echo "Configure credentials using one of:"
echo " • AWS SSO: aws sso login --profile <profile>"
echo " • AWS Profile: export AWS_PROFILE=<profile>"
echo " • Isengard CLI: isengardcli add-profile --profile <profile>"
echo " • Environment: export AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=..."
echo " • aws configure: aws configure"
echo ""
echo "Then re-run: task deploy"
exit 1
fi
ACCOUNT=$(aws sts get-caller-identity --region {{.AWS_REGION}} --query 'Account' --output text)
ARN=$(aws sts get-caller-identity --region {{.AWS_REGION}} --query 'Arn' --output text)
echo "✓ AWS credentials valid"
echo " Region: {{.AWS_REGION}}"
echo " Account: ${ACCOUNT}"
echo " Role: ${ARN}"
check:env:
desc: Validate .env file exists and required variables are set
# Internal: only ever run as a dep of deploy/destroy tasks, never invoked
# directly (unlike check:prereqs / check:aws, which SETUP.md documents).
internal: true
run: once
silent: true
cmds:
- |
if [ ! -f .env ]; then
echo "❌ No .env file found"
echo ""
echo "Create one from the example:"
echo " cp .env.example .env"
echo ""
echo "Then edit it with your settings."
exit 1
fi
MISSING=0
for VAR in AWS_REGION ENVIRONMENT PROJECT_NAME PLANNER_MODEL_ID JUDGE_MODEL_ID IMAGE_ANALYSIS_MODEL_ID; do
if [ -z "${!VAR}" ]; then
echo "❌ ${VAR} is not set in .env"
MISSING=1
fi
done
if [ "$MISSING" -eq 1 ]; then
echo ""
echo "Add missing variables to .env (see .env.example)"
exit 1
fi
echo "✓ .env file valid"
# ════════════════════════════════════════════════════════════════
# Deploy targets
# ════════════════════════════════════════════════════════════════
deploy:tf-bootstrap:
desc: Create Terraform remote backend (S3 + DynamoDB + KMS) in the current account
deps: [check:env, check:aws]
silent: true
cmds:
- |
# with-env.sh resolves $ENVIRONMENT and — when AWS_ACCOUNT_ID is set —
# asserts the live account matches before we create any backend
# resources.
source scripts/utils/with-env.sh
ACCOUNT=$(aws sts get-caller-identity --region "${AWS_REGION}" --query 'Account' --output text)
# Optional interactive confirmation for shared accounts. The account
# *equality* check is owned by with-env.sh (above); this prompt only
# adds a human gate before mutating a shared account's backend.
SHARED_ACCOUNT="${SHARED_ACCOUNT:-no}"
if [ "$SHARED_ACCOUNT" = "yes" ]; then
echo "⚠️ This is a shared account ($ACCOUNT) for environment '${ENVIRONMENT}'"
echo " Creating backend resources: S3 bucket, DynamoDB table, KMS key"
if [ "{{.NON_INTERACTIVE}}" = "true" ]; then
echo " (auto-confirmed — running as part of full deploy pipeline)"
else
read -p " Continue? [y/N] " CONFIRM
if [ "$CONFIRM" != "y" ] && [ "$CONFIRM" != "Y" ]; then
echo "Aborted."
exit 1
fi
fi
fi
echo ""
echo "Creating Terraform backend in account ${ACCOUNT} (${ENVIRONMENT})..."
echo ""
# Run the setup script — it's idempotent (skips existing resources)
bash scripts/utils/setup-terraform-backend.sh
deploy:memory:
desc: Deploy shared semantic memory resource
deps: [check:env]
cmds:
- |
source scripts/utils/with-env.sh
bash scripts/deploy_shared_memory.sh
deploy:knowledge-bases:
desc: Deploy Document Index and Standards Knowledge Bases
deps: [check:env]
cmds:
- |
source scripts/utils/with-env.sh
set -e
bash scripts/deploy_document_kb.sh
bash scripts/deploy_standards_kb.sh
deploy:agents:
desc: Deploy all agents (review + chat) to AgentCore
deps: [check:env]
cmds:
- |
source scripts/utils/with-env.sh
set -e
# Re-point the .bedrock_agentcore.yaml symlink at the resolved env before
# the CLI runs, so configure/deploy write through to the right canonical
# per-env file, derived per-invocation from $ENVIRONMENT.
bash scripts/agentcore_config.sh link
bash scripts/deploy_agent.sh all
bash scripts/agentcore_config.sh backup
deploy:agent:
desc: "Deploy agent(s) (usage: task deploy:agent -- <name|review|chat|all>)"
deps: [check:env]
cmds:
- |
source scripts/utils/with-env.sh
set -e
# Re-point the symlink at the resolved env before the CLI runs (see
# deploy:agents).
bash scripts/agentcore_config.sh link
bash scripts/deploy_agent.sh {{.CLI_ARGS}}
bash scripts/agentcore_config.sh backup
deploy:agent-permissions:
desc: Grant agent execution roles required IAM permissions (registry + memory)
deps: [check:env]
cmds:
- |
source scripts/utils/with-env.sh
bash scripts/grant_agent_permissions.sh
deploy:seed:
desc: Seed agent registry in DynamoDB
deps: [check:env]
cmds:
- |
source scripts/utils/with-env.sh
bash scripts/seed_agent_registry.sh
deploy:infra:
desc: Deploy infrastructure via Terraform
deps: [check:env, build:api-docs]
dir: terraform
cmds:
# One command block so the sourced env guard's exports reach both the
# init and apply that follow. Path is ../ because dir: terraform.
- |
source ../scripts/utils/with-env.sh
# Per-environment Terraform data dir: each env re-inits in isolation
# (provider cache + backend pointer) instead of sharing one .terraform/
# that a forgotten switch could leave pointed at the wrong account.
# Remote state lives in S3, so this is re-init only — no state moves.
# Relative to terraform/ because dir: terraform.
export TF_DATA_DIR=".terraform/${ENVIRONMENT}"
terraform init -upgrade -reconfigure -backend-config="backends/${ENVIRONMENT}.hcl"
# Auto-populate cloudfront_url from prior deploy if available.
# This breaks the Cognito ↔ CloudFront dependency cycle: the first
# deploy creates the distribution, subsequent deploys feed its URL
# back into Cognito callback URLs and CORS origins.
#
# Terraform -raw prints a "No outputs found" warning to stdout (not
# stderr) on empty state and exits 0 — a known bug (hashicorp/terraform
# #32384). Piping through grep ensures CF_URL is only set when the
# output is an actual URL. On first deploy this is empty (no prior
# CloudFront distribution), which is fine.
CF_URL=$(terraform output -raw frontend_url 2>/dev/null | grep -E '^https://' || true)
CF_VAR=""
if [ -n "$CF_URL" ]; then
CF_VAR="-var=cloudfront_url=${CF_URL}"
fi
terraform apply \
-var-file="environments/${ENVIRONMENT}.tfvars" \
-var="planner_model_id={{.PLANNER_MODEL_ID}}" \
-var="judge_model_id={{.JUDGE_MODEL_ID}}" \
-var="image_analysis_model_id={{.IMAGE_ANALYSIS_MODEL_ID}}" \
${CF_VAR} \
-auto-approve
deploy:frontend:
desc: Build and deploy the frontend to S3 + invalidate CloudFront
deps: [check:aws, build:frontend]
cmds:
- |
source scripts/utils/with-env.sh
export TF_DATA_DIR=".terraform/${ENVIRONMENT}"
BUCKET=$(terraform -chdir=terraform output -raw edge_bucket_name 2>/dev/null)
DIST_ID=$(terraform -chdir=terraform output -raw edge_distribution_id 2>/dev/null)
if [ -z "$BUCKET" ] || [ -z "$DIST_ID" ]; then
echo "❌ Could not read edge module outputs."
echo " Set deploy_frontend = true in your tfvars and run:"
echo " ENVIRONMENT=${ENVIRONMENT} task deploy:infra"
exit 1
fi
echo "Syncing frontend/dist/ → s3://${BUCKET}"
aws s3 sync frontend/dist/ "s3://${BUCKET}" --delete --region {{.AWS_REGION}}
# Overwrite config.json with the Terraform-generated version.
# The build step snapshots public/config.json into dist/ at build time,
# which may be stale. This ensures the deployed config always matches
# the latest Terraform output (relative URLs when API proxy is enabled,
# direct URLs otherwise).
echo "Overwriting config.json with Terraform-generated config"
aws s3 cp frontend/public/config.json "s3://${BUCKET}/config.json" --region {{.AWS_REGION}}
# Only index.html and config.json need invalidation — content-hashed
# assets are served by new filenames and both are CachingDisabled in
# CloudFront (belt-and-braces so deploys are always fresh).
echo "Invalidating /index.html and /config.json on ${DIST_ID}"
aws cloudfront create-invalidation \
--distribution-id "${DIST_ID}" \
--paths "/index.html" "/config.json" \
--output text > /dev/null
URL=$(terraform -chdir=terraform output -raw frontend_url 2>/dev/null)
echo "✓ Frontend deployed: ${URL}"
deploy:user:
desc: Create a Cognito user with permanent password and group assignment
interactive: true
dir: terraform
silent: true
cmds:
- |
source ../scripts/utils/with-env.sh
export TF_DATA_DIR=".terraform/${ENVIRONMENT}"
USER_POOL_ID=$(terraform output -raw cognito_user_pool_id 2>/dev/null || true)
if [ -z "$USER_POOL_ID" ]; then
echo "❌ Could not read Cognito User Pool ID. Run 'task deploy:infra' first."
exit 1
fi
REGION="{{.AWS_REGION}}"
echo "Creating Cognito user..."
echo "Environment: ${ENVIRONMENT}"
echo "User Pool: ${USER_POOL_ID}"
echo ""
# ── Email ──
read -p "Email address: " EMAIL
if [ -z "$EMAIL" ]; then
echo "❌ Email is required"
exit 1
fi
# ── Password ──
# Generate a random default: 12 chars, mixed case + digits + symbol.
# Uses a finite read (256 bytes) to avoid SIGPIPE with pipefail enabled.
RAW="$(head -c 256 /dev/urandom | LC_ALL=C tr -dc 'A-Za-z0-9!@#%')"
DEFAULT_PW="${RAW:0:12}!"
echo ""
echo "Enter a password or press Enter to use a generated one."
echo " Requirements: 8+ chars, uppercase, lowercase, number, symbol"
read -p "Password [${DEFAULT_PW}]: " PASSWORD
PASSWORD="${PASSWORD:-${DEFAULT_PW}}"
# ── Group ──
echo ""
echo "Fetching groups from Cognito..."
GROUPS_JSON=$(aws cognito-idp list-groups \
--user-pool-id "${USER_POOL_ID}" \
--region "${REGION}" \
--query 'Groups[].{name:GroupName,desc:Description}' \
--output json 2>/dev/null)
GROUP_COUNT=$(echo "${GROUPS_JSON}" | python3 -c "import sys,json; print(len(json.load(sys.stdin)))")
if [ "${GROUP_COUNT}" -gt 0 ]; then
echo ""
echo "Select group:"
# Build the menu and find the default index
DEFAULT_IDX=1
for i in $(seq 0 $((GROUP_COUNT - 1))); do
NAME=$(echo "${GROUPS_JSON}" | python3 -c "import sys,json; print(json.load(sys.stdin)[${i}]['name'])")
DESC=$(echo "${GROUPS_JSON}" | python3 -c "import sys,json; print(json.load(sys.stdin)[${i}].get('desc','') or '')")
NUM=$((i + 1))
if [ -n "${DESC}" ]; then
echo " ${NUM}) ${NAME} — ${DESC}"
else
echo " ${NUM}) ${NAME}"
fi
# Default to the "users" group (not admins, not viewers)
if echo "${NAME}" | grep -q "users"; then
DEFAULT_IDX=${NUM}
fi
done
echo ""
read -p "Group [${DEFAULT_IDX}]: " GROUP_CHOICE
GROUP_CHOICE="${GROUP_CHOICE:-${DEFAULT_IDX}}"
# Validate selection
if ! echo "${GROUP_CHOICE}" | grep -qE '^[0-9]+$' || [ "${GROUP_CHOICE}" -lt 1 ] || [ "${GROUP_CHOICE}" -gt "${GROUP_COUNT}" ]; then
echo "❌ Invalid selection: ${GROUP_CHOICE}"
exit 1
fi
GROUP_NAME=$(echo "${GROUPS_JSON}" | python3 -c "import sys,json; print(json.load(sys.stdin)[$((GROUP_CHOICE - 1))]['name'])")
fi
# ── Create user ──
echo ""
echo "Creating user..."
aws cognito-idp admin-create-user \
--user-pool-id "${USER_POOL_ID}" \
--username "${EMAIL}" \
--user-attributes Name=email,Value="${EMAIL}" Name=email_verified,Value=true \
--message-action SUPPRESS \
--temporary-password 'TempBootstrap1!' \
--region "${REGION}" > /dev/null
# Set permanent password (skips forced change on first login)
aws cognito-idp admin-set-user-password \
--user-pool-id "${USER_POOL_ID}" \
--username "${EMAIL}" \
--password "${PASSWORD}" \
--permanent \
--region "${REGION}"
# Assign to group
if [ -n "${GROUP_NAME}" ]; then
aws cognito-idp admin-add-user-to-group \
--user-pool-id "${USER_POOL_ID}" \
--username "${EMAIL}" \
--group-name "${GROUP_NAME}" \
--region "${REGION}"
fi
# ── Summary ──
echo ""
echo "✓ User created successfully"
echo " Email: ${EMAIL}"
echo " Password: ${PASSWORD}"
if [ -n "${GROUP_NAME}" ]; then
echo " Group: ${GROUP_NAME}"
else
echo " Group: (none — no groups found in pool)"
fi
echo ""
echo " The user can sign in immediately — no password change required."
# ════════════════════════════════════════════════════════════════
# Build targets
# ════════════════════════════════════════════════════════════════
build:layers:
desc: Build Lambda layers (dependencies + core)
deps: [build:dependencies-layer, build:core-layer, build:load-document]
build:dependencies-layer:
desc: Build dependencies Lambda layer (boto3, python-jose)
cmds:
- bash scripts/build_dependencies_layer.sh
sources:
- scripts/build_dependencies_layer.sh
- pyproject.toml
- uv.lock
generates:
- .build/dependencies_layer/python/**/*
build:core-layer:
desc: Build core Lambda layer (shared application code)
cmds:
- bash scripts/build_core_layer.sh
sources:
- scripts/build_core_layer.sh
- api/core/**/*.py
generates:
- .build/core_layer/python/**/*
build:load-document:
desc: Build load_document Lambda package
cmds:
- bash scripts/build_load_document.sh
sources:
- scripts/build_load_document.sh
- api/workflow/load_document.py
- pyproject.toml
- uv.lock
generates:
- .build/load_document/**/*
build:api-docs:
desc: Generate API reference docs from OpenAPI spec
cmds:
- python3 scripts/generate_api_docs.py
sources:
- api/openapi.yaml
- scripts/generate_api_docs.py
generates:
- frontend/src/docs/api-reference.md
build:frontend:
desc: Build the frontend SPA for production (outputs to frontend/dist)
dir: frontend
deps: [frontend:config]
cmds:
- npm ci
- npm run build
sources:
- src/**/*
- package.json
- package-lock.json
- vite.config.js
generates:
- dist/**/*
frontend:config:
desc: Regenerate frontend/public/config.json from Terraform outputs for the resolved env
silent: true
cmds:
- |
source scripts/utils/with-env.sh
export TF_DATA_DIR=".terraform/${ENVIRONMENT}"
# config.json is the canonical Terraform output frontend_config_json.
# When the output is absent (env not yet deployed), leave any existing
# config.json untouched so a UI-only `task dev` is not blocked.
CONFIG=$(terraform -chdir=terraform output -raw frontend_config_json 2>/dev/null || true)
if [ -z "$CONFIG" ]; then
echo "⚠️ No Terraform output for '${ENVIRONMENT}' — config.json left unchanged."
echo " Run 'task deploy:infra' if the app needs a backend."
exit 0
fi
printf '%s\n' "$CONFIG" > frontend/public/config.json
echo "✓ frontend/public/config.json regenerated for ${ENVIRONMENT}"
# ════════════════════════════════════════════════════════════════
# Destroy targets
# ════════════════════════════════════════════════════════════════
destroy:infra:
desc: Destroy Terraform-managed infrastructure
prompt: This will delete all AWS infrastructure (API Gateway, Lambda, DynamoDB, Cognito, etc). Continue?
cmds:
- task: destroy:infra:run
destroy:infra:run:
internal: true
silent: true
dir: terraform
cmds:
# One command block so the sourced env guard's exports reach both the
# init and destroy that follow. Path is ../ because dir: terraform.
- |
source ../scripts/utils/with-env.sh
# Per-environment Terraform data dir (see deploy:infra). Re-init only;
# remote state lives in S3. Relative to terraform/ because dir: terraform.
export TF_DATA_DIR=".terraform/${ENVIRONMENT}"
terraform init -reconfigure -backend-config="backends/${ENVIRONMENT}.hcl"
# See deploy:infra for why grep is needed here (terraform #32384).
CF_URL=$(terraform output -raw frontend_url 2>/dev/null | grep -E '^https://' || true)
CF_VAR=""
if [ -n "$CF_URL" ]; then
CF_VAR="-var=cloudfront_url=${CF_URL}"
fi
terraform destroy \
-var-file="environments/${ENVIRONMENT}.tfvars" \
-var="planner_model_id={{.PLANNER_MODEL_ID}}" \
-var="judge_model_id={{.JUDGE_MODEL_ID}}" \
-var="image_analysis_model_id={{.IMAGE_ANALYSIS_MODEL_ID}}" \
${CF_VAR} \
-auto-approve
destroy:knowledge-bases:
desc: Delete Knowledge Bases, vector stores, and associated IAM roles
prompt: This will delete all Knowledge Bases and their vector indexes. Continue?
cmds:
- task: destroy:knowledge-bases:run
destroy:knowledge-bases:run:
internal: true
silent: true
deps: [check:env]
cmds:
- |
source scripts/utils/with-env.sh
bash scripts/destroy_knowledge_bases.sh
destroy:agents:
desc: Delete all AgentCore agents
prompt: This will delete all deployed agents from AgentCore. Continue?
cmds:
- task: destroy:agents:run
destroy:agents:run:
internal: true
silent: true
cmds:
- |
source scripts/utils/with-env.sh
# Re-point at the resolved env so we list/destroy the right env's agents.
bash scripts/agentcore_config.sh link
echo "Deleting AgentCore agents..."
# Read agent names from .bedrock_agentcore.yaml via agentcore configure list
AGENTS=$(agentcore configure list 2>/dev/null | grep '✅' | awk '{print $2}' || true)
if [ -z "$AGENTS" ]; then
echo "No agents found in .bedrock_agentcore.yaml"
exit 0
fi
echo "Found agents:"
echo "$AGENTS"
echo ""
for AGENT_NAME in $AGENTS; do
echo "Deleting ${AGENT_NAME}..."
# `agentcore destroy` also deletes the agent's bound chat memory, so
# this is the single owner of per-agent memory cleanup (destroy:memory
# only handles the standalone shared semantic memory).
agentcore destroy --agent "${AGENT_NAME}" --force 2>&1 || \
echo " ⚠️ Could not fully delete ${AGENT_NAME} (may need manual cleanup)"
done
echo ""
echo "✓ Agent cleanup complete"
# The deployed agents are gone, so remove the local config that tracked
# them; the next deploy recreates it. .bedrock_agentcore.yaml is a symlink
# to the canonical .bedrock_agentcore.yaml.<env>: delete both the target
# and the link so the canonical file is not orphaned behind a dangling link.
if [ -L .bedrock_agentcore.yaml ]; then
TARGET=$(readlink .bedrock_agentcore.yaml)
rm -f "$TARGET" .bedrock_agentcore.yaml
echo "✓ Removed .bedrock_agentcore.yaml and ${TARGET}"
elif [ -f .bedrock_agentcore.yaml ]; then
# Fallback when it is a regular file rather than a symlink.
rm -f .bedrock_agentcore.yaml
echo "✓ Removed .bedrock_agentcore.yaml"
fi
destroy:memory:
desc: Delete the shared semantic memory for this project
# Per-agent chat memories are owned by their agent runtime and are removed
# by `agentcore destroy` (destroy:agents) — not here.
prompt: This will delete the shared semantic memory. Continue?
cmds:
- task: destroy:memory:run
destroy:memory:run:
internal: true
silent: true
cmds:
- |
source scripts/utils/with-env.sh
echo "Cleaning up shared memory..."
echo ""
# This task owns ONLY the shared semantic memory. Per-agent chat
# memories are bound to their agent runtime and are deleted by
# `agentcore destroy` in destroy:agents — deleting them here too caused
# a double-delete (the agentcore CLI then logged ResourceNotFound on the
# already-gone memory). No yaml read / agentcore_config link needed here.
DELETED=0
# ── Helper: delete a single memory and wait for completion ──
delete_and_wait() {
local memory_id="$1"
local label="$2"
echo "Deleting ${label} (${memory_id})..."
local err
if ! err=$(aws bedrock-agentcore-control delete-memory \
--memory-id "$memory_id" \
--client-token "delete-${memory_id}-$(date +%s)" \
--region {{.AWS_REGION}} 2>&1); then
# A missing memory is already gone — treat as success (idempotent),
# not an error. Any other failure is real and propagates as a warning.
if printf '%s' "$err" | grep -q 'ResourceNotFoundException'; then
echo " ✓ Already deleted"
return 0
fi
echo " ⚠️ Could not initiate deletion of ${memory_id}: ${err}"
return 1
fi
# Wait for this memory to be fully deleted
local timeout=120
local elapsed=0
while [ $elapsed -lt $timeout ]; do
local remaining
remaining=$(aws bedrock-agentcore-control list-memories \
--region {{.AWS_REGION}} \
--query "memories[?id=='${memory_id}'].id | [0]" \
--output text 2>/dev/null)
if [ -z "$remaining" ] || [ "$remaining" = "None" ]; then
echo " ✓ Deleted"
DELETED=$((DELETED + 1))
return 0
fi
sleep 5
elapsed=$((elapsed + 5))
done
echo " ❌ Timeout waiting for ${memory_id}"
return 1
}
# ── Shared memory (by project naming convention) ──
MEMORY_PREFIX="risk_assessor_shared_memory_${ENVIRONMENT}"
SHARED_ID=$(aws bedrock-agentcore-control list-memories \
--region {{.AWS_REGION}} \
--query "memories[?starts_with(id, '${MEMORY_PREFIX}')].id | [0]" \
--output text 2>/dev/null)
if [ -n "$SHARED_ID" ] && [ "$SHARED_ID" != "None" ]; then
delete_and_wait "$SHARED_ID" "shared memory"
else
echo "No shared memory found matching '${MEMORY_PREFIX}'"
fi
echo ""
if [ $DELETED -gt 0 ]; then
echo "✓ ${DELETED} memory resource(s) deleted"
else
echo "Nothing to delete"
fi
destroy:ssm:
desc: Clean up SSM parameters
prompt: This will delete all SSM parameters under /{{.PROJECT_NAME}}/<resolved-env>/. Continue?
cmds:
- task: destroy:ssm:run
destroy:ssm:run:
internal: true
silent: true
cmds:
- |
source scripts/utils/with-env.sh
PREFIX="/{{.PROJECT_NAME}}/${ENVIRONMENT}"
echo "Cleaning up SSM parameters under ${PREFIX}..."
PARAMS=$(aws ssm get-parameters-by-path \
--path "${PREFIX}" \
--recursive \
--query 'Parameters[].Name' \
--output text \
--region {{.AWS_REGION}} 2>/dev/null || true)
if [ -z "$PARAMS" ]; then
echo "No SSM parameters found under ${PREFIX}"
exit 0
fi
for PARAM in $PARAMS; do
echo " Deleting ${PARAM}..."
aws ssm delete-parameter --name "${PARAM}" --region {{.AWS_REGION}} 2>/dev/null || true
done
echo "✓ SSM parameters cleaned up"
destroy:logs:
desc: Delete CloudWatch log groups created by project Lambdas and API Gateway
prompt: This will delete all CloudWatch log groups matching '{{.PROJECT_NAME}}'. Continue?
cmds:
- task: destroy:logs:run
destroy:logs:run:
internal: true
silent: true
cmds:
- |
source scripts/utils/with-env.sh
echo "Cleaning up CloudWatch log groups..."
LOG_GROUPS=$(aws logs describe-log-groups \
--log-group-name-prefix "/aws/" \
--query "logGroups[?contains(logGroupName, '{{.PROJECT_NAME}}')].logGroupName" \
--output text \
--region {{.AWS_REGION}} 2>/dev/null | tr '\t' '\n' || true)
if [ -z "$LOG_GROUPS" ]; then
echo "No log groups found matching '{{.PROJECT_NAME}}'"
exit 0
fi
DELETED=0
for LG in $LOG_GROUPS; do
echo " Deleting ${LG}..."
aws logs delete-log-group --log-group-name "$LG" --region {{.AWS_REGION}} 2>/dev/null || {
echo " ⚠️ Could not delete ${LG}"
continue
}
DELETED=$((DELETED + 1))
done
echo "✓ ${DELETED} log group(s) deleted"
# ════════════════════════════════════════════════════════════════
# Environment
#
# task env Show the resolved environment + account.
# ENVIRONMENT=<env> task <name> Target a specific environment per-command.
#
# ENVIRONMENT is read from .env (the default target) and can be overridden
# per-command. AWS identity (AWS_PROFILE, AWS_ACCOUNT_ID) comes from .env and
# is resolved + account-guarded by with-env.sh. There is no persisted
# "current environment" mode.
# ════════════════════════════════════════════════════════════════
env:
desc: Show current environment, profile, and AWS account
silent: true
cmds:
- |
# Resolve + guard via the single source of truth, then report the
# values the helper actually resolved — never the {{.ENVIRONMENT}} /
# {{.AWS_PROFILE}} templates, which go stale under a per-command override.
source scripts/utils/with-env.sh
BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
DISPLAY_PROFILE="${AWS_PROFILE:-[default]}"
ACCOUNT=$(aws sts get-caller-identity --region {{.AWS_REGION}} \
--query 'Account' --output text 2>/dev/null || echo "credentials expired")
echo ""
echo " Environment: ${ENVIRONMENT}"
echo " AWS Profile: ${DISPLAY_PROFILE}"
echo " Git Branch: ${BRANCH}"
echo " Account: ${ACCOUNT}"
echo ""
# ════════════════════════════════════════════════════════════════
# AgentCore config management
# ════════════════════════════════════════════════════════════════
agentcore:backup:
desc: Back up .bedrock_agentcore.yaml to S3 and local timestamped copy
deps: [check:env, check:aws]
cmds:
- |
source scripts/utils/with-env.sh
set -e
# Re-point at the resolved env first so we back up the right config.
bash scripts/agentcore_config.sh link
bash scripts/agentcore_config.sh backup
agentcore:restore:
desc: "Restore .bedrock_agentcore.yaml from S3 (usage: task agentcore:restore [-- <env>])"
deps: [check:env, check:aws]
cmds:
- |
source scripts/utils/with-env.sh
set -e
# Re-point first so the restore writes through the symlink into the
# resolved env's canonical .bedrock_agentcore.yaml.<env> file.
bash scripts/agentcore_config.sh link
bash scripts/agentcore_config.sh restore {{.CLI_ARGS}}
agentcore:backups:
desc: List available AgentCore config backups (local + S3)
cmds:
- |
source scripts/utils/with-env.sh
bash scripts/agentcore_config.sh list
# ════════════════════════════════════════════════════════════════
# User management
# ════════════════════════════════════════════════════════════════
user:group:
desc: "Change a user's Cognito group (usage: task user:group -- <email> <group>)"
deps: [check:aws]
dir: terraform
silent: true
cmds:
- |
ARGS="{{.CLI_ARGS}}"
EMAIL=$(echo "$ARGS" | awk '{print $1}')
GROUP=$(echo "$ARGS" | awk '{print $2}')
if [ -z "$EMAIL" ] || [ -z "$GROUP" ]; then
echo "Usage: task user:group -- <email> <group>"
echo ""
echo "Available groups: admins, users, viewers"
exit 1
fi
source ../scripts/utils/with-env.sh
export TF_DATA_DIR=".terraform/${ENVIRONMENT}"
USER_POOL_ID=$(terraform output -raw cognito_user_pool_id 2>/dev/null || true)
if [ -z "$USER_POOL_ID" ]; then
echo "❌ Could not read Cognito User Pool ID. Run 'task deploy:infra' first."