fix(cloudformation): apply TimeToLiveSpecification on DynamoDB tables (#4951)

* feat(dynamodb): add typed time-to-live operations to the table access

DynamoDbTableAccess gains timeToLive and updateTimeToLive next to the
stream operations. The native engine reads the TTL flag and attribute
from the table definition and calls DynamoDbService.updateTimeToLive
under the scope's account; the Local engine sends DescribeTimeToLive
and UpdateTimeToLive.

* fix(cloudformation): apply TimeToLiveSpecification on DynamoDB tables

An AWS::DynamoDB::Table declaring TimeToLiveSpecification reached
CREATE_COMPLETE while DescribeTimeToLive answered DISABLED, because the
provisioner never read the property.

The provisioner now reconciles TTL against what the table reports, so
UpdateTimeToLive is called only when the setting differs: enabled turns
it on, Enabled false or a block removed on an update turns it off with
the current attribute name, and renaming an enabled attribute fails with
the DynamoDB ValidationException before anything changes. Enabled with
no AttributeName fails with ValidationError before the table is created.

An in-place table update now records the tags, stream and TTL setting
it replaces, and rollbackUpdate puts all three back, so a stack whose
update fails on a later resource ends UPDATE_ROLLBACK_COMPLETE instead
of UPDATE_ROLLBACK_FAILED. A restore that throws keeps the snapshot.

* fix(cloudformation): roll back and clean up failed DynamoDB table provisions

A table's in-place update that failed after its snapshot, for example on
UpdateTimeToLive after the tags and the stream had changed, lost the
snapshot: the engine put the previous resource back and reported
UPDATE_ROLLBACK_COMPLETE with the changes still live. The provisioner
now retains a failed attempt that carries its snapshot, so the engine
hands it to rollbackUpdate. A failure before the snapshot changed
nothing and still uses the engine's restore.

A provision that failed after createTable left the new table behind,
on create and on a replacing update alike. The provisioner now deletes
a table this attempt created, tolerating ResourceNotFoundException, and
never one it adopted or updates in place. A delete that fails is logged
and leaves the physical id and the rollback ownership marker, so the
stack's create rollback retries it. A table recreated because the
update target was gone takes no snapshot, since it has no prior state.

* fix(cloudformation): match the AWS status reasons for invalid TimeToLiveSpecification

Renaming an enabled TTL attribute and enabling TTL without an
AttributeName now fail with the handler message AWS CloudFormation
reports, as measured in eu-west-1, and with its InvalidRequest handler
error code. The resource status reason is the AWS inner text exactly;
the type and logical id prefix are gone, since AWS does not include them.

* fix(cloudformation): scope DynamoDB table TTL to the stack and validate Enabled

- An update leaves TTL alone when neither the template nor the previous
  one declared TimeToLiveSpecification, so TTL enabled outside the stack
  survives, as on AWS.
- A TimeToLiveSpecification without Enabled, or with a non-Boolean one,
  fails model validation before the table is created.
- A replacing update whose created table cannot be deleted reports a
  rollback failure naming the table instead of leaving it untracked.
This commit is contained in:
Mario Toffia authored and GitHub committed 2026-10-14 15:57:36 -04:00
1 parent 6e8a083d2b
commit a5228a0bf7
13 files changed
+1161 -43

No files matched your search

@@ -196,6 +196,14 @@ public final class CfnRollback {
*/
public static final String REPLACEMENT_CLEANUP_ATTR = "__FlociReplacementCleanup";
/**
* Holds the tags, stream setting and time-to-live setting a DynamoDB table carried before an
* in-place update changed them, with the account and region that address it, so a failed
* stack update can put all three back. Written by {@code DynamoDbCfnProvisioner} before its
* first mutating call and spent by its {@code rollbackUpdate}.
*/
public static final String DYNAMODB_TABLE_UPDATE_SNAPSHOT_ATTR = "__FlociDynamoDbTableUpdateSnapshot";
/**
* Holds the attributes and tags a queue carried before an in-place update changed them,
* so a failed stack update can restore them.
@@ -1,11 +1,15 @@
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.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
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;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbOperations.Scope;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbTableAccess.TimeToLive;
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;
@@ -17,6 +21,7 @@ import org.jboss.logging.Logger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -35,6 +40,11 @@ import java.util.Set;
* applied directly against the DynamoDB service rather than through the async CDK Provider
* framework, and its delete removes the replica the same way instead of invoking the handler.
* {@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.
*/
@ApplicationScoped
public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
@@ -44,6 +54,8 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
static final String REPLICA = "Custom::DynamoDBReplica";
private static final Logger LOG = Logger.getLogger(DynamoDbCfnProvisioner.class);
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final TimeToLive TIME_TO_LIVE_OFF = new TimeToLive(false, null);
private static final String REPLICA_TABLE_NAME_ATTR = "TableName";
private static final String REPLICA_REGION_ATTR = "__FlociDynamoDbReplicaRegion";
@@ -102,6 +114,8 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
}
private void provisionTable(StackResource r, JsonNode props, ProvisionContext ctx) {
// A snapshot describes the update in flight; one an earlier update left behind is stale.
r.getAttributes().remove(CfnRollback.DYNAMODB_TABLE_UPDATE_SNAPSHOT_ATTR);
CloudFormationTemplateEngine engine = ctx.engine();
String region = ctx.region();
// TableName is create-only, so an update without one must keep the name generated on
@@ -109,6 +123,12 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
// UpdateStack and re-pointed Ref at it.
String tableName = ctx.stablePhysicalName(ctx.resolveOptional(props, "TableName"),
r.getLogicalId(), TABLE_NAME_MAX_LENGTH, false);
JsonNode ttlSpec = props != null ? engine.resolveNode(props.get("TimeToLiveSpecification")) : null;
boolean ttlDeclared = ttlSpec != null && ttlSpec.isObject();
// A stack that never declared TTL leaves it alone, as AWS does, so TTL set outside the stack
// 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;
List<KeySchemaElement> keySchema = new ArrayList<>();
List<AttributeDefinition> attrDefs = new ArrayList<>();
@@ -184,8 +204,10 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
Scope scope = new Scope(ctx.accountId(), region);
TableDefinition table;
boolean created = false;
try {
table = dynamoDb.tables().createTable(scope, tableName, keySchema, attrDefs, null, null, gsis, lsis);
created = true;
} catch (AwsException e) {
if (!"ResourceInUseException".equals(e.getErrorCode())) {
throw e;
@@ -193,48 +215,103 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
table = dynamoDb.tables().describeTable(scope, tableName);
}
Map<String, String> tags = parseCfnTags(props != null ? props.get("Tags") : null, engine);
List<String> staleTags = ProvisionContext.staleTagKeys(
dynamoDb.tables().listTagsOfResource(scope, table.getTableArn()), tags);
if (!staleTags.isEmpty()) {
dynamoDb.tables().untagResource(scope, table.getTableArn(), staleTags);
}
if (!tags.isEmpty()) {
dynamoDb.tables().tagResource(scope, table.getTableArn(), tags);
}
try {
// TTL is read when the template declares it, and on an in-place update for the rollback
// snapshot, so UpdateTimeToLive is called only when something differs. A rename of an
// enabled TTL attribute fails here, and the snapshot is taken here, before anything changes.
// A table this attempt created has no prior state to snapshot; a failure deletes it instead.
boolean inPlaceUpdate = !created && ctx.reusesPriorEntity(tableName);
TimeToLive currentTtl = null;
if (ttlDeclared || inPlaceUpdate) {
currentTtl = dynamoDb.tables().timeToLive(scope, tableName);
requireTimeToLiveChangeAllowed(currentTtl, desiredTtl);
}
Map<String, String> currentTags = dynamoDb.tables().listTagsOfResource(scope, table.getTableArn());
if (inPlaceUpdate && TABLE.equals(r.getResourceType())) {
snapshotBeforeUpdate(r, scope, tableName, table, currentTags, currentTtl);
}
// A template that declares StreamSpecification wants a stream. Unlike the DynamoDB API,
// the CloudFormation property carries no StreamEnabled flag: declaring the block IS the
// request, so its presence alone turns the stream on. Without this the table is created
// streamless and an event source mapping polls its ARN forever.
//
// Removing the block on an update is the inverse request: the stream is reconciled off,
// or a table updated out of streaming would keep emitting records to whatever still holds
// its ARN.
JsonNode streamSpec = props != null ? props.path("StreamSpecification") : null;
if (streamSpec != null && streamSpec.isObject()) {
String viewType = streamSpec.has("StreamViewType")
? engine.resolve(streamSpec.get("StreamViewType"))
: null;
table = dynamoDb.tables().enableStream(scope, tableName, viewType);
} else if (table.isStreamEnabled()) {
table = dynamoDb.tables().disableStream(scope, tableName);
}
reconcileTags(scope, table.getTableArn(), currentTags,
parseCfnTags(props != null ? props.get("Tags") : null, engine));
r.setPhysicalId(tableName);
r.getAttributes().put("Arn", table.getTableArn());
// Only the global table's registry schema declares TableId read-only; a plain table exposes
// Arn and StreamArn alone, so publishing it there would accept a Fn::GetAtt CloudFormation
// rejects. DescribeTable reports the same value, so Fn::GetAtt and the API agree.
if (GLOBAL_TABLE.equals(r.getResourceType())) {
r.getAttributes().put("TableId", table.getTableId());
reconcileGlobalTableReplicas(tableName, props, ctx);
// A template that declares StreamSpecification wants a stream. Unlike the DynamoDB API,
// the CloudFormation property carries no StreamEnabled flag: declaring the block IS the
// request, so its presence alone turns the stream on. Without this the table is created
// streamless and an event source mapping polls its ARN forever.
//
// Removing the block on an update is the inverse request: the stream is reconciled off,
// or a table updated out of streaming would keep emitting records to whatever still holds
// its ARN.
JsonNode streamSpec = props != null ? props.path("StreamSpecification") : null;
if (streamSpec != null && streamSpec.isObject()) {
String viewType = streamSpec.has("StreamViewType")
? engine.resolve(streamSpec.get("StreamViewType"))
: null;
table = dynamoDb.tables().enableStream(scope, tableName, viewType);
} else if (table.isStreamEnabled()) {
table = dynamoDb.tables().disableStream(scope, tableName);
}
// TimeToLiveSpecification is reconciled like the stream: declaring it enabled turns TTL on
// for the attribute, and Enabled false or a block removed on an update turns it off.
if (ttlManaged && currentTtl != null) {
reconcileTimeToLive(scope, tableName, currentTtl, desiredTtl);
}
r.setPhysicalId(tableName);
r.getAttributes().put("Arn", table.getTableArn());
// Only the global table's registry schema declares TableId read-only; a plain table exposes
// Arn and StreamArn alone, so publishing it there would accept a Fn::GetAtt CloudFormation
// rejects. DescribeTable reports the same value, so Fn::GetAtt and the API agree.
if (GLOBAL_TABLE.equals(r.getResourceType())) {
r.getAttributes().put("TableId", table.getTableId());
reconcileGlobalTableReplicas(tableName, props, ctx);
}
// Only a live stream has an ARN worth handing to Fn::GetAtt. Publishing one unconditionally
// resolved to nothing on a streamless table; publishing the retained ARN of a stream that
// has since been switched off would resolve to something no longer running. An update
// starts from the previous attributes, so the stale entry has to be removed rather than
// merely left unwritten.
publishStreamArn(r, table);
} catch (RuntimeException failure) {
// A table this attempt created would outlive the failure otherwise: the create rollback
// deletes only a resource that carries its physical id, and a replacing update puts the
// previous resource back. An adopted table, or one an in-place update changes, is kept.
// DeletionPolicy Retain does not keep it: AWS validates the tags and the stream inside
// CreateTable, so on AWS such a failure leaves no table to retain.
if (created) {
deleteCreatedTable(r, scope, tableName, ctx.isUpdate(), failure);
}
throw failure;
}
// Only a live stream has an ARN worth handing to Fn::GetAtt. Publishing one unconditionally
// resolved to nothing on a streamless table; publishing the retained ARN of a stream that
// has since been switched off would resolve to something no longer running. An update
// starts from the previous attributes, so the stale entry has to be removed rather than
// merely left unwritten.
}
/**
* Deletes the table a failed provision created. A delete that fails on create leaves the table
* owned by the resource, so the stack's create rollback retries it. On a replacing update the
* engine puts the previous resource back and never learns this table, so the failure is
* reported as a rollback failure that names it.
*/
private void deleteCreatedTable(StackResource r, Scope scope, String tableName, boolean update,
RuntimeException failure) {
try {
CfnDeletes.safeDelete("DynamoDB table", tableName,
() -> dynamoDb.tables().deleteTable(scope, tableName), "ResourceNotFoundException");
} catch (RuntimeException cleanupFailure) {
failure.addSuppressed(cleanupFailure);
String reason = "Could not delete DynamoDB table " + tableName + ", created for "
+ r.getLogicalId() + " by a failed provision: " + cleanupFailure.getMessage();
LOG.warnv("{0}", reason);
if (update) {
r.getAttributes().put(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR, reason);
} else {
r.setPhysicalId(tableName);
r.getAttributes().put(CfnRollback.ROLLBACK_OWNED_ATTR, "true");
}
}
}
private static void publishStreamArn(StackResource r, TableDefinition table) {
if (table.isStreamEnabled() && table.getStreamArn() != null) {
r.getAttributes().put("StreamArn", table.getStreamArn());
} else {
@@ -242,6 +319,141 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
}
}
private void reconcileTags(Scope scope, String tableArn, Map<String, String> current,
Map<String, String> desired) {
List<String> staleTags = ProvisionContext.staleTagKeys(current, desired);
if (!staleTags.isEmpty()) {
dynamoDb.tables().untagResource(scope, tableArn, staleTags);
}
if (!desired.isEmpty()) {
dynamoDb.tables().tagResource(scope, tableArn, desired);
}
}
/**
* {@code Enabled} is required and may arrive as the string {@code "true"}, so it goes through
* the engine. Both checks run before the table is created, as AWS validates the template
* before any resource exists. The failures carry the error code AWS CloudFormation reports.
*/
private static TimeToLive declaredTimeToLive(JsonNode spec, CloudFormationTemplateEngine engine) {
JsonNode enabledNode = spec.get("Enabled");
if (enabledNode == null || enabledNode.isNull()) {
throw new AwsException("InvalidRequest",
"Model validation failed (#/TimeToLiveSpecification: required key [Enabled] not found)", 400);
}
String enabledText = engine.resolve(enabledNode);
if (!"true".equalsIgnoreCase(enabledText) && !"false".equalsIgnoreCase(enabledText)) {
throw new AwsException("InvalidRequest", "Model validation failed (#/TimeToLiveSpecification/Enabled:"
+ " expected type: Boolean, found: String)", 400);
}
boolean enabled = Boolean.parseBoolean(enabledText);
String attributeName = spec.has("AttributeName") ? engine.resolve(spec.get("AttributeName")) : null;
if (enabled && (attributeName == null || attributeName.isBlank())) {
throw new AwsException("InvalidRequest", "Invalid request provided: AttributeName property of"
+ " TimeToLiveSpecification is required when TTL status is enabled or when enabling TTL.", 400);
}
return new TimeToLive(enabled, attributeName);
}
/**
* DynamoDB refuses to enable a second attribute while one is enabled, and CloudFormation
* renames one by disabling TTL in an update and enabling the new attribute in a later one. The
* failure carries the handler message and error code AWS CloudFormation reports.
*/
private static void requireTimeToLiveChangeAllowed(TimeToLive current, TimeToLive desired) {
if (desired.enabled() && current.enabled() && !desired.attributeName().equals(current.attributeName())) {
throw new AwsException("InvalidRequest", "Invalid request provided: Cannot change time-to-live attribute"
+ " name. To update this property, you must first disable TTL then enable TTL with the new"
+ " attribute name.", 400);
}
}
/** Calls UpdateTimeToLive only when the table's setting differs; disabling names the current attribute. */
private void reconcileTimeToLive(Scope scope, String tableName, TimeToLive current, TimeToLive desired) {
if (desired.enabled() && !current.enabled()) {
dynamoDb.tables().updateTimeToLive(scope, tableName, desired.attributeName(), true);
} else if (!desired.enabled() && current.enabled()) {
dynamoDb.tables().updateTimeToLive(scope, tableName, current.attributeName(), false);
}
}
/**
* 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.
*/
private static void snapshotBeforeUpdate(StackResource r, Scope scope, String tableName, TableDefinition table,
Map<String, String> tags, TimeToLive ttl) {
ObjectNode snapshot = MAPPER.createObjectNode();
snapshot.put("accountId", scope.accountId());
snapshot.put("region", scope.region());
snapshot.put("tableName", tableName);
ObjectNode tagsNode = snapshot.putObject("tags");
tags.forEach(tagsNode::put);
snapshot.put("streamEnabled", table.isStreamEnabled());
snapshot.put("streamViewType", table.getStreamViewType());
snapshot.put("ttlEnabled", ttl.enabled());
snapshot.put("ttlAttributeName", ttl.attributeName());
r.getAttributes().put(CfnRollback.DYNAMODB_TABLE_UPDATE_SNAPSHOT_ATTR, snapshot.toString());
}
/**
* An in-place update that failed after its snapshot may already have changed the table, so the
* engine keeps this attempt for {@link #rollbackUpdate} instead of putting the previous resource
* back over it. A failure before the snapshot changed nothing and is left to the engine.
*/
@Override
public boolean retainsFailedUpdateState(StackResource resource) {
return resource.getAttributes().containsKey(CfnRollback.DYNAMODB_TABLE_UPDATE_SNAPSHOT_ATTR);
}
/**
* 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
* 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.
*/
@Override
public boolean rollbackUpdate(StackResource resource) {
String raw = resource.getAttributes().get(CfnRollback.DYNAMODB_TABLE_UPDATE_SNAPSHOT_ATTR);
if (raw == null) {
return false;
}
JsonNode snapshot;
try {
snapshot = MAPPER.readTree(raw);
} catch (JsonProcessingException e) {
throw new IllegalStateException("Could not read the DynamoDB table update snapshot for "
+ resource.getLogicalId(), e);
}
Scope scope = new Scope(snapshot.path("accountId").asText(), snapshot.path("region").asText());
String tableName = snapshot.path("tableName").asText();
TableDefinition table = dynamoDb.tables().describeTable(scope, tableName);
Map<String, String> tags = new LinkedHashMap<>();
snapshot.path("tags").properties().forEach(tag -> tags.put(tag.getKey(), tag.getValue().asText()));
reconcileTags(scope, table.getTableArn(),
dynamoDb.tables().listTagsOfResource(scope, table.getTableArn()), tags);
if (snapshot.path("streamEnabled").asBoolean()) {
table = dynamoDb.tables().enableStream(scope, tableName, snapshot.path("streamViewType").textValue());
} else if (table.isStreamEnabled()) {
table = dynamoDb.tables().disableStream(scope, tableName);
}
TimeToLive priorTtl = new TimeToLive(snapshot.path("ttlEnabled").asBoolean(),
snapshot.path("ttlAttributeName").textValue());
TimeToLive currentTtl = dynamoDb.tables().timeToLive(scope, tableName);
requireTimeToLiveChangeAllowed(currentTtl, priorTtl);
reconcileTimeToLive(scope, tableName, currentTtl, priorTtl);
publishStreamArn(resource, table);
resource.getAttributes().remove(CfnRollback.DYNAMODB_TABLE_UPDATE_SNAPSHOT_ATTR);
return true;
}
/**
* Reconciles a global table's tracked replica regions to its declared {@code Replicas} property.
* Serves create and update: declared regions absent from the table are added and tracked regions
@@ -476,6 +476,20 @@ public class DynamoDbLocalBackend implements DynamoDbBackend {
return table(call(scope, "UpdateTable", body).path("TableDescription"));
}
@Override
public TimeToLive timeToLive(Scope scope, String tableName) {
JsonNode description = call(scope, "DescribeTimeToLive", body(tableName)).path("TimeToLiveDescription");
return new TimeToLive("ENABLED".equals(text(description, "TimeToLiveStatus")),
text(description, "AttributeName"));
}
@Override
public void updateTimeToLive(Scope scope, String tableName, String attributeName, boolean enabled) {
ObjectNode body = body(tableName);
body.putObject("TimeToLiveSpecification").put("AttributeName", attributeName).put("Enabled", enabled);
call(scope, "UpdateTimeToLive", body);
}
private TableDefinition table(JsonNode description) {
TableDefinition table = aws.convertValue(description, TableDefinition.class);
JsonNode spec = description.path("StreamSpecification");
@@ -15,6 +15,10 @@ import java.util.Optional;
/** Typed table operations for Java consumers that manage DynamoDB tables directly. */
public interface DynamoDbTableAccess {
/** A table's time-to-live setting, as DescribeTimeToLive reports it. */
record TimeToLive(boolean enabled, String attributeName) {
}
TableDefinition createTable(Scope scope, String tableName, List<KeySchemaElement> keySchema,
List<AttributeDefinition> attributeDefinitions, Long readCapacity,
Long writeCapacity, List<GlobalSecondaryIndex> globalSecondaryIndexes,
@@ -34,6 +38,10 @@ public interface DynamoDbTableAccess {
TableDefinition disableStream(Scope scope, String tableName);
TimeToLive timeToLive(Scope scope, String tableName);
void updateTimeToLive(Scope scope, String tableName, String attributeName, boolean enabled);
Map<String, String> listTagsOfResource(Scope scope, String resourceArn);
void tagResource(Scope scope, String resourceArn, Map<String, String> tags);
@@ -193,6 +193,20 @@ public class NativeDynamoDbBackend implements DynamoDbBackend {
return RequestScopes.callAs(scope.accountId(), () -> dynamoDbService.disableStream(tableName, scope.region()));
}
// Mirrors the native DescribeTimeToLive: no attribute name is reported while TTL is off.
@Override
public TimeToLive timeToLive(Scope scope, String tableName) {
TableDefinition table = describeTable(scope, tableName);
boolean enabled = table.isTtlEnabled() && table.getTtlAttributeName() != null;
return new TimeToLive(enabled, enabled ? table.getTtlAttributeName() : null);
}
@Override
public void updateTimeToLive(Scope scope, String tableName, String attributeName, boolean enabled) {
RequestScopes.runAs(scope.accountId(),
() -> dynamoDbService.updateTimeToLive(tableName, attributeName, enabled, scope.region()));
}
@Override
public Map<String, String> listTagsOfResource(Scope scope, String resourceArn) {
return RequestScopes.callAs(scope.accountId(),