Skip to content

Commit 647d4e4

Browse files
committed
docs: fix VPC Link integration — use SRV record + Cloud Map ARN
Fixes based on chaodu-agent's live E2E finding in openabdev#1275: - Cloud Map service must use SRV records (not A) — the port comes from SRV - Integration URI must be the Cloud Map service ARN (not http:// URL) - API Gateway HTTP API VPC_LINK rejects http:// URIs with: BadRequestException: integration uri should be a valid Cloud Map service ARN - Capture SERVICE_ID from create-service for the service ARN lookup - Also fix --task-definition your-bot:latest → your-bot (ECS family name) - Update architecture diagram, path passthrough callout, and DNS record descriptions to match the corrected configuration
1 parent 12653ab commit 647d4e4

1 file changed

Lines changed: 31 additions & 21 deletions

File tree

docs/refarch/running-telegram-line-on-aws.md

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ API Gateway HTTP API and uses Cloud Map for service discovery instead of hardcod
7474
│ AWS Cloud Map │ ~$0 (private DNS)
7575
│ namespace: oab │
7676
│ service: your-bot │
77-
│ → DNS A record
78-
│ resolves to task IP
77+
│ → DNS SRV record │
78+
│ resolves to IP:port
7979
└───────────┬───────────┘
8080
8181
@@ -94,10 +94,12 @@ API Gateway HTTP API and uses Cloud Map for service discovery instead of hardcod
9494
- The task's security group
9595
- AWS CLI or Console access
9696

97-
> **DNS record type: use A, not SRV**
98-
> API Gateway HTTP API integration resolves DNS A records — SRV records do **not** work
99-
> for VPC Link targets. Always use `{Type="A"}` in your Cloud Map service configuration.
100-
> The port (`:8080`) is specified in the integration URI, not the DNS record.
97+
> **DNS record type: use SRV, not A**
98+
> API Gateway HTTP API VPC Link integrations require the Cloud Map service **ARN**
99+
> (not an `http://` URL) as the integration URI. The port comes from the **SRV** record —
100+
> A records do **not** carry port information and will fail with
101+
> `BadRequestException: integration uri should be a valid Cloud Map service ARN`.
102+
> Use `{Type="SRV"}` in your Cloud Map service configuration.
101103
102104
### Step-by-Step
103105

@@ -110,12 +112,13 @@ aws servicediscovery create-private-dns-namespace \
110112
--vpc vpc-abc123 \
111113
--region us-east-1
112114

113-
# Service with DNS A record (auto-registers task IP)
115+
# Service with DNS SRV record (auto-registers task IP + port)
114116
aws servicediscovery create-service \
115117
--name your-bot \
116118
--namespace-id ns-xxx \
117-
--dns-config 'NamespaceId="ns-xxx",DnsRecords=[{Type="A",TTL="60"}]' \
118-
--region us-east-1
119+
--dns-config 'NamespaceId="ns-xxx",DnsRecords=[{Type="SRV",TTL="60"}]' \
120+
--region us-east-1 \
121+
--query 'Service.Id' --output text # save this as SERVICE_ID
119122
```
120123

121124
#### 2. Enable Service Discovery on Your ECS Service
@@ -131,7 +134,7 @@ aws ecs delete-service --cluster oab --service your-bot --region us-east-1
131134
aws ecs create-service \
132135
--cluster oab \
133136
--service-name your-bot \
134-
--task-definition your-bot:latest \
137+
--task-definition your-bot \
135138
--desired-count 0 \
136139
--launch-type FARGATE \
137140
--network-configuration \
@@ -143,9 +146,9 @@ aws ecs create-service \
143146
aws ecs update-service --cluster oab --service your-bot --desired-count 1 --region us-east-1
144147
```
145148

146-
When the task starts, ECS auto-registers its private IP as the DNS A record for
147-
`your-bot.oab`. Other services in the same VPC resolve this name to reach the task on
148-
`:8080`.
149+
When the task starts, ECS auto-registers its private IP and port as the DNS SRV record
150+
for `your-bot.oab`. The SRV record carries both address and port, which the VPC Link
151+
uses to route traffic.
149152

150153
> **ECS task-def naming**: Use the family name (resolves to latest ACTIVE revision)
151154
> or `family:revision` (e.g., `your-bot:1`). ECS does not support Docker-style
@@ -174,13 +177,19 @@ API_ID=$(aws apigatewayv2 create-api \
174177
--region us-east-1 \
175178
--query 'ApiId' --output text)
176179

177-
# Create the integration FIRST: VPC Link → Cloud Map service endpoint
178-
# Endpoint = your-bot.oab:8080 (the Cloud Map DNS name)
180+
# Get the Cloud Map service ARN (needed for the integration URI)
181+
SERVICE_ARN=$(aws servicediscovery get-service \
182+
--id $SERVICE_ID \
183+
--region us-east-1 \
184+
--query 'Service.Arn' --output text)
185+
186+
# Create the integration FIRST: VPC Link → Cloud Map service ARN
187+
# The integration URI must be the Cloud Map service ARN (not an http:// URL)
179188
INTEGRATION_ID=$(aws apigatewayv2 create-integration \
180189
--api-id $API_ID \
181190
--integration-type HTTP_PROXY \
182191
--integration-method POST \
183-
--integration-uri "http://your-bot.oab:8080" \
192+
--integration-uri "$SERVICE_ARN" \
184193
--connection-type VPC_LINK \
185194
--connection-id $VPC_LINK_ID \
186195
--payload-format-version "1.0" \
@@ -216,13 +225,14 @@ https://{api-id}.execute-api.us-east-1.amazonaws.com/prod/webhook/line
216225
```
217226

218227
> **Path passthrough is automatic**: API Gateway HTTP API appends the route path to the
219-
> integration URI. The route `POST /webhook/telegram` combined with integration URI
220-
> `http://your-bot.oab:8080` results in requests hitting
221-
> `http://your-bot.oab:8080/webhook/telegram` on the container. No path rewriting
222-
> needed.
228+
> integration target. The route `POST /webhook/telegram` results in
229+
> `POST /webhook/telegram` hitting the container. No path rewriting needed.
230+
>
231+
> When the Cloud Map service is registered via ECS service discovery, the SRV record
232+
> carries the container port — API Gateway does not need to specify it separately.
223233
224234
This URL **never changes** — even when tasks restart and get new private IPs, Cloud Map
225-
auto-updates the DNS record and the VPC Link resolves the new IP transparently.
235+
auto-updates the DNS SRV record and the VPC Link resolves the new IP transparently.
226236

227237
#### 5. Security Group: Inbound Rules
228238

0 commit comments

Comments
 (0)