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

feat(lib-storage): rewrite lib-storage upload #2039

Merged
merged 26 commits into from
Feb 19, 2021

Conversation

alexforsyth
Copy link
Contributor

@alexforsyth alexforsyth commented Feb 16, 2021

Issue

Description

As part of a review of our codebase I rewrote Upload(). This PR fixes a range of issues and should address most of the Issues filed (below). This rewrite is backwards compatible.

Upload is a wrapper on s3.multipart upload. This is largely analogous to managed upload in V2 of the JS SDK.
Here's how you use Upload:

import { Upload } from "@aws-sdk/lib-storage";
import { S3 } from "@aws-sdk/client-s3";

(async () => {
  const upload = new Upload({
    params: {
      Bucket: configuration.Bucket,
      Key: configuration.Key,
      Body: String | Buffer | Uint8Array | Stream | ReadableStream,
    },
    client: new S3({}),
    queueSize: 3,
  });

  upload.on("httpUploadProgress", (progress) => {
    console.log(progress);
  });

  await upload.done();
})();

Testing

How was this change tested?

Manual Browser testing

  • correctly uploads a string
  • correctly uploads an ArrayBuffer
  • correctly uploads a stream of unknown length (audio stream)
  • correctly provides status updates

Manual Node testing

  • correctly uploads a string
  • correctly uploads an Buffer
  • correctly uploads a stream of unknown length (audio stream)
  • correctly provides status updates

Additional context

Add any other context about the PR here.

PRs:
Fixes: #1990
Fixes: #1955

Issues:
Fixes: #1973
Fixes: #1891
Fixes: #1729
Fixes: #1688


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@monken
Copy link

monken commented Feb 16, 2021

Hi @alexforsyth, will you incorporate the performance improvements from my PR at #1955 ?

@alexforsyth
Copy link
Contributor Author

alexforsyth commented Feb 17, 2021

@monken yes! I'll request you as a reviewer when this PR is in better shape. Everything should be using for...await syntax here. I'm looking at the buffer concat in readable chunker right now. The way you do it is much better, I'll only concat once.

@codecov-io
Copy link

codecov-io commented Feb 17, 2021

Codecov Report

Merging #2039 (05b6f8a) into master (f2a47e8) will increase coverage by 0.26%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2039      +/-   ##
==========================================
+ Coverage   79.30%   79.57%   +0.26%     
==========================================
  Files         368      365       -3     
  Lines       15132    15130       -2     
  Branches     3222     3251      +29     
==========================================
+ Hits        12001    12039      +38     
+ Misses       3131     3091      -40     
Impacted Files Coverage Δ
packages/util-waiter/src/utils/validate.ts 81.81% <0.00%> (-18.19%) ⬇️
...process-arnables-plugin/update-arnables-request.ts 91.30% <0.00%> (-8.70%) ⬇️
packages/s3-request-presigner/src/presigner.ts 94.73% <0.00%> (-5.27%) ⬇️
...s/middleware-bucket-endpoint/src/bucketHostname.ts 98.27% <0.00%> (-1.73%) ⬇️
packages/util-dynamodb/src/convertToAttr.ts 98.94% <0.00%> (-1.06%) ⬇️
lib/storage/src/index.ts 100.00% <0.00%> (ø)
packages/util-waiter/src/poller.ts 100.00% <0.00%> (ø)
packages/util-waiter/src/waiter.ts 100.00% <0.00%> (ø)
protocol_tests/aws-ec2/endpoints.ts 81.48% <0.00%> (ø)
packages/smithy-client/src/client.ts 76.47% <0.00%> (ø)
... and 74 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 16214be...05b6f8a. Read the comment docs.

@alexforsyth alexforsyth changed the title WIP: rewrite storage feat(lib-storage): rewrite lib-storage upload Feb 17, 2021
@trivikr trivikr requested review from AllanZhengYP and trivikr and removed request for AllanZhengYP February 17, 2021 18:42
@alexforsyth
Copy link
Contributor Author

@monken it looks like I cannot add you as a reviewer to this PR. I'd still love your feedback at any rate

@samsullivan
Copy link
Contributor

Thank you so much for your attention here, since I only was able to give partial care previously and we've been waiting for these performance improvements to switch over to the new SDK.

If you care, I'll get this tested with my use case some point this week.

@alexforsyth
Copy link
Contributor Author

@samsullivan that'd be great! We're looking to get this out with the next release

@markb-trustifi
Copy link

Please check that it supports server-side encryption with SSECustomerKey.

@alexforsyth
Copy link
Contributor Author

@markb-trustifi it should, all the params you normally pass to multipart upload should work just the same as they are simply passed through to the underlying client.

lib/storage/src/Upload.ts Show resolved Hide resolved
lib/storage/src/chunker.ts Outdated Show resolved Hide resolved
lib/storage/src/chunker.ts Outdated Show resolved Hide resolved
lib/storage/src/chunks/getDataReadable.ts Outdated Show resolved Hide resolved
lib/storage/src/chunks/getChunkStream.ts Outdated Show resolved Hide resolved
lib/storage/src/chunks/getChunkStream.ts Outdated Show resolved Hide resolved
lib/storage/src/chunks/getChunkStream.ts Outdated Show resolved Hide resolved
lib/storage/src/chunks/getChunkBuffer.ts Outdated Show resolved Hide resolved
lib/storage/src/chunks/getChunkBuffer.ts Outdated Show resolved Hide resolved
lib/storage/CHANGELOG.md Outdated Show resolved Hide resolved
lib/storage/src/Upload.ts Outdated Show resolved Hide resolved
lib/storage/src/bytelength.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@samsullivan samsullivan left a comment

Choose a reason for hiding this comment

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

Don't have time to review the code changes, but I 💯 agree that this needed to be rewritten and I appreciate your work. I built you're branch in my test build and threw this into our stage AWS environment just now and it worked fine!

Super excited to have this released. v2 of the JS SDK has an ECS Fargate bug where it doesn't use the IAM role on the container, so I'll get to remove some access keys once upgraded 🙂

@alexforsyth
Copy link
Contributor Author

@monken @samsullivan @xfournet Thanks so much for the engagement. It's awesome to see the involvement. We're aiming at releasing these changes soon

@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • CodeBuild project: sdk-staging-test
  • Commit ID: 6fe4156
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@alexforsyth
Copy link
Contributor Author

FYI: This should be out with 3.6.0

@alexforsyth alexforsyth deleted the rewrite-storage branch February 22, 2021 17:12
@skozer
Copy link

skozer commented Feb 22, 2021

Confirmed working in 3.6.0, thanks!

@samsullivan
Copy link
Contributor

☝️ same here, really appreciate the effort by everybody on this one. Happy to be off of v2 SDK!

@github-actions
Copy link

github-actions bot commented Mar 9, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
9 participants