aws-samples / aws-samples/agents4energy

AgUiHandler runtime missing APPSYNC_HTTP_ENDPOINT/AGENTCORE_MEMORY_ID env vars on primary deploy path

Open
#165 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
48
Forks
68
PR merge metrics
No merged PRs in 30d

Description

### Summary

While fixing #163 (missing `appsync:GraphQL` IAM grant for the AgentCore runtime execution role), a related but separate gap was discovered: the `AgUiHandler` runtime is never given `APPSYNC_HTTP_ENDPOINT` / `AGENTCORE_MEMORY_ID` as container environment variables on the primary deploy path (`web/amplify/backend.ts` → `web/amplify/constructs/agentCoreRuntimeWithBuild.ts`).

### Impact

Without `APPSYNC_HTTP_ENDPOINT` set, `agent/handler/agent.py`'s `publish_event()` no-ops (`if not APPSYNC_ENDPOINT: return`), so AG-UI events are never published even after the IAM grant fix in #163. Without `AGENTCORE_MEMORY_ID`, the `AgentCoreMemorySessionManager` never activates, so conversation memory save/load does not happen for the `/chat-handler` flow.

### Root cause

`docs/ag-ui-handler-pattern.md` still documents these values as being wired by the now-removed `scripts/extract-deployment-info.js` post-deploy script. That step was never migrated into the in-stack CDK when the deploy path moved into `backend.ts` (introduced in PR #30).

Wiring this in-line inside `backend.ts` creates a genuine CloudFormation circular dependency: the AppSync HTTP endpoint is a token native to the data stack, but the data stack already depends on the agent stack for the runtime ARN (same shape as the issue that had to be worked around for the `appsync:GraphQL` grant in #163). Properly fixing this likely requires a CDK custom resource (e.g. a Lambda-backed custom resource that calls `UpdateAgentRuntime` post-creation) rather than a direct construct-level env var reference.

### Suggested fix direction

- Add a custom resource (or similar decoupling mechanism) that, after both stacks deploy, updates the `AgUiHandler` runtime's container environment with the AppSync HTTP endpoint and the `MyHarnessMemory` ID — breaking the circular dependency by deferring the wiring to a custom-resource `onEvent` handler that runs after both stacks exist.
- Update `docs/ag-ui-handler-pattern.md` to reflect the fix once implemented (it currently documents the removed `extract-deployment-info.js` script for this step).

### Context

Originally identified during work on #163: https://github.com/waltmayf/agentcore-amplify-fullstack/issues/57

---
*Imported from `waltmayf/agentcore-amplify-fullstack`#62 — originally filed by @app/github-actions on 2026-07-06. Migrated to open-source repo; cross-references updated post-import.*

Contributor guide

Open the contributing guide

Research direction

Trace the primary deployment path from web/amplify/backend.ts through web/amplify/constructs/agentCoreRuntimeWithBuild.ts, and inspect agent/handler/agent.py plus docs/ag-ui-handler-pattern.md. Determine how to defer wiring APPSYNC_HTTP_ENDPOINT and AGENTCORE_MEMORY_ID without a circular dependency; done means the runtime receives both values on deployment and the documentation reflects the migrated path.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.