mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
Provisioning AWS::DynamoDB::Table ignored StreamSpecification, so a stack that declared a stream produced a streamless table: DescribeTable returned neither StreamSpecification nor LatestStreamArn, and event source mappings registered against the expected stream ARN polled "Stream not found" forever. The plain UpdateTable API enabled streams correctly on the same runtime, which is what made this look CloudFormation-specific. The CloudFormation property carries no StreamEnabled flag — unlike the DynamoDB API, declaring the block IS the request — so the block's presence now turns the stream on, honouring StreamViewType. A block that omits StreamViewType still yields a working stream: the schema marks it required and AWS documents no default, so this is deliberately the same leniency DynamoDbJsonHandler already applies on CreateTable/UpdateTable, not an AWS behaviour. Removing the block on an update is the inverse request and switches the stream back off, so a table updated out of streaming stops emitting records to whatever still holds its ARN. Streams are reconciled through new DynamoDbService enableStream/disableStream, mirroring what the JSON handler already does inline for CreateTable/UpdateTable and persisting the table so the change survives. Callers that reach DynamoDB through the service rather than the handler had no entry point for this. Re-enabling a live stream now retargets its view type. The records a stream emits are built from the stream description, which was left untouched once the stream was ENABLED, so a changed StreamViewType was reported by DescribeTable while records kept the old shape. This also fixes the same inconsistency on the UpdateTable path. Make that stream state durable. Both handler paths mutate the table after the service has stored it, and a persistent backend serializes on write rather than holding the live object, so the on-disk copy kept the previous settings. Since startup rebuilds every stream from the persisted table, a restart resurrected the old view type — and a stream declared on CreateTable was lost outright, because the persisted copy still had streamEnabled false. Both paths now flush once after their mutations, which also makes the billing mode, table class, tags and SSE settings they set survive a restart. Also reconcile the StreamArn attribute: only a live stream has an ARN worth handing to Fn::GetAtt. The previous synthetic value resolved to nothing on a streamless table, and because an update starts from the resource's previous attributes, a stale ARN is now removed rather than merely left unwritten. Adds DynamoDbStreamSpecificationCfnProvisionerTest covering the declared stream, an explicit StreamViewType, a block with no view type, removal and retention on update, a view-type change on update, and the unchanged no-stream path; DynamoDbStreamServiceTest coverage that a retarget reaches the emitted records; and DynamoDbStreamViewTypeDurabilityTest, which drives the handler against a file-backed store and reloads it to prove both paths survive a restart.