fix(cloudformation): apply KinesisStreamSpecification on AWS::DynamoDB::Table (#7464)

* fix(cloudformation): apply KinesisStreamSpecification on AWS::DynamoDB::Table

The property was accepted and ignored, so a stack that declared it got a
table whose item changes never reached the stream.

The declared stream becomes the table's active Kinesis streaming
destination on create and update. Removing a block the previous template
declared turns it off, and a stack that never declared it leaves
destinations set outside it alone. The in-place update snapshot of a
stack that manages the destinations records them, so a failed update
puts them back as they were.

A change of ApproximateCreationDateTimePrecision alone updates the active
destination in place, as CloudFormation does with one
UpdateKinesisStreamingDestination call, so forwarding never stops and
records already captured are still delivered.

A block that is not an object fails template validation, as
TimeToLiveSpecification does, rather than reading as a removed block
that turns forwarding off.

A StreamArn the destination cannot use fails the table as the AWS handler
does, and the table this attempt created is deleted. One under 37
characters fails EnableKinesisStreamingDestination's validation. One that
is not a Kinesis stream ARN, such as the stream name Ref returns, or one
naming a stream that does not exist fails as NotStabilized.

DynamoDbTableAccess gains enable, disable and update operations for the
destination. DynamoDB Local has no Kinesis forwarding, so that backend
leaves the table as it is and logs a warning. CloudFormation still checks
StreamArn there as AWS does; only the forwarding is skipped.

* fix(cloudformation): match Kinesis destinations by their whole stream ARN

A destination was looked up by the last segment of its StreamArn in the
table's account and region, so an ARN for another account, region or
resource type that ended in a local stream's name forwarded to that
stream. KinesisService.describeStreamByArn now finds a stream only by its
exact ARN. NativeDynamoDbTableService uses it, so the public
EnableKinesisStreamingDestination action reports such an ARN as not
found, and CloudFormation fails the table as NotStabilized.

The DynamoDB Local backend looks the stream up the same way before it
skips forwarding, so a template naming a missing stream fails there too.

A declared StreamArn the table already forwards to now goes through the
same template checks as a new one; only the rollback restore skips them.
This commit is contained in:
mokamoto12 authored and GitHub committed 2026-11-03 23:10:27 -04:00
1 parent a026c8a94c
commit 8b756a3467
19 files changed
+1096 -31

No files matched your search

@@ -3,9 +3,12 @@ package io.github.hectorvent.floci.services.cloudformation.provisioners;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
@@ -14,6 +17,7 @@ import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbTableAccess.
import io.github.hectorvent.floci.services.dynamodb.model.AttributeDefinition;
import io.github.hectorvent.floci.services.dynamodb.model.GlobalSecondaryIndex;
import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement;
import io.github.hectorvent.floci.services.dynamodb.model.KinesisStreamingDestination;
import io.github.hectorvent.floci.services.dynamodb.model.LocalSecondaryIndex;
import io.github.hectorvent.floci.services.dynamodb.model.TableDefinition;
import jakarta.enterprise.context.ApplicationScoped;
@@ -43,9 +47,11 @@ import java.util.Set;
* {@code Ref} of a replica follows CDK's {@code <tableName>-<region>} format.
*
* <p>A table's {@code TimeToLiveSpecification} is reconciled against what DescribeTimeToLive
* reports, so UpdateTimeToLive is called only when the setting differs. An in-place update of an
* {@code AWS::DynamoDB::Table} keeps the tags, stream and TTL setting it replaces, so a failed
* stack update can put all three back.
* reports, so UpdateTimeToLive is called only when the setting differs. Its
* {@code KinesisStreamSpecification} is reconciled against the table's active Kinesis streaming
* destinations the same way. An in-place update of an {@code AWS::DynamoDB::Table} keeps the tags,
* stream, TTL setting and Kinesis streaming destinations it replaces, so a failed stack update can
* put all four back.
*/
@ApplicationScoped
public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
@@ -62,6 +68,14 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
private static final String REPLICA_REGION_ATTR = "__FlociDynamoDbReplicaRegion";
private static final String REPLICA_SKIP_DELETION_ATTR = "__FlociDynamoDbReplicaSkipDeletion";
private static final int TABLE_NAME_MAX_LENGTH = 255;
private static final String KINESIS_STREAM_SPECIFICATION = "KinesisStreamSpecification";
private static final String DESTINATION_ACTIVE = "ACTIVE";
private static final int STREAM_ARN_MIN_LENGTH = 37;
private static final int STREAM_ARN_MAX_LENGTH = 1024;
/** One Kinesis streaming destination a table should forward to, with its timestamp precision. */
private record KinesisDestinationSpec(String streamArn, String precision) {
}
private final DynamoDbFacade dynamoDb;
@@ -133,6 +147,15 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
// survives an update; removing a block the previous template declared turns TTL off.
boolean ttlManaged = ttlDeclared || ctx.previouslyDeclared("TimeToLiveSpecification");
TimeToLive desiredTtl = ttlDeclared ? declaredTimeToLive(ttlSpec, engine) : TIME_TO_LIVE_OFF;
JsonNode kinesisSpec = props != null ? engine.resolveNode(props.get(KINESIS_STREAM_SPECIFICATION)) : null;
boolean kinesisDeclared = kinesisSpec != null && !kinesisSpec.isNull();
if (kinesisDeclared) {
CfnPropertyTypes.requireType(KINESIS_STREAM_SPECIFICATION, kinesisSpec, JsonNodeType.OBJECT);
}
boolean kinesisManaged = kinesisDeclared || ctx.previouslyDeclared(KINESIS_STREAM_SPECIFICATION);
List<KinesisDestinationSpec> desiredKinesis = kinesisDeclared
? List.of(declaredKinesisDestination(kinesisSpec, engine))
: List.of();
List<KeySchemaElement> keySchema = new ArrayList<>();
List<AttributeDefinition> attrDefs = new ArrayList<>();
@@ -232,7 +255,7 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
}
Map<String, String> currentTags = dynamoDb.tables().listTagsOfResource(scope, table.getTableArn());
if (inPlaceUpdate && TABLE.equals(r.getResourceType())) {
snapshotBeforeUpdate(r, scope, tableName, table, currentTags, currentTtl);
snapshotBeforeUpdate(r, scope, tableName, table, currentTags, currentTtl, kinesisManaged);
}
reconcileTags(scope, table.getTableArn(), currentTags,
@@ -262,6 +285,10 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
reconcileTimeToLive(scope, tableName, currentTtl, desiredTtl);
}
if (kinesisManaged) {
table = reconcileKinesisDestinations(scope, tableName, table, desiredKinesis, true);
}
r.setPhysicalId(tableName);
r.getAttributes().put("Arn", table.getTableArn());
// Only the global table's registry schema declares TableId read-only; a plain table exposes
@@ -382,12 +409,128 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
}
/**
* Keeps the tags, stream setting and TTL setting the table has before an in-place update
* changes them, with the account and region that address it, so {@link #rollbackUpdate} can
* put all three back.
* Runs before the table is created, as AWS validates the template before any resource exists. An
* empty {@code StreamArn} is present, so it passes here and fails the API's length check later.
*/
private static KinesisDestinationSpec declaredKinesisDestination(JsonNode spec,
CloudFormationTemplateEngine engine) {
JsonNode streamArnNode = spec.get("StreamArn");
String streamArn = streamArnNode == null || streamArnNode.isNull() ? null : engine.resolve(streamArnNode);
if (streamArn == null) {
throw new AwsException("InvalidRequest",
"Model validation failed (#/KinesisStreamSpecification: required key [StreamArn] not found)", 400);
}
JsonNode precisionNode = spec.get("ApproximateCreationDateTimePrecision");
String precision = precisionNode == null || precisionNode.isNull()
? KinesisStreamingDestination.PRECISION_MILLISECOND
: engine.resolve(precisionNode);
if (!KinesisStreamingDestination.PRECISION_MILLISECOND.equals(precision)
&& !KinesisStreamingDestination.PRECISION_MICROSECOND.equals(precision)) {
throw new AwsException("InvalidRequest", "Model validation failed"
+ " (#/KinesisStreamSpecification/ApproximateCreationDateTimePrecision:"
+ " failed validation constraint for keyword [enum])", 400);
}
return new KinesisDestinationSpec(streamArn, precision);
}
private static List<KinesisDestinationSpec> activeKinesisDestinations(TableDefinition table) {
List<KinesisDestinationSpec> active = new ArrayList<>();
for (KinesisStreamingDestination destination : table.getKinesisStreamingDestinations()) {
if (DESTINATION_ACTIVE.equals(destination.getDestinationStatus())) {
active.add(new KinesisDestinationSpec(destination.getStreamArn(),
destination.getApproximateCreationDateTimePrecision()));
}
}
return active;
}
/**
* Leaves exactly the desired destinations active. A destination whose precision alone differs is
* updated in place, as CloudFormation does with one UpdateKinesisStreamingDestination call. The
* active list is copied first: the service may hand back the stored table, whose destination list
* the calls below change.
* {@code fromTemplate} checks every declared {@code StreamArn} as the AWS handler does, whether
* or not the table already forwards to it; a rollback restores destinations the table already had
* and enables them as they were.
*/
private TableDefinition reconcileKinesisDestinations(Scope scope, String tableName, TableDefinition table,
List<KinesisDestinationSpec> desired, boolean fromTemplate) {
if (fromTemplate) {
for (KinesisDestinationSpec destination : desired) {
requireUsableStreamArn(tableName, destination.streamArn());
}
}
List<KinesisDestinationSpec> active = activeKinesisDestinations(table);
for (KinesisDestinationSpec destination : active) {
if (!containsStream(desired, destination.streamArn())) {
table = dynamoDb.tables().disableKinesisStreamingDestination(scope, tableName,
destination.streamArn());
}
}
for (KinesisDestinationSpec destination : desired) {
if (active.contains(destination)) {
continue;
}
if (containsStream(active, destination.streamArn())) {
table = dynamoDb.tables().updateKinesisStreamingDestination(scope, tableName,
destination.streamArn(), destination.precision());
} else if (fromTemplate) {
table = enableKinesisDestination(scope, tableName, destination);
} else {
table = dynamoDb.tables().enableKinesisStreamingDestination(scope, tableName,
destination.streamArn(), destination.precision());
}
}
return table;
}
/**
* Fails the way the AWS handler does. A {@code StreamArn} outside the API's 37 to 1024 characters
* fails EnableKinesisStreamingDestination's own validation. Any other value that is not a Kinesis
* stream ARN, such as a stream's name from {@code Ref}, never becomes active, so the table does
* not stabilize.
*/
private static void requireUsableStreamArn(String tableName, String streamArn) {
String violation = SmithyValidationErrors.lengthOutOfRange("streamArn", streamArn,
STREAM_ARN_MIN_LENGTH, STREAM_ARN_MAX_LENGTH);
if (violation != null) {
throw SmithyValidationErrors.exception("InvalidRequest", violation);
}
if (!AwsArnUtils.isArnFor(streamArn, "kinesis")) {
throw notStabilized(tableName);
}
}
/** A stream that does not exist, as the table's account and region see it, never becomes active either. */
private TableDefinition enableKinesisDestination(Scope scope, String tableName,
KinesisDestinationSpec destination) {
try {
return dynamoDb.tables().enableKinesisStreamingDestination(scope, tableName, destination.streamArn(),
destination.precision());
} catch (AwsException e) {
if ("ResourceNotFoundException".equals(e.getErrorCode())) {
throw notStabilized(tableName);
}
throw e;
}
}
private static AwsException notStabilized(String tableName) {
return new AwsException("NotStabilized", "Resource of type '" + TABLE + "' with identifier '" + tableName
+ "' did not stabilize.", 400);
}
private static boolean containsStream(List<KinesisDestinationSpec> destinations, String streamArn) {
return destinations.stream().anyMatch(destination -> destination.streamArn().equals(streamArn));
}
/**
* Keeps the tags, stream setting, TTL setting and active Kinesis streaming destinations the table
* has before an in-place update changes them, with the account and region that address it, so
* {@link #rollbackUpdate} can put all four back.
*/
private static void snapshotBeforeUpdate(StackResource r, Scope scope, String tableName, TableDefinition table,
Map<String, String> tags, TimeToLive ttl) {
Map<String, String> tags, TimeToLive ttl, boolean kinesisManaged) {
ObjectNode snapshot = MAPPER.createObjectNode();
snapshot.put("accountId", scope.accountId());
snapshot.put("region", scope.region());
@@ -398,6 +541,14 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
snapshot.put("streamViewType", table.getStreamViewType());
snapshot.put("ttlEnabled", ttl.enabled());
snapshot.put("ttlAttributeName", ttl.attributeName());
if (kinesisManaged) {
ArrayNode destinations = snapshot.putArray("kinesisDestinations");
for (KinesisDestinationSpec destination : activeKinesisDestinations(table)) {
destinations.addObject()
.put("streamArn", destination.streamArn())
.put("precision", destination.precision());
}
}
r.getAttributes().put(CfnRollback.DYNAMODB_TABLE_UPDATE_SNAPSHOT_ATTR, snapshot.toString());
}
@@ -412,9 +563,10 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
}
/**
* Puts back the tags, stream setting and TTL setting an in-place table update changed. All
* three go back or none is claimed: restoring one alone would report a rollback while the
* others stayed changed. Only an in-place {@code AWS::DynamoDB::Table} update takes the
* Puts back the tags, stream setting, TTL setting and Kinesis streaming destinations an in-place
* table update changed. All four go back or none is claimed: restoring one alone would report a
* rollback while the others stayed changed. A snapshot without destinations leaves them as they
* are. Only an in-place {@code AWS::DynamoDB::Table} update takes the
* snapshot, so a global table or a replacing update still reports that rollback is not
* implemented. The snapshot is spent only once the restore succeeded: a restore that throws
* leaves it in place for the next attempt.
@@ -453,6 +605,15 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
requireTimeToLiveChangeAllowed(currentTtl, priorTtl);
reconcileTimeToLive(scope, tableName, currentTtl, priorTtl);
if (snapshot.has("kinesisDestinations")) {
List<KinesisDestinationSpec> priorDestinations = new ArrayList<>();
for (JsonNode destination : snapshot.path("kinesisDestinations")) {
priorDestinations.add(new KinesisDestinationSpec(destination.path("streamArn").asText(),
destination.path("precision").asText()));
}
table = reconcileKinesisDestinations(scope, tableName, table, priorDestinations, false);
}
publishStreamArn(resource, table);
resource.getAttributes().remove(CfnRollback.DYNAMODB_TABLE_UPDATE_SNAPSHOT_ATTR);
return true;
@@ -74,7 +74,7 @@ public class NativeDynamoDbTableService {
* read-back of the stored {@link KinesisStreamingDestination}: that object is shared across
* requests, so reading it again could report a status a concurrent call wrote in the meantime.
*/
record KinesisDestination(String tableName, String streamArn, String destinationStatus,
public record KinesisDestination(String tableName, String streamArn, String destinationStatus,
String approximateCreationDateTimePrecision) {}
/** One GlobalSecondaryIndexOverride or LocalSecondaryIndexOverride entry; LSIs carry no throughput. */
@@ -524,13 +524,13 @@ public class NativeDynamoDbTableService {
* @param precision an already validated ApproximateCreationDateTimePrecision
* @return a snapshot of what this call left on the destination, with the canonical table name
*/
KinesisDestination enableKinesisStreamingDestination(String tableName, String streamArn, String precision, String region) {
public KinesisDestination enableKinesisStreamingDestination(String tableName, String streamArn, String precision,
String region) {
TableDefinition table = dynamoDbService.describeTable(tableName, region);
String resolvedTableName = table.getTableName();
String streamName = streamArn.substring(streamArn.lastIndexOf('/') + 1);
try {
kinesisService.describeStream(streamName, region);
kinesisService.describeStreamByArn(streamArn, region);
} catch (AwsException e) {
throw new AwsException("ResourceNotFoundException",
"Kinesis stream not found: " + streamArn, 400);
@@ -568,7 +568,7 @@ public class NativeDynamoDbTableService {
*
* @return a snapshot of what this call left on the destination, with the canonical table name
*/
KinesisDestination disableKinesisStreamingDestination(String tableName, String streamArn, String region) {
public KinesisDestination disableKinesisStreamingDestination(String tableName, String streamArn, String region) {
TableDefinition table = dynamoDbService.describeTable(tableName, region);
String resolvedTableName = table.getTableName();
@@ -595,6 +595,35 @@ public class NativeDynamoDbTableService {
return disabled;
}
/**
* Changes the precision of an active destination in place, as UpdateKinesisStreamingDestination
* does. Forwarding never stops: records already captured are still delivered, and the forwarder
* stamps each later write with the new precision.
*
* @param precision an already validated ApproximateCreationDateTimePrecision
* @return a snapshot of what this call left on the destination, with the canonical table name
*/
public KinesisDestination updateKinesisStreamingDestination(String tableName, String streamArn, String precision,
String region) {
TableDefinition table = dynamoDbService.describeTable(tableName, region);
String resolvedTableName = table.getTableName();
Optional<KinesisStreamingDestination> existing = table.findKinesisStreamingDestination(streamArn);
if (existing.isEmpty()) {
throw new AwsException("ResourceNotFoundException",
"Kinesis streaming destination not found for stream: " + streamArn, 400);
}
if (!"ACTIVE".equals(existing.get().getDestinationStatus())) {
throw new AwsException("ValidationException",
"Kinesis streaming destination is not active for stream: " + streamArn, 400);
}
existing.get().setApproximateCreationDateTimePrecision(precision);
KinesisDestination updated = new KinesisDestination(resolvedTableName, streamArn, "ACTIVE", precision);
dynamoDbService.persistTable(resolvedTableName, table, region);
return updated;
}
/** The AWS managed key a table reports when SSE is KMS and no customer key was given. */
static String defaultKmsMasterKeyArn(String region) {
return AwsArnUtils.Arn.of("kms", region, DEFAULT_ACCOUNT_ID,
@@ -13,6 +13,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
@@ -23,6 +24,7 @@ import io.github.hectorvent.floci.services.dynamodb.model.GlobalSecondaryIndex;
import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement;
import io.github.hectorvent.floci.services.dynamodb.model.LocalSecondaryIndex;
import io.github.hectorvent.floci.services.dynamodb.model.TableDefinition;
import io.github.hectorvent.floci.services.kinesis.KinesisService;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Typed;
import jakarta.inject.Inject;
@@ -58,30 +60,35 @@ public class DynamoDbLocalBackend implements DynamoDbBackend {
private static final Duration READINESS_BUDGET = Duration.ofSeconds(30);
private static final Scope PROBE = new Scope("000000000000", "us-east-1"); // partition-literal: readiness probe namespace, Local accepts any region
private static final String REPLICAS_UNSUPPORTED = "Replicas are not supported by the DynamoDB Local backend";
private static final String KINESIS_DESTINATIONS_UNSUPPORTED =
"Kinesis streaming destinations are not supported by the DynamoDB Local backend";
private static final Pattern PARTITION = Pattern.compile(AwsArnUtils.PARTITION_REGEX);
private static final List<String> PUBLIC_ARN_FIELDS = List.of("TableArn", "IndexArn", "LatestStreamArn",
"StreamArn", "LastEvaluatedStreamArn", "message", "Message");
private final DynamoDbLocalClient client;
private final AccountAwareStorageBackend<Map<String, String>> tags;
private final KinesisService kinesisService;
private final ObjectMapper objectMapper;
private final ObjectMapper aws;
private final Duration readiness;
@Inject
public DynamoDbLocalBackend(EmulatorConfig config, StorageFactory storageFactory, ObjectMapper objectMapper) {
public DynamoDbLocalBackend(EmulatorConfig config, StorageFactory storageFactory, KinesisService kinesisService,
ObjectMapper objectMapper) {
this(new DynamoDbLocalClient(validatedEndpoint(config.services().dynamodb().localEndpoint()),
Duration.ofSeconds(config.services().dynamodb().localConnectTimeoutSeconds()),
Duration.ofSeconds(config.services().dynamodb().localRequestTimeoutSeconds()), objectMapper),
storageFactory.create("dynamodb", "dynamodb-local-tags.json",
new TypeReference<Map<String, Map<String, String>>>() {}),
objectMapper, READINESS_BUDGET);
kinesisService, objectMapper, READINESS_BUDGET);
}
DynamoDbLocalBackend(DynamoDbLocalClient client, AccountAwareStorageBackend<Map<String, String>> tags,
ObjectMapper objectMapper, Duration readiness) {
KinesisService kinesisService, ObjectMapper objectMapper, Duration readiness) {
this.client = client;
this.tags = tags;
this.kinesisService = kinesisService;
this.objectMapper = objectMapper;
this.aws = objectMapper.copy().setPropertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE);
this.readiness = readiness;
@@ -536,6 +543,39 @@ public class DynamoDbLocalBackend implements DynamoDbBackend {
return key(scope.region(), name);
}
/**
* DynamoDB Local has no Kinesis forwarding. The three destination calls leave the table as it is
* and log a warning, so a template declaring {@code KinesisStreamSpecification} deploys on this
* backend without forwarding. Enabling still needs the stream to exist, as on AWS.
*/
@Override
public TableDefinition enableKinesisStreamingDestination(Scope scope, String tableName, String streamArn,
String precision) {
try {
RequestScopes.runAs(scope.accountId(), () -> kinesisService.describeStreamByArn(streamArn, scope.region()));
} catch (AwsException e) {
throw new AwsException("ResourceNotFoundException", "Kinesis stream not found: " + streamArn, 400);
}
return ignoredKinesisDestinationCall(scope, tableName, streamArn);
}
@Override
public TableDefinition disableKinesisStreamingDestination(Scope scope, String tableName, String streamArn) {
return ignoredKinesisDestinationCall(scope, tableName, streamArn);
}
@Override
public TableDefinition updateKinesisStreamingDestination(Scope scope, String tableName, String streamArn,
String precision) {
return ignoredKinesisDestinationCall(scope, tableName, streamArn);
}
private TableDefinition ignoredKinesisDestinationCall(Scope scope, String tableName, String streamArn) {
LOG.warnv("{0}; the destination {1} of table {2} is ignored", KINESIS_DESTINATIONS_UNSUPPORTED, streamArn,
tableName);
return describeTable(scope, tableName);
}
@Override
public TableDefinition applyReplicaUpdates(Scope scope, String tableName, List<String> addRegions,
List<String> removeRegions) {
@@ -38,6 +38,14 @@ public interface DynamoDbTableAccess {
TableDefinition disableStream(Scope scope, String tableName);
TableDefinition enableKinesisStreamingDestination(Scope scope, String tableName, String streamArn,
String precision);
TableDefinition disableKinesisStreamingDestination(Scope scope, String tableName, String streamArn);
TableDefinition updateKinesisStreamingDestination(Scope scope, String tableName, String streamArn,
String precision);
TimeToLive timeToLive(Scope scope, String tableName);
void updateTimeToLive(Scope scope, String tableName, String attributeName, boolean enabled);
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.dynamodb.DynamoDbStreamService;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbTtlService;
import io.github.hectorvent.floci.services.dynamodb.NativeDynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.NativeDynamoDbStreamsJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.NativeDynamoDbTableService;
import io.github.hectorvent.floci.services.dynamodb.model.AttributeDefinition;
import io.github.hectorvent.floci.services.dynamodb.model.GlobalSecondaryIndex;
import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement;
@@ -34,6 +35,7 @@ public class NativeDynamoDbBackend implements DynamoDbBackend {
private final NativeDynamoDbJsonHandler jsonHandler;
private final NativeDynamoDbStreamsJsonHandler streamsHandler;
private final NativeDynamoDbTableService tableService;
private final DynamoDbService dynamoDbService;
private final DynamoDbStreamService streamService;
private final DynamoDbTtlService ttlService;
@@ -42,10 +44,12 @@ public class NativeDynamoDbBackend implements DynamoDbBackend {
@Inject
public NativeDynamoDbBackend(NativeDynamoDbJsonHandler jsonHandler,
NativeDynamoDbStreamsJsonHandler streamsHandler,
NativeDynamoDbTableService tableService,
DynamoDbService dynamoDbService, DynamoDbStreamService streamService,
DynamoDbTtlService ttlService, ObjectMapper objectMapper) {
this.jsonHandler = jsonHandler;
this.streamsHandler = streamsHandler;
this.tableService = tableService;
this.dynamoDbService = dynamoDbService;
this.streamService = streamService;
this.ttlService = ttlService;
@@ -193,6 +197,32 @@ public class NativeDynamoDbBackend implements DynamoDbBackend {
return RequestScopes.callAs(scope.accountId(), () -> dynamoDbService.disableStream(tableName, scope.region()));
}
@Override
public TableDefinition enableKinesisStreamingDestination(Scope scope, String tableName, String streamArn,
String precision) {
return RequestScopes.callAs(scope.accountId(), () -> {
tableService.enableKinesisStreamingDestination(tableName, streamArn, precision, scope.region());
return dynamoDbService.describeTable(tableName, scope.region());
});
}
@Override
public TableDefinition disableKinesisStreamingDestination(Scope scope, String tableName, String streamArn) {
return RequestScopes.callAs(scope.accountId(), () -> {
tableService.disableKinesisStreamingDestination(tableName, streamArn, scope.region());
return dynamoDbService.describeTable(tableName, scope.region());
});
}
@Override
public TableDefinition updateKinesisStreamingDestination(Scope scope, String tableName, String streamArn,
String precision) {
return RequestScopes.callAs(scope.accountId(), () -> {
tableService.updateKinesisStreamingDestination(tableName, streamArn, precision, scope.region());
return dynamoDbService.describeTable(tableName, scope.region());
});
}
// Mirrors the native DescribeTimeToLive: no attribute name is reported while TTL is off.
@Override
public TimeToLive timeToLive(Scope scope, String tableName) {
@@ -207,6 +207,19 @@ public class KinesisService implements ResourceProvider {
return resolveStreamForAccount(accountId, streamName, region);
}
/**
* The stream whose own ARN is {@code streamArn}, in the caller's account and {@code region}. A
* name alone, or an ARN for another account, region or resource type, names no stream here.
*/
public KinesisStream describeStreamByArn(String streamArn, String region) {
String streamName = streamArn.substring(streamArn.lastIndexOf('/') + 1);
KinesisStream stream = resolveStream(streamName, region);
if (!streamArn.equals(stream.getStreamArn())) {
throw new AwsException("ResourceNotFoundException", "Stream " + streamName + " not found", 400);
}
return stream;
}
public KinesisConsumer registerStreamConsumer(String streamArn, String consumerName, String region) {
String consumerArn = streamArn + "/consumer/" + consumerName + ":" + System.currentTimeMillis();
KinesisConsumer consumer = new KinesisConsumer(consumerName, consumerArn, streamArn);