-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fixed idempotency issue by first checking if table does not exist #1035
Closed
alantao912
wants to merge
5
commits into
nextjs
from
1033-bug-create-table-command-in-appstackts-not-idempotent
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule dlp-cli
updated
48 files
22 changes: 22 additions & 0 deletions
22
serverless/packages/functions/src/dbutils/get_all_tablenames.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
export async function get_all_tablenames() : Promise<string[]> { | ||
const AWS = require("aws-sdk"); | ||
AWS.config.update({region:'us-east-1'}); | ||
let dynamodb = new AWS.DynamoDB(); | ||
|
||
let params = | ||
{ | ||
ExclusiveStartTableName: null | ||
}; | ||
let tables: string[] = []; | ||
while (true) { | ||
let response = await dynamodb.listTables(params).promise(); | ||
tables = tables.concat(response.TableNames); | ||
|
||
if (response.LastEvaluatedTableName === undefined) { | ||
break; | ||
} | ||
params.ExclusiveStartTableName = response.LastEvaluatedTableName; | ||
} | ||
return tables; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { get_all_tablenames } from "./get_all_tablenames"; | ||
|
||
export async function table_exists(table_name: string) : Promise<boolean> { | ||
const tableNames: string[] = await get_all_tablenames(); | ||
return tableNames.indexOf(table_name) !== -1; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { Api, Bucket, StackContext, Table } from "sst/constructs"; | ||
import { Bucket as s3Bucket } from "aws-cdk-lib/aws-s3"; | ||
import { table_exists } from "../packages/functions/src/dbutils/table_exists"; | ||
|
||
export function AppStack({ stack }: StackContext) { | ||
const bucket = new Bucket(stack, "dlp-upload-bucket", { | ||
|
@@ -11,26 +12,29 @@ export function AppStack({ stack }: StackContext) { | |
), | ||
}, | ||
}); | ||
const trainspaceRunTable = new Table(stack, "trainspace-run", { | ||
fields: { | ||
runId: "string", | ||
trainspaceId: "string", | ||
userId: "string", | ||
timestamp: "string", | ||
resultCsvUri: "string", | ||
modelPtUri: "string", | ||
onnxUri: "string", | ||
confusionMatrixUri: "string", | ||
aucRocUri: "string" | ||
}, | ||
primaryIndex: { | ||
partitionKey: "runId", | ||
}, | ||
globalIndexes: { | ||
"TrainspaceIndex": { partitionKey: "trainspaceId", sortKey: "timestamp"}, | ||
"UserIndex": {partitionKey: "userId"} | ||
}, | ||
}); | ||
let trainspaceRunTable = null; | ||
if (!table_exists("trainspace")) { | ||
trainspaceRunTable = new Table(stack, "trainspace-run", { | ||
fields: { | ||
runId: "string", | ||
trainspaceId: "string", | ||
userId: "string", | ||
timestamp: "string", | ||
resultCsvUri: "string", | ||
modelPtUri: "string", | ||
onnxUri: "string", | ||
confusionMatrixUri: "string", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this code work for if I want to update fields of a dynamo table? |
||
aucRocUri: "string" | ||
}, | ||
primaryIndex: { | ||
partitionKey: "runId", | ||
}, | ||
globalIndexes: { | ||
"TrainspaceIndex": { partitionKey: "trainspaceId", sortKey: "timestamp"}, | ||
"UserIndex": {partitionKey: "userId"} | ||
}, | ||
}); | ||
} | ||
const api = new Api(stack, "Api", { | ||
authorizers: { | ||
FirebaseAuthorizer: { | ||
|
@@ -71,7 +75,7 @@ export function AppStack({ stack }: StackContext) { | |
api.getFunction("GET /datasets/user/{type}/{filename}/columns") | ||
?.functionName ?? "", | ||
TrainspaceRunTableName: { | ||
value: trainspaceRunTable.tableName | ||
value: "trainspace" | ||
} | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: can you please run Prettier for all changed files? There are some aesthetic issues; for example, each file should end with a blank line.
We'll need to update our checks to also check /serverless in addition to /frontend