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

chore: Uprade aws-sdk to v3 #3989

Merged
merged 9 commits into from
Dec 3, 2024
Merged

chore: Uprade aws-sdk to v3 #3989

merged 9 commits into from
Dec 3, 2024

Conversation

jamdelion
Copy link
Contributor

@jamdelion jamdelion commented Nov 20, 2024

I'm not particularly familiar with configuring AWS so have found this quite tricky, despite the helpful codemod script recommended by AWS.

I've added some comments on the code below with some of the issues/questions I've had!


Picking up from the work @jamdelion has started here!

What does this PR do?

  • Update aws-sdk from v2 (deprecated) to v3
  • Updates associated functions, types and mocks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one where I'm not sure what to do. There seem to be various suggestions in the docs e.g. new CreateBucketsCommand, replace S3 with S3Client but I suppose I'm not altogether clear on what the Bucket part of the code is doing, and there are red squiggly lines over everything!


return {
body: file.Body as Buffer,
body: file.Body,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing this causes type issues in modules/file/controller because it expects the body to be a Buffer - Argument of type 'StreamingBlobPayloadOutputTypes | undefined' is not assignable to parameter of type 'Buffer | undefined'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link

github-actions bot commented Nov 28, 2024

Removed vultr server and associated DNS entries

@DafyddLlyr DafyddLlyr force-pushed the jh/aws-sdk-upgrade-v3 branch from eea0e83 to 76f98ff Compare November 28, 2024 18:16
@@ -22,7 +22,6 @@ MICROSOFT_CLIENT_SECRET=👻

# AWS credentials for uploading user files from local and pull request environments to a staging S3 bucket
AWS_S3_REGION=eu-west-2
AWS_S3_ACL=public-read
Copy link
Contributor

@DafyddLlyr DafyddLlyr Nov 28, 2024

Choose a reason for hiding this comment

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

This env var is actually static and never change, I've simply removed it and hardcoded it here -

https://github.com/theopensystemslab/planx-new/pull/3989/files#diff-673b129524b241afeec398bcfbbc214d9df07c53667a53c3291890f6bca12acaR79

Comment on lines -40 to -42
mockPutObject = vi.fn(() => ({
promise: () => Promise.resolve(),
}));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a common pattern - many of these functions are now async by default and we no longer need to chain .promise().

"s3.eu-west-2.amazonaws.com",
);
it(`does not use Minio config on ${env} environment`, async () => {
vi.stubEnv("NODE_ENV", env);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a really nice little helper vitest provides for testing.

import { isLiveEnv } from "../../../helpers.js";

export function s3Factory() {
return new S3({
params: { Bucket: process.env.AWS_S3_BUCKET },
Copy link
Contributor

Choose a reason for hiding this comment

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

Bucket is now passed into the PutObject and GetObject commands.

Comment on lines -82 to -84
Body: file?.buffer || JSON.stringify(file),
Body: file.buffer,
ContentDisposition: `inline;filename="${filename}"`,
ContentType: file?.mimetype || "application/json",
Copy link
Contributor

Choose a reason for hiding this comment

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

These || statements are unreachable and can be safely removed.

@DafyddLlyr DafyddLlyr changed the title wip: uprade aws-sdk to v3 chore: Uprade aws-sdk to v3 Nov 28, 2024
@DafyddLlyr DafyddLlyr requested a review from a team November 28, 2024 21:47
@DafyddLlyr
Copy link
Contributor

Update AWS SDK to v3

@DafyddLlyr DafyddLlyr marked this pull request as ready for review November 28, 2024 21:49
Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

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

Thanks both for tag-teaming this one, some nice wins here!

One minor comment re: a test, but also want to flag I'm not able to load flows on this pizza (sharedb issue I think? teams & flow lists load fine), and would like to manually double check our send-to-email zip before final approval !

api.planx.uk/modules/file/file.test.ts Outdated Show resolved Hide resolved
@DafyddLlyr
Copy link
Contributor

One minor comment re: a test, but also want to flag I'm not able to load flows on this pizza (sharedb issue I think? teams & flow lists load fine), and would like to manually double check our send-to-email zip before final approval !

Take a look at Pizza now, thanks for raising this.

@DafyddLlyr
Copy link
Contributor

@jessicamcinchak Pizza up and running 🍕

Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

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

Thanks for fixing pizza - double-checked files in submission zips all working as expected ✅ https://api.3989.planx.pizza/admin/session/210c2ff2-8358-47aa-8081-384cd1cdfe96/zip

Happy for this to merge !

@DafyddLlyr DafyddLlyr merged commit cfede5d into main Dec 3, 2024
12 checks passed
@jamdelion jamdelion deleted the jh/aws-sdk-upgrade-v3 branch December 3, 2024 11:20
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.

3 participants