Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of table migrations #11

Closed
domdomegg opened this issue Aug 6, 2023 · 1 comment
Closed

Improve handling of table migrations #11

domdomegg opened this issue Aug 6, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@domdomegg
Copy link
Member

Currently createTable attempts to slightly tweak the CloudFormation resource and then submit this to the CreateTable API:

createTable(dynamodb, migration) {
return new Promise((resolve, reject) => {
if (migration.StreamSpecification && migration.StreamSpecification.StreamViewType) {
migration.StreamSpecification.StreamEnabled = true;
}
if (migration.TimeToLiveSpecification) {
delete migration.TimeToLiveSpecification;
}
if (migration.SSESpecification) {
migration.SSESpecification.Enabled = migration.SSESpecification.SSEEnabled;
delete migration.SSESpecification.SSEEnabled;
}
if (migration.PointInTimeRecoverySpecification) {
delete migration.PointInTimeRecoverySpecification;
}
if (migration.Tags) {
delete migration.Tags;
}
if (migration.BillingMode === "PAY_PER_REQUEST") {
delete migration.BillingMode;
const defaultProvisioning = {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5
};
migration.ProvisionedThroughput = defaultProvisioning;
if (migration.GlobalSecondaryIndexes) {
migration.GlobalSecondaryIndexes.forEach((gsi) => {
gsi.ProvisionedThroughput = defaultProvisioning;
});
}
}
if(migration.ContributorInsightsSpecification) {
delete migration.ContributorInsightsSpecification;
}
if(migration.GlobalSecondaryIndexes) {
migration.GlobalSecondaryIndexes.forEach((gsi) => {
if (gsi.ContributorInsightsSpecification) {
delete gsi.ContributorInsightsSpecification;
}
});
}
dynamodb.raw.createTable(migration, (err) => {
if (err) {
if (err.name === 'ResourceInUseException') {
this.serverlessLog(`DynamoDB - Warn - table ${migration.TableName} already exists`);
resolve();
} else {
this.serverlessLog("DynamoDB - Error - ", err);
reject(err);
}
} else {
this.serverlessLog("DynamoDB - created table " + migration.TableName);
resolve(migration);
}
});
});
}

However, this often doesn't comply with the API spec when adding extra things to CloudFormation (see #1, #10) and https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_CreateTable.html.

I think a better approach would be to just construct the API request body directly, rather than try to massage the CloudFormation into the API body. We could add warnings for unsupported properties.

@domdomegg
Copy link
Member Author

Unfortunately on further investigation I think we are always going to have to do some translation of CloudFormation into AWS DynamoDB API calls given the two really do differ. Closing as not possible for now.

@domdomegg domdomegg closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant