Skip to content

Commit d47b1a8

Browse files
committed
fix: formatting, docker compose v2 syntax, and outdated userId references in docs
- Fix ruff formatting in scripts/utils.py - Replace docker-compose (v1) with docker compose (v2) in LOCAL_DEVELOPMENT.md - Fix manual curl example in LOCAL_DOCKER_TESTING.md to use mock JWT Authorization header instead of userId in payload - Update AGENT_CONFIGURATION.md example to use extract_user_id_from_context() with RequestContext instead of payload.get('userId')
1 parent a8ed112 commit d47b1a8

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

docs/AGENT_CONFIGURATION.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,21 @@ Create your agent code that:
114114
**Example Structure**:
115115

116116
```python
117-
from bedrock_agentcore.runtime import BedrockAgentCoreApp
117+
from bedrock_agentcore.runtime import BedrockAgentCoreApp, RequestContext
118+
from utils.auth import extract_user_id_from_context
118119

119120
app = BedrockAgentCoreApp()
120121

121122
@app.entrypoint
122-
async def agent_handler(payload):
123+
async def agent_handler(payload, context: RequestContext):
123124
"""Main entrypoint for the agent"""
124125
user_query = payload.get("prompt")
125-
user_id = payload.get("userId")
126126
session_id = payload.get("runtimeSessionId")
127127

128+
# Extract user ID securely from the validated JWT token
129+
# instead of trusting the payload body (which could be manipulated)
130+
user_id = extract_user_id_from_context(context)
131+
128132
# Your agent logic here
129133
# ...
130134

docs/LOCAL_DEVELOPMENT.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ aws cloudformation describe-stacks --stack-name your-stack-name --query 'Stacks[
6060

6161
2. **Start the Stack**:
6262
```bash
63-
cd docker && docker-compose up --build
63+
cd docker && docker compose up --build
6464
```
6565

6666
3. **Access the Application**:
@@ -90,7 +90,7 @@ AWS_SECRET_ACCESS_KEY=your-secret
9090
AWS_SESSION_TOKEN=your-token
9191
```
9292

93-
Then run: `cd docker && docker-compose up --build`
93+
Then run: `cd docker && docker compose up --build`
9494

9595
## Development Workflow
9696

@@ -99,7 +99,7 @@ Then run: `cd docker && docker-compose up --build`
9999
- **Frontend Changes**: Files are mounted as volumes, so changes appear immediately
100100
- **Agent Changes**: Rebuild the agent container:
101101
```bash
102-
cd docker && docker-compose up --build agent
102+
cd docker && docker compose up --build agent
103103
```
104104

105105
### Using Different Agent Patterns
@@ -115,22 +115,22 @@ To use a different agent pattern (e.g., LangGraph):
115115
116116
2. **Rebuild**:
117117
```bash
118-
cd docker && docker-compose up --build agent
118+
cd docker && docker compose up --build agent
119119
```
120120

121121
### Logs and Debugging
122122

123123
```bash
124124
# View all logs
125-
docker-compose logs -f
125+
docker compose logs -f
126126

127127
# View specific service logs
128-
docker-compose logs -f agent
129-
docker-compose logs -f frontend
128+
docker compose logs -f agent
129+
docker compose logs -f frontend
130130

131131
# Access container shell
132-
docker-compose exec agent bash
133-
docker-compose exec frontend sh
132+
docker compose exec agent bash
133+
docker compose exec frontend sh
134134
```
135135

136136
## Troubleshooting
@@ -143,7 +143,7 @@ docker-compose exec frontend sh
143143
1. Verify AWS credentials: `aws sts get-caller-identity`
144144
2. Check environment variables are set correctly
145145
3. Ensure deployed stack exists and is healthy
146-
4. Check agent logs: `docker-compose logs agent`
146+
4. Check agent logs: `docker compose logs agent`
147147

148148
### Frontend Can't Connect to Agent
149149

@@ -176,13 +176,13 @@ docker-compose exec frontend sh
176176

177177
```bash
178178
# Stop all services
179-
cd docker && docker-compose down
179+
cd docker && docker compose down
180180

181181
# Stop and remove volumes
182-
cd docker && docker-compose down -v
182+
cd docker && docker compose down -v
183183

184184
# Stop and remove images
185-
cd docker && docker-compose down --rmi all
185+
cd docker && docker compose down --rmi all
186186
```
187187

188188
## Production Deployment

docs/LOCAL_DOCKER_TESTING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,11 @@ docker run --rm -it -p 8080:8080 \
189189
-e AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \
190190
fast-agent-local
191191

192-
# Test with curl
192+
# Test with curl (mock JWT with sub=test-user)
193193
curl -X POST http://localhost:8080/invocations \
194194
-H "Content-Type: application/json" \
195-
-d '{"prompt": "Hello", "userId": "test", "runtimeSessionId": "test-123"}'
195+
-H "Authorization: Bearer $(python3 -c "import base64,json; h=base64.urlsafe_b64encode(json.dumps({'alg':'none','typ':'JWT'}).encode()).rstrip(b'=').decode(); p=base64.urlsafe_b64encode(json.dumps({'sub':'test-user'}).encode()).rstrip(b'=').decode(); print(f'{h}.{p}.')")" \
196+
-d '{"prompt": "Hello", "runtimeSessionId": "test-123"}'
196197
```
197198

198199
### Testing Health Endpoint

scripts/utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,14 @@ def create_mock_jwt(user_id: str) -> str:
227227
Returns:
228228
str: A mock JWT string (header.payload.signature).
229229
"""
230-
header = base64.urlsafe_b64encode(
231-
json.dumps({"alg": "none", "typ": "JWT"}).encode()
232-
).rstrip(b"=").decode()
233-
payload = base64.urlsafe_b64encode(
234-
json.dumps({"sub": user_id}).encode()
235-
).rstrip(b"=").decode()
230+
header = (
231+
base64.urlsafe_b64encode(json.dumps({"alg": "none", "typ": "JWT"}).encode())
232+
.rstrip(b"=")
233+
.decode()
234+
)
235+
payload = (
236+
base64.urlsafe_b64encode(json.dumps({"sub": user_id}).encode())
237+
.rstrip(b"=")
238+
.decode()
239+
)
236240
return f"{header}.{payload}."

0 commit comments

Comments
 (0)