You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(agent): validate AWS credentials before Docker build (#33)
Move credential resolution (explicit env vars, AWS CLI/SSO, ~/.aws
mount) before the Docker image build so expired sessions and missing
credentials fail immediately with actionable guidance.
- Fix unbound variable crash with empty array under set -u
- Remove dead MOUNT_AWS_DIR variable
- Expand error message to list all three credential methods
- Update local testing docs with credential resolution details,
troubleshooting table, and Starlight admonitions
Co-authored-by: Alain Krok <alkrok@amazon.com>
Copy file name to clipboardExpand all lines: docs/guides/DEVELOPER_GUIDE.md
+39-1Lines changed: 39 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -256,6 +256,10 @@ cd ..
256
256
257
257
Before deploying to AWS, you can build and run the agent Docker container locally. The `agent/run.sh` script handles building the image, resolving AWS credentials, and applying AgentCore-matching resource constraints (2 vCPU, 8 GB RAM) so the local environment closely mirrors production.
258
258
259
+
:::tip
260
+
The script validates AWS credentials **before** starting the Docker build, so problems like an expired SSO session surface immediately — not after a lengthy image build.
261
+
:::
262
+
259
263
#### Prerequisites
260
264
261
265
The `owner/repo` you pass to `run.sh` must match an onboarded Blueprint and be a repository your `GITHUB_TOKEN` can **push to and open PRs on** (same rules as **Repository preparation** at the start of this guide). If you have not changed the Blueprint, fork `awslabs/agent-plugins`, set **`repo`** to your fork, and use a PAT scoped to that fork—then pass the same **`owner/repo`** here.
@@ -267,7 +271,29 @@ export GITHUB_TOKEN="ghp_..." # Fine-grained PAT (see agent/README.md for re
267
271
export AWS_REGION="us-east-1"# Region where Bedrock models are enabled
268
272
```
269
273
270
-
For AWS credentials, either export `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY` directly, or have the AWS CLI configured (the script will resolve credentials from your active profile or SSO session automatically).
274
+
#### AWS credential resolution
275
+
276
+
The script resolves AWS credentials in priority order:
277
+
278
+
1.**Explicit environment variables** — If `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` are set, they are passed directly to the container. Include `AWS_SESSION_TOKEN` when using temporary credentials (e.g. from `aws sts assume-role`).
279
+
280
+
```bash
281
+
export AWS_ACCESS_KEY_ID="AKIA..."
282
+
export AWS_SECRET_ACCESS_KEY="..."
283
+
export AWS_SESSION_TOKEN="..."# required for temporary credentials
284
+
```
285
+
286
+
2.**AWS CLI resolution** — If the CLI is installed, the script runs `aws configure export-credentials` to resolve credentials from your active profile or SSO session. Set `AWS_PROFILE` to target a specific profile.
287
+
288
+
```bash
289
+
export AWS_PROFILE="my-dev-profile"# optional — defaults to the CLI default profile
290
+
```
291
+
292
+
3.**`~/.aws` directory mount** — If neither of the above is available but `~/.aws` exists, the directory is bind-mounted read-only into the container. This works for static credential files but **not for SSO tokens**, which don't resolve well inside the container.
293
+
294
+
:::caution
295
+
If none of these methods succeeds, the script prints a warning and continues without AWS credentials. The container will start but any AWS API call (Bedrock, DynamoDB, etc.) will fail at runtime. Make sure at least one credential source is configured before running a real task.
296
+
:::
271
297
272
298
#### Running a task locally
273
299
@@ -303,6 +329,8 @@ curl -X POST http://localhost:8080/invocations \
303
329
-d '{"input":{"prompt":"Fix the login bug","repo_url":"owner/repo"}}'
304
330
```
305
331
332
+
In server mode, `repo_url`, `prompt`, and other task parameters can be sent via the `/invocations` JSON payload instead of environment variables.
333
+
306
334
#### Monitoring a running container
307
335
308
336
The container runs with a fixed name (`bgagent-run`). In a second terminal:
@@ -320,12 +348,22 @@ docker exec -it bgagent-run bash # shell into the container
320
348
|---|---|---|
321
349
|`ANTHROPIC_MODEL`|`us.anthropic.claude-sonnet-4-6`| Bedrock model ID |
322
350
|`MAX_TURNS`|`100`| Max agent turns before stopping |
351
+
|`MAX_BUDGET_USD`|| Cost ceiling for local batch runs (USD). Not used in production — see below |
323
352
|`DRY_RUN`|| Set to `1` to validate config and print prompt without running the agent |
324
353
325
354
**Cost budget** is not configured here for production tasks: set **`max_budget_usd`** when creating a task (REST API, CLI `--max-budget`, or per-repo Blueprint). The orchestrator passes it in the runtime invocation payload. The optional env var `MAX_BUDGET_USD` applies only to **local batch** runs; see `agent/README.md`.
326
355
327
356
For the full list of environment variables and GitHub PAT permissions, see `agent/README.md`.
328
357
358
+
#### Troubleshooting
359
+
360
+
| Symptom | Cause | Fix |
361
+
|---|---|---|
362
+
|`ERROR: Failed to resolve AWS credentials via AWS CLI`| SSO session expired or profile misconfigured | Run `aws sso login --profile <your-profile>` if using SSO, or `aws configure` to set up a profile, or export `AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY` directly |
363
+
|`ERROR: GITHUB_TOKEN is not set`| Missing PAT | Export `GITHUB_TOKEN` (see `agent/README.md` for required scopes) |
364
+
|`WARNING: No AWS credentials detected`| No env vars, no AWS CLI, no `~/.aws` directory | Configure one of the three credential methods above |
365
+
|`WARNING: Image exceeds AgentCore 2 GB limit!`| Agent image too large for production | Reduce dependencies or use multi-stage Docker build |
366
+
329
367
### Deployment
330
368
331
369
Once your agent works locally, you can deploy it on AWS. A **full**`mise run //cdk:deploy` of this stack has been observed at **~572 seconds (~9.5 minutes)** total (CDK-reported *Total time*); expect variation by Region, account state, and whether container layers are already cached.
0 commit comments