Skip to content

Sample that demonstrates how to convert CSV files hosted on COS to data stored in a RDBMS #180

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

Merged
merged 21 commits into from
Apr 21, 2025

Conversation

reggeenr
Copy link
Collaborator

@reggeenr reggeenr commented Apr 6, 2025

This PR provides

  • a sample app that integrates with COS, Secrets Manager and ICD PostgreSQL using trusted profiles.
  • a readme that lists a step-by-step guide to deploy the sample
  • a draw.io that contains useful diagrams and graphics explaining this sample

@reggeenr reggeenr requested a review from SaschaSchwarze0 April 6, 2025 21:58
const pgClient = await getPgClient(secretsManager, smPgSecretId);

//
// Perform a single SQL insert statement per user
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to do bulk inserts to reduce load on the database.

Conceptually, using upserts here might also make sense, but does not need to be changed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would a lot of sense for this specific use case. But at the same time I wanted to mimic a flow in which complex information is processed and handled line be line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about your comment. While I kept the loop and individual db operations per line, I adjusted the table and switched to use upserts. Thanks for the feedback


export async function getPgClient(secretsManager, secretId) {
const fn = "getPgClient ";
const startTime = Date.now();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to after line51.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your motivation on this @SaschaSchwarze0 ?

Do you want to track independent durations for the SM and the PG init operaion?
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Yes, I assumed you wanted to measure the secret fetching.

const startTime = Date.now();
console.log(`${fn} > firstName: '${firstName}', lastName: '${lastName}'`);
return new Promise(function (resolve, reject) {
const queryText = "INSERT INTO users(firstname,lastname) VALUES($1, $2)";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To continue the best practive you have followed elsewhere, what about measuring and logging statement durations ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean.

such statements are backed into the call on each DB operation, COS operation and SM operation. From my perspective, we are good.

image

@reggeenr reggeenr merged commit ea01433 into main Apr 21, 2025
2 checks passed
@reggeenr reggeenr deleted the cos-to-sql branch April 21, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants