Repository navigation
Component Infra Stacks
Source-Agent-Infra-Deployment-Review checks 98fadf7 on the unmerged
architecture-review branch. The standalone JWT Runtime V2 construct and Data
stack now exist there, but app composition still uses guest Cognito and the
old budget path and does not instantiate the new runtime. Planned asset
publication must be separated from bootstrap synthesis. The historical
resource descriptions below do not establish that this branch is deployable.
The infra package defines four CDK stacks: WebSocket/Lambda plumbing, monthly budget enforcement, Cognito guest identity, and static frontend hosting. It also contains the WebSocket Lambda handler described in Component-WebSocket-Transport. The CDK code read on 2026-09-26 does not define an AgentCore runtime construct and does not define an AgentCore Memory construct.
The guest identity pool remains current code, not the deployment target: constitution v1.5.0 requires invite-only, allowlisted sign-in and forbids unauthenticated spend-bearing access. The architecture review must replace this path before first deployment; the constitution amendment added no infrastructure.
packages/infra/lib/agent-stack.tspackages/infra/lib/budget-stack.tspackages/infra/lib/cognito-stack.tspackages/infra/lib/frontend-stack.tspackages/infra/lib/handlers/websocket-handler.ts
class AgentStack extends cdk.Stackinterface BudgetStackProps extends cdk.StackProps { unauthRole: iam.Role; unauthPolicyName: string; alertEmail: string; }class BudgetStack extends cdk.Stackinterface CognitoStackProps extends cdk.StackProps { agentRuntimeArn: string; }-
class CognitoStack extends cdk.StackidentityPoolId: stringunauthRole: iam.RoleunauthPolicyName: string
class FrontendStack extends cdk.Stackhandler: APIGatewayProxyWebsocketHandlerV2
Current resources:
- Imports two SSM SecureString parameters by name for weather and news API keys.
- Creates
WebSocketHandlerLambda fromlib/handlers, Node.js 22.x, 30 second timeout, 256 MB memory. - Does not set the WebSocket Lambda's CloudWatch log retention or log level explicitly; see Concept-Observability.
- Publishes a Lambda version and
livealias for rollback. - Grants the Lambda read access to those two secure parameters.
- Creates an API Gateway v2 WebSocket API with route selection expression
$request.body.type. - Creates Lambda proxy integration.
- Creates
$connectroute withAWS_IAMauthorization. - Creates
$disconnectand$defaultroutes. - Creates
prodstage with auto deploy and route throttling. - Grants API Gateway permission to invoke the Lambda alias.
- Grants the Lambda
execute-api:ManageConnectionsfor the WebSocket API. - Outputs the WebSocket endpoint, live alias ARN, and expected SSM parameter names.
Important verification: no AgentCore runtime resource and no AgentCore Memory resource are constructed in agent-stack.ts. There is no CfnMemory, memory ID output, memory policy, or AgentCore memory wiring in the stack code read.
Current resources:
- SNS topic
BudgetHardStopTopic. Anything published to it triggers the hard stop, so only the 100% notification publishes there. - Topic policy letting
budgets.amazonaws.comcallsns:Publish, withaws:SourceAccountandaws:SourceArnconditions that restrict it to this account's budgets. Both are built from CDK tokens, never a literal account ID. - Inline Node.js 22 Lambda that deletes a named inline policy from the unauth role.
- Does not set the hard-stop Lambda's CloudWatch log retention or log level explicitly; see Concept-Observability.
- IAM permission allowing that Lambda to delete the specific role policy.
- Lambda subscription to the hard-stop topic.
- AWS Budgets monthly cost budget named for Max Height, with actual-cost notifications at 50%, 80%, and 100% of a 10 USD monthly amount. All three email the owner. Only 100% also publishes to the hard-stop topic.
- Output
HardStopTopicArn. Nothing consumes it.
The owner's address comes from the alertEmail prop, which bin/app.ts reads from the CDK context key budgetAlertEmail. The constructor throws if it is missing or blank, and the message names the key. Every cdk synth, diff and deploy of the app therefore needs -c budgetAlertEmail=<owner email>. The address is never committed, because the repo is public.
Until 2026-10-03 the 50%, 80% and 100% notifications all published to one topic, and the hard-stop Lambda was that topic's only subscriber. It never checked which threshold fired, so a $5 warning would have revoked guest access. No person was subscribed either, so P2's $5 and $8 email alarms emailed nobody.
A second bug hid the first. The topic had no access policy for budgets.amazonaws.com. AWS requires one, so as written Budgets could not have delivered any notification at all, the $10 hard stop included. Fixing only the grant would have armed the routing bug, so both changed together.
Warnings now go by email only, with no SNS subscriber. That makes the bug structurally impossible rather than filtered at runtime. The two runtime alternatives were rejected:
- Parse the threshold in the Lambda. AWS does not document the format of a Budgets SNS message, so a parser fails either open (warnings delete the policy) or closed (the hard stop never fires).
- An SNS subscription filter policy. It needs message attributes or a JSON body to match on, and Budgets is not documented to provide either.
Each budget notification allows one SNS subscriber and up to ten email subscribers, so the warnings' SNS slot stays free. A future machine-readable $8 signal can use it for the soft-degrade (FR-016), which today has a frontend consumer and no producer. That would add a topic, so it is a Spec Kit trigger.
All of this is verified against synthesized templates only. Nothing has been deployed, so no real notification has been delivered.
The 100% budget notification is meant to drive the hard-stop Lambda, which removes the unauthenticated role policy supplied by CognitoStack. As written it would silently do nothing (issue #61). The Lambda deletes the literal name CognitoUnauthRoleDefaultPolicy, but CDK's Role.addToPolicy generates the inline policy's name with a hash suffix. A synth on 2026-10-02 produced CognitoUnauthRoleDefaultPolicy4E16848D. The delete would therefore hit NoSuchEntityException, which the handler logs as "Policy already detached" and treats as success. budget-stack.test.ts passes the same literal to a mock role, so the test agrees with the bug. Nothing has been deployed, so it is latent.
Even with the correct name, the hard stop only removes the guest role's InvokeAgentRuntime. The frontend reaches the agent through the WebSocket API's Lambda, whose own role the hard stop never touches. The mechanism is an open question for the architecture review.
Current resources:
- Cognito Identity Pool with unauthenticated identities enabled.
- Federated unauthenticated IAM role for Cognito Identity.
- Policy allowing
bedrock-agentcore:InvokeAgentRuntimeonprops.agentRuntimeArn. - Policy allowing Polly neural synthesis with
VoiceIdconstrained toMatthew; resource is*. - Identity pool role attachment.
- Output for the identity pool ID.
The stack exposes unauthRole and unauthPolicyName so Concept-Budget-Ceiling enforcement can detach the policy.
Current resources:
- Private S3 bucket with block-public-access, S3-managed encryption, SSL enforcement, destroy removal policy, and auto-delete objects.
- CloudFront response headers policy with CSP, content-type options, frame deny, strict-origin referrer policy, and HSTS.
- The current CSP's
connect-srcallows'self', wildcard API Gateway WebSockets, and Cognito Identity hosts. It does not allow a Polly host. - CloudFront distribution with S3 origin access control, HTTPS redirect,
index.htmlroot, and SPA-style 403/404 fallback to/index.html. - Outputs for distribution URL and bucket name.
useAudio.ts calls synthesizeTurn in pollyTts.ts, which constructs a
browser-side PollyClient and sends SynthesizeSpeech requests. Once that
path has working credentials and an endpoint, the deployed CSP would block
those cross-origin requests, preventing the intended Polly voice output. The
same policy also has no sign-in user-pool endpoint yet. This is a code-level
prediction, not a browser-verified failure: nothing has been deployed.
Spec 003 FR-032, FR-036 and FR-050 leave endpoint, credentials and exact CSP
hosts to the deployment plan. See Component-Audio-Chain.
frontend-stack.ts:51-62 maps 403 and 404 to /index.html with status 200.
CloudFront custom error responses are a DistributionConfig member with no
per-behavior form (CloudFront API: CustomErrorResponse),
so they apply to every origin on the distribution. Once the runtime sits
behind the same distribution, its authorizer's 403 would arrive as an HTML 200,
and the client could never tell that its token had expired.
Spec 003's plan replaces errorResponses with a CloudFront Function on the
default behavior only. The function rewrites any URI whose last segment has
no . to /index.html. Two constraints shaped it:
- Lambda@Edge was not an option. The AWS Free plan does not support it (supported services, re-read 2026-10-11). The Free plan is temporary (Decision-AWS-Account-Plan), so this constraint lapses. A CloudFront Function remains the cheaper fit for a URI rewrite.
-
cloudfront.Functiondefaults to the JavaScript 1.0 runtime (aws-cloudfront/lib/function.d.ts:88,aws-cdk-lib2.272.0), so the plan setsFunctionRuntime.JS_2_0explicitly.
This is a plan; the stack still has errorResponses. See Source-Spec-003.
- Known deviation C4 is real in current code:
agent-stack.tsdoes not contain an AgentCore Memory construct. -
Never hardcode a CDK-generated policy name.
Role.addToPolicynames the inline policy<RoleId>DefaultPolicy<hash>, not<RoleId>DefaultPolicy. The hard stop does exactly that, and its idempotentNoSuchEntityExceptionpath turns the miss into a false success (seeBudgetStackabove, issue #61). -
AWS Budgets cannot publish to an SNS topic without a topic policy granting
budgets.amazonaws.com, and CDK'ssns.Topicadds none. Without it no notification arrives, the hard stop included (see Warning routing above). - One topic cannot route by threshold. Budgets' SNS message format is undocumented, and filter policies have nothing reliable to match on. Give each destination its own subscriber instead.
-
Never publish anything else to
BudgetHardStopTopic. Every message revokes guest access. Ops alarms (T111) need their own topic (deviation C8). -
CloudFront
errorResponsesare distribution-wide. A SPA's 403/404 fallback rewrites every origin's errors, APIs included, into an HTML 200 (see N6 above). -
cloudfront.Functiondefaults to JavaScript 1.0. Setruntime: FunctionRuntime.JS_2_0explicitly. - Lambda@Edge is unavailable on the AWS Free plan, until the account upgrades in December 2026 (Decision-AWS-Account-Plan). A CloudFront Function is cheaper for edge rewrites anyway.
-
Tags.ofdoes not reachCfnBudget. Inaws-cdk-lib2.272.0 it is notITaggable(aws-budgets/lib/budgets.generated.d.ts:14); a budget's tags must go in its ownresourceTags. -
The budget's defaults count credits.
BudgetStacksets noCostTypes, soIncludeCreditistrueand Free-plan credits can hide all spend. See Concept-Budget-Ceiling. -
The deployment CSP omits Polly. The browser calls Polly directly, but
connect-srcpermits only the site, API Gateway WebSockets and Cognito Identity hosts. This is a latent voice failure until the deployment's endpoints and CSP agree; seeFrontendStackabove. -
CognitoStackPropsrequires anagentRuntimeArn, butAgentStackdoes not create or expose an AgentCore runtime ARN. This closes once the runtime moves into CDK — see below. -
Planned change (2026-09-27, deviation C7). The AgentCore Runtime is moving into this stack. The AgentCore constructs graduated from
@aws-cdk/aws-bedrock-agentcore-alphainto stableaws-cdk-lib/aws-bedrockagentcore, and CloudFormation gained aPlatformVersionproperty, so the CLI no longer has to own the runtime. ImportRuntime,MemoryandMemoryStrategyfrom the stable module. The alpha pin was removed on 2026-09-28 (issue #34); all six constructs T023b and T152 need were confirmed present in stable then, and theimportis what proves it from here on. See Decision-AgentCore-Runtime-V2. -
AgentStackdeploys a WebSocket Lambda handler from infra code; it is not the same runtime path aspackages/agent/src/index.ts. -
AgentStackoutputs a WebSocket endpoint. Treat deployed endpoint values as public routing data, and avoid copying environment-specific endpoints into public wiki pages.
- Concept-Cloud-Only-Inference
- Concept-Budget-Ceiling
- Concept-Personality-Gate
- Concept-IP-And-Legal-Posture
- Concept-Supply-Chain-Discipline
- Concept-Graceful-Degradation
- Concept-Observability
- Concept-Testing-And-TDD
- Concept-Credential-Hygiene
Editing in the browser? Wiki edits are live and bypass wiki:lint. Read
Guide-Wiki-Contributing first.