mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): honor DynamoDB on-demand billing mode (#7931)
This commit is contained in:
1 parent
77cb014f9d
commit
b3de4b3179
11 files changed
+52
-9
No files matched your search
+4
-1
@@ -230,10 +230,13 @@ public class DynamoDbCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
|
||||
Scope scope = new Scope(ctx.accountId(), region);
|
||||
boolean onDemand = "PAY_PER_REQUEST".equals(ctx.resolveOptional(props, "BillingMode"));
|
||||
TableDefinition table;
|
||||
boolean created = false;
|
||||
try {
|
||||
table = dynamoDb.tables().createTable(scope, tableName, keySchema, attrDefs, null, null, gsis, lsis);
|
||||
table = onDemand
|
||||
? dynamoDb.tables().createOnDemandTable(scope, tableName, keySchema, attrDefs, gsis, lsis)
|
||||
: dynamoDb.tables().createTable(scope, tableName, keySchema, attrDefs, null, null, gsis, lsis);
|
||||
created = true;
|
||||
} catch (AwsException e) {
|
||||
if (!"ResourceInUseException".equals(e.getErrorCode())) {
|
||||
|
||||
@@ -635,7 +635,11 @@ public class DynamoDbService {
|
||||
|
||||
TableDefinition table = new TableDefinition(tableName, keySchema, attributeDefinitions,
|
||||
region, regionResolver.getAccountId());
|
||||
if (readCapacity != null && writeCapacity != null) {
|
||||
if ("PAY_PER_REQUEST".equals(billingMode)) {
|
||||
table.setBillingMode(billingMode);
|
||||
table.getProvisionedThroughput().setReadCapacityUnits(0L);
|
||||
table.getProvisionedThroughput().setWriteCapacityUnits(0L);
|
||||
} else if (readCapacity != null && writeCapacity != null) {
|
||||
table.getProvisionedThroughput().setReadCapacityUnits(readCapacity);
|
||||
table.getProvisionedThroughput().setWriteCapacityUnits(writeCapacity);
|
||||
}
|
||||
|
||||
@@ -144,11 +144,7 @@ public class NativeDynamoDbTableService {
|
||||
|
||||
table.setDeletionProtectionEnabled(Boolean.TRUE.equals(settings.deletionProtectionEnabled()));
|
||||
|
||||
if ("PAY_PER_REQUEST".equals(billingMode)) {
|
||||
table.setBillingMode("PAY_PER_REQUEST");
|
||||
table.getProvisionedThroughput().setReadCapacityUnits(0L);
|
||||
table.getProvisionedThroughput().setWriteCapacityUnits(0L);
|
||||
} else {
|
||||
if (!"PAY_PER_REQUEST".equals(billingMode)) {
|
||||
table.setBillingMode("PROVISIONED");
|
||||
}
|
||||
|
||||
|
||||
@@ -411,6 +411,15 @@ public class DynamoDbLocalBackend implements DynamoDbBackend {
|
||||
return table(call(scope, "CreateTable", body).path("TableDescription"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDefinition createOnDemandTable(Scope scope, String tableName, List<KeySchemaElement> keySchema,
|
||||
List<AttributeDefinition> attributeDefinitions,
|
||||
List<GlobalSecondaryIndex> globalSecondaryIndexes,
|
||||
List<LocalSecondaryIndex> localSecondaryIndexes) {
|
||||
return createTable(scope, tableName, keySchema, attributeDefinitions, null, null, globalSecondaryIndexes,
|
||||
localSecondaryIndexes);
|
||||
}
|
||||
|
||||
private ObjectNode index(ArrayNode indexes, String indexName, List<KeySchemaElement> keySchema,
|
||||
String projectionType, List<String> nonKeyAttributes) {
|
||||
ObjectNode index = indexes.addObject().put("IndexName", indexName);
|
||||
|
||||
@@ -24,6 +24,11 @@ public interface DynamoDbTableAccess {
|
||||
Long writeCapacity, List<GlobalSecondaryIndex> globalSecondaryIndexes,
|
||||
List<LocalSecondaryIndex> localSecondaryIndexes);
|
||||
|
||||
TableDefinition createOnDemandTable(Scope scope, String tableName, List<KeySchemaElement> keySchema,
|
||||
List<AttributeDefinition> attributeDefinitions,
|
||||
List<GlobalSecondaryIndex> globalSecondaryIndexes,
|
||||
List<LocalSecondaryIndex> localSecondaryIndexes);
|
||||
|
||||
TableDefinition describeTable(Scope scope, String tableName);
|
||||
|
||||
Optional<TableDefinition> findTable(Scope scope, String tableName);
|
||||
|
||||
@@ -171,6 +171,16 @@ public class NativeDynamoDbBackend implements DynamoDbBackend {
|
||||
scope.region()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDefinition createOnDemandTable(Scope scope, String tableName, List<KeySchemaElement> keySchema,
|
||||
List<AttributeDefinition> attributeDefinitions,
|
||||
List<GlobalSecondaryIndex> globalSecondaryIndexes,
|
||||
List<LocalSecondaryIndex> localSecondaryIndexes) {
|
||||
return RequestScopes.callAs(scope.accountId(), () -> dynamoDbService.createTable(tableName, keySchema,
|
||||
attributeDefinitions, null, null, globalSecondaryIndexes, localSecondaryIndexes,
|
||||
List.of(), "PAY_PER_REQUEST", scope.region()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDefinition describeTable(Scope scope, String tableName) {
|
||||
return RequestScopes.callAs(scope.accountId(), () -> dynamoDbService.describeTable(tableName, scope.region()));
|
||||
|
||||
Reference in new issue
Block a user