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

feat: support import existing table #2605

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,27 @@ const processOnEvent = async (event: AWSCDKAsyncCustomResource.OnEventRequest):
let result;
switch (event.RequestType) {
case 'Create':
const tableName = tableDef.tableName;
if (tableName && (await doesTableExist(tableName))) {
// Inspect and use the state of the existing table
console.log(`Inspecting table with name: ${tableName}`);
const describeTableResult = await ddbClient.describeTable({ TableName: tableName });
if (!describeTableResult.Table) {
throw new Error(`Failed to inspect status of existing table ${tableName} to import`);
}
log('Current table state: ', describeTableResult);
result = {
PhysicalResourceId: describeTableResult.Table.TableName,
Data: {
TableArn: describeTableResult.Table.TableArn,
TableStreamArn: describeTableResult.Table.LatestStreamArn,
TableName: describeTableResult.Table.TableName,
},
};
console.log('Returning result: ', result);
return result;
}

console.log('Initiating CREATE event');
const createTableInput = toCreateTableInput(tableDef);
console.log('Create Table Params: ', createTableInput);
Expand Down
Loading