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
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
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
@@ -142,6 +142,10 @@ cd ..
142
142
143
143
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.
144
144
145
+
:::tip
146
+
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.
147
+
:::
148
+
145
149
#### Prerequisites
146
150
147
151
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.
@@ -153,7 +157,29 @@ export GITHUB_TOKEN="ghp_..." # Fine-grained PAT (see agent/README.md for re
153
157
export AWS_REGION="us-east-1"# Region where Bedrock models are enabled
154
158
```
155
159
156
-
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).
160
+
#### AWS credential resolution
161
+
162
+
The script resolves AWS credentials in priority order:
163
+
164
+
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`).
165
+
166
+
```bash
167
+
export AWS_ACCESS_KEY_ID="AKIA..."
168
+
export AWS_SECRET_ACCESS_KEY="..."
169
+
export AWS_SESSION_TOKEN="..."# required for temporary credentials
170
+
```
171
+
172
+
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.
173
+
174
+
```bash
175
+
export AWS_PROFILE="my-dev-profile"# optional — defaults to the CLI default profile
176
+
```
177
+
178
+
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.
179
+
180
+
:::caution
181
+
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.
182
+
:::
157
183
158
184
#### Running a task locally
159
185
@@ -189,6 +215,8 @@ curl -X POST http://localhost:8080/invocations \
189
215
-d '{"input":{"prompt":"Fix the login bug","repo_url":"owner/repo"}}'
190
216
```
191
217
218
+
In server mode, `repo_url`, `prompt`, and other task parameters can be sent via the `/invocations` JSON payload instead of environment variables.
219
+
192
220
#### Monitoring a running container
193
221
194
222
The container runs with a fixed name (`bgagent-run`). In a second terminal:
@@ -206,12 +234,22 @@ docker exec -it bgagent-run bash # shell into the container
206
234
|---|---|---|
207
235
|`ANTHROPIC_MODEL`|`us.anthropic.claude-sonnet-4-6`| Bedrock model ID |
208
236
|`MAX_TURNS`|`100`| Max agent turns before stopping |
237
+
|`MAX_BUDGET_USD`|| Cost ceiling for local batch runs (USD). Not used in production — see below |
209
238
|`DRY_RUN`|| Set to `1` to validate config and print prompt without running the agent |
210
239
211
240
**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`.
212
241
213
242
For the full list of environment variables and GitHub PAT permissions, see `agent/README.md`.
214
243
244
+
#### Troubleshooting
245
+
246
+
| Symptom | Cause | Fix |
247
+
|---|---|---|
248
+
|`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 |
249
+
|`ERROR: GITHUB_TOKEN is not set`| Missing PAT | Export `GITHUB_TOKEN` (see `agent/README.md` for required scopes) |
250
+
|`WARNING: No AWS credentials detected`| No env vars, no AWS CLI, no `~/.aws` directory | Configure one of the three credential methods above |
251
+
|`WARNING: Image exceeds AgentCore 2 GB limit!`| Agent image too large for production | Reduce dependencies or use multi-stage Docker build |
252
+
215
253
### Deployment
216
254
217
255
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