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

Migrate from s3 sdk v2 to v3 #6731

Merged
merged 10 commits into from May 19, 2024
Merged

Migrate from s3 sdk v2 to v3 #6731

merged 10 commits into from May 19, 2024

Conversation

lng2020
Copy link
Contributor

@lng2020 lng2020 commented Mar 28, 2024

close #5683. Nothing breaking, test with my local setup and everything works.
Noticeable change:
The s3 SDK v3 method PutObjectCommand doesn't support stream input and it requires a content-length field to be set, which is discussed in aws/aws-sdk-js-v3#2348.
So I didn't use PutObjectCommand because I think loading whole files into the buffer may cause a burden. As the issue comment above suggests, I use the Upload class from @aws-sdk/lib-storage which is compatible with v2.

Just in case anyone needs a clear answer: putObject can't write a stream to S3, you have to use the Upload class in @aws-sdk/lib-storage

@auto-assign auto-assign bot requested a review from tommoor March 28, 2024 17:07
@CLAassistant
Copy link

CLAassistant commented Mar 28, 2024

CLA assistant check
All committers have signed the CLA.

@lng2020 lng2020 marked this pull request as draft March 28, 2024 18:45
@lng2020
Copy link
Contributor Author

lng2020 commented Mar 28, 2024

Need to polish about signature-v4-crt

@tommoor
Copy link
Member

tommoor commented Mar 28, 2024

Appreciate the help here 🙏

@lng2020 lng2020 marked this pull request as ready for review March 29, 2024 04:14
package.json Outdated
@@ -47,6 +47,11 @@
"> 0.25%, not dead"
],
"dependencies": {
"@aws-sdk/client-s3": "3.535.0",
"@aws-sdk/lib-storage": "3.535.0",
"@aws-sdk/s3-presigned-post": "3.535.0",
Copy link
Contributor Author

@lng2020 lng2020 Mar 29, 2024

Choose a reason for hiding this comment

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

My local env can work without importing @aws-sdk/s3-presigned-post as expected. But CI cannot find this module so I imported it here. Don't know the root cause and I found a similar issue with aws-sdk/middleware-endpoint before(aws/aws-sdk-js-v3#3983).

server/storage/files/S3Storage.ts Outdated Show resolved Hide resolved
region: env.AWS_REGION,
endpoint: this.getEndpoint(),
signatureVersion: "v4",
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 condition is deprecated and now is replaced by import "@aws-sdk/signature-v4-crt"; according to https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt

@lng2020
Copy link
Contributor Author

lng2020 commented Mar 29, 2024

ready for review

@tommoor
Copy link
Member

tommoor commented Apr 3, 2024

So, there is a bug here – when downloading a document that includes an embedded image (Document -> ... -> Download -> Markdown), the image in the generated zip file is 0 bytes.

This would suggest that getFileStream is not working correctly. I checked out main to test it continues to work correctly there.

try {
return this.client
.getObject({
this.client
Copy link
Member

Choose a reason for hiding this comment

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

The response is no longer returned, can we restore this to async/await style?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in d520b03 (#6731) . I'm not so familiar with all promise, await, and async things. Please feel free to correct me if I'm doing wrong.

@lng2020
Copy link
Contributor Author

lng2020 commented Apr 3, 2024

So, there is a bug here – when downloading a document that includes an embedded image (Document -> ... -> Download -> Markdown), the image in the generated zip file is 0 bytes.

From my local test, it's been fixed by d520b03 (#6731). There is a long discussion about this getObjectComand aws/aws-sdk-js-v3#1877 about this inflexibility command 😄 and It seems required to use the Readable type. Let me know if there are other malfunctions or other improvements.

@tommoor
Copy link
Member

tommoor commented Apr 4, 2024

I really don't want to change the signature of the storage interface here, it's weird to have a method called getFileStream that returns a promise :/ It feels like it was very close before the last round of changes with the exception of that one issue

@lng2020
Copy link
Contributor Author

lng2020 commented Apr 4, 2024

can we restore this to async/await style?

I assume this means using async/await in getFileStream and results in a promise returned so I change the signature. Could u kindly specify what the right approach is?

@tommoor
Copy link
Member

tommoor commented Apr 4, 2024

I think you're right, this is a terrible limitation of the new version – how annoying.

invariant(
env.AWS_S3_UPLOAD_BUCKET_NAME,
"AWS_S3_UPLOAD_BUCKET_NAME is required"
);

this.client
return this.client
Copy link
Member

Choose a reason for hiding this comment

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

This seemed to be a bug – nothing returned here, but with this change I think it's ready to merge

@tommoor tommoor merged commit 3a7dd94 into outline:main May 19, 2024
11 checks passed
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.

Upgrade AWS SDK to v3
3 participants