Repository navigation
Expand file tree
/
Copy pathlocal_stack.just
More file actions
157 lines (150 loc) · 8.14 KB
/
Copy pathlocal_stack.just
File metadata and controls
157 lines (150 loc) · 8.14 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
# LocalStack recipes for local AWS emulation
export AWS_PAGER := ""
# Start LocalStack for local AWS emulation
# Pinned to v4 — `latest` requires LOCALSTACK_AUTH_TOKEN for all features.
start_localstack:
#!/usr/bin/env bash
set -euo pipefail
if docker ps --format '{{ "{{.Names}}" }}' | grep -qx localstack; then
echo "LocalStack already running"
elif docker ps -a --format '{{ "{{.Names}}" }}' | grep -qx localstack; then
docker start localstack >/dev/null
echo "LocalStack started"
else
docker run -d --name localstack \
--network databases \
-p 4566:4566 \
-e SERVICES=sqs,dynamodb,s3 \
localstack/localstack:4
echo "LocalStack started"
fi
docker network connect databases localstack 2>/dev/null || true
echo "Waiting for LocalStack to be ready..."
until curl -fsS http://localhost:4566/_localstack/health >/dev/null 2>&1; do sleep 1; done
echo "LocalStack ready"
# Create SQS queues in LocalStack
create_local_queues:
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name notification-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name notification-ingress-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name push-delivery-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name email-service-backfill-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name delete-chat-handler-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name contacts-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name convert-service-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name delete-document-handler-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name document-upload-finalizer-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name document-text-extractor-lambda-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name email-service-scheduled-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name email-service-gmail-inbox-sync-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name email-service-gmail-inbox-retry-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name email-service-gmail-ops-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name email-service-gmail-ops-retry-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name email-service-refresh-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name search-event-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name ai-projection-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name email-sfs-delete-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name email-service-sfs-mapper-queue || true
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name static-file-s3-event-notification-queue || true
@echo "SQS queues created"
# Purge all messages from every SQS queue in LocalStack
purge_queues:
#!/usr/bin/env bash
set -euo pipefail
queues=$(aws --endpoint-url=http://localhost:4566 sqs list-queues --query 'QueueUrls[]' --output text)
# `--output text` emits the literal "None" (not empty) when there are no queues.
if [ -z "$queues" ] || [ "$queues" = "None" ]; then
echo "No SQS queues found"
exit 0
fi
for queue_url in $queues; do
if aws --endpoint-url=http://localhost:4566 sqs purge-queue --queue-url "$queue_url"; then
echo "Purged $queue_url"
else
echo "Failed to purge $queue_url" >&2
fi
done
echo "All SQS queues purged"
# Create DynamoDB tables in LocalStack
create_local_tables:
# bulk-upload table (PK + SK with GSI)
aws --endpoint-url=http://localhost:4566 dynamodb create-table \
--table-name bulk-upload \
--attribute-definitions \
AttributeName=PK,AttributeType=S \
AttributeName=SK,AttributeType=S \
--key-schema \
AttributeName=PK,KeyType=HASH \
AttributeName=SK,KeyType=RANGE \
--billing-mode PAY_PER_REQUEST \
--global-secondary-indexes '[{"IndexName":"DocumentPkIndex","KeySchema":[{"AttributeName":"SK","KeyType":"HASH"}],"Projection":{"ProjectionType":"ALL"}}]' \
|| true
# connection-gateway table (PK + SK with GSI)
aws --endpoint-url=http://localhost:4566 dynamodb create-table \
--table-name connection-gateway-table \
--attribute-definitions \
AttributeName=PK,AttributeType=S \
AttributeName=SK,AttributeType=S \
--key-schema \
AttributeName=PK,KeyType=HASH \
AttributeName=SK,KeyType=RANGE \
--billing-mode PAY_PER_REQUEST \
--global-secondary-indexes '[{"IndexName":"ConnectionPkIndex","KeySchema":[{"AttributeName":"SK","KeyType":"HASH"},{"AttributeName":"PK","KeyType":"RANGE"}],"Projection":{"ProjectionType":"ALL"}}]' \
|| true
# static-file-metadata table (simple key)
aws --endpoint-url=http://localhost:4566 dynamodb create-table \
--table-name static-file-metadata \
--attribute-definitions \
AttributeName=file_id,AttributeType=S \
--key-schema \
AttributeName=file_id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
|| true
@echo "DynamoDB tables created"
# Create S3 buckets in LocalStack
create_local_buckets:
aws --endpoint-url=http://localhost:4566 s3 mb s3://macro-email-attachments || true
aws --endpoint-url=http://localhost:4566 s3 mb s3://doc-storage || true
aws --endpoint-url=http://localhost:4566 s3 mb s3://docx-upload || true
aws --endpoint-url=http://localhost:4566 s3 mb s3://static-file-storage || true
aws --endpoint-url=http://localhost:4566 s3 mb s3://bulk-upload-staging || true
aws --endpoint-url=http://localhost:4566 s3 mb s3://macro-call-recording-local || true
# Apply CORS configuration to all buckets
for bucket in macro-email-attachments doc-storage docx-upload static-file-storage bulk-upload-staging macro-call-recording-local; do \
aws --endpoint-url=http://localhost:4566 s3api put-bucket-cors --bucket $bucket --cors-configuration '{"CORSRules":[{"AllowedOrigins":["http://localhost:3000","http://localhost:3001","http://localhost:3002","http://localhost:3003","http://localhost:3004","http://localhost:3005","http://localhost:3006","http://localhost:3007","http://localhost:3008","http://localhost:3009"],"AllowedMethods":["GET","PUT","POST","DELETE","HEAD"],"AllowedHeaders":["*"],"ExposeHeaders":["ETag"],"MaxAgeSeconds":3600}]}' || true; \
done
@echo "S3 buckets created"
# Wire document-storage ObjectCreated events to the local upload finalizer worker.
configure_document_upload_finalizer_notifications:
#!/usr/bin/env bash
set -euo pipefail
queue_url="http://localhost:4566/000000000000/document-upload-finalizer-queue"
queue_arn="arn:aws:sqs:us-east-1:000000000000:document-upload-finalizer-queue"
policy=$(python3 - <<'PY'
import json
policy = {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": "*",
"Action": "sqs:SendMessage",
"Resource": "arn:aws:sqs:us-east-1:000000000000:document-upload-finalizer-queue",
"Condition": {"ArnEquals": {"aws:SourceArn": "arn:aws:s3:::doc-storage"}},
}],
}
print(json.dumps({"Policy": json.dumps(policy)}))
PY
)
aws --endpoint-url=http://localhost:4566 sqs set-queue-attributes \
--queue-url "$queue_url" \
--attributes "$policy" || true
aws --endpoint-url=http://localhost:4566 s3api put-bucket-notification-configuration \
--bucket doc-storage \
--notification-configuration "{\"QueueConfigurations\":[{\"Id\":\"document-upload-finalizer\",\"QueueArn\":\"$queue_arn\",\"Events\":[\"s3:ObjectCreated:*\"]}]}"
echo "Document upload finalizer S3 notification configured"
# Full LocalStack setup
setup_localstack:
just start_localstack
just create_local_queues
just create_local_tables
just create_local_buckets
just configure_document_upload_finalizer_notifications