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
truecharts-admin added a commit to truecharts/charts that referenced this pull request Jun 14, 2024
…97bcc by renovate (#23333)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [outlinewiki/outline](https://togithub.com/outline/outline) | minor |
`0.76.1` -> `0.77.0` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>outline/outline (outlinewiki/outline)</summary>

###
[`v0.77.0`](https://togithub.com/outline/outline/releases/tag/v0.77.0)

[Compare
Source](https://togithub.com/outline/outline/compare/v0.76.1...v0.77.0)

#### What's Changed

This release changes how documents are rendered, allowing the
introduction of new editor functionality and attributes. Highlighted for
this release are some big improvements to tables:


![image](https://togithub.com/outline/outline/assets/380914/6109e4a5-fc5a-4a25-ae33-eebbe9adc0db)

- **Column resizing:** You can now resize columns by dragging the border
between them
- **Full-width tables:** Tables now expand to the full width of the
editor
- **More content:** Table cells now support embeds, code blocks, and all
other content types
-   **Toggleable headers:** You can now toggle a header row and column
- **Improved overflow:** Tables now scroll horizontally when they're too
wide for the editor
- **Improved row and column controls**: We've made it one click to add
rows and columns

##### Other improvements

- Added more highlighter color choices in
[outline/outline#7012
- New collection permissions UI in
[outline/outline#6917
- Big rendering performance improvements for documents with many images
- Add `Manage` permission to documents allows other users to manage
sharing in
[outline/outline#7003
- Added an embedded Yandex Maps component by
[@&#8203;shashinma](https://togithub.com/shashinma) in
[outline/outline#6881
- Added a permission selector in document/collection invite flow in
[outline/outline#6948
- Added support for embedded youtube clips by
[@&#8203;Pranav2612000](https://togithub.com/Pranav2612000) in
[outline/outline#6942
- Matomo integration in
[outline/outline#7009
- `/` block insert shortcut now works anywhere on a line or table in
[outline/outline#7026
- Added the ability to remove a previously uploaded team logo or profile
picture
-   Added a menu option to create template directly in collection

##### Fixes

-   Various fixes to improve the fluidity of app loading
- Image placeholders are now correctly sized when uploading retina
images
- Images and PDF's are now served with inline content disposition in
[outline/outline#6924
- Added support for Figma's new link formats and Figjam boards by
[@&#8203;RenderCoder](https://togithub.com/RenderCoder) in
[outline/outline#6946
- `files.get` now supports range header, fixes video loading in Safari
in
[outline/outline#6950
- Fixed an issue where zoomed images could get stuck in
[outline/outline#6980
-   Share button was removed on templates
-   Fixed race condition that could result in document emoji not saving
-   Removed trust of `state.host` in auth error redirect
-   Collapsed sidebar now works better in Arc/Edge redesign

#### New Contributors

- [@&#8203;shashinma](https://togithub.com/shashinma) made their first
contribution in
[outline/outline#6881
- [@&#8203;lng2020](https://togithub.com/lng2020) made their first
contribution in
[outline/outline#6731
- [@&#8203;RenderCoder](https://togithub.com/RenderCoder) made their
first contribution in
[outline/outline#6946
- [@&#8203;Frzk](https://togithub.com/Frzk) made their first
contribution in
[outline/outline#6971
- [@&#8203;bkrausz](https://togithub.com/bkrausz) made their first
contribution in
[outline/outline#7022

**Full Changelog**:
outline/outline@v0.76.0...v0.77.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MDcuNCIsInVwZGF0ZWRJblZlciI6IjM3LjQwNy40IiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbImF1dG9tZXJnZSIsInVwZGF0ZS9kb2NrZXIvZ2VuZXJhbC9ub24tbWFqb3IiXX0=-->
Shuttleu pushed a commit to Shuttleu/outline that referenced this pull request Jun 20, 2024
* chore: migrate from s3 sdk v2 to v3

* import signature-v4-crt

* downgrade minor version

* Add s3-presigned-post manually

* Change s3 mock

* Update server/storage/files/S3Storage.ts

* docs

* Upgrade aws-sdk

---------

Co-authored-by: Tom Moor <tom.moor@gmail.com>
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