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

fix(util-create-request): fix creating undefined request #803

Merged
merged 2 commits into from
Jan 28, 2020

Conversation

AllanZhengYP
Copy link
Contributor

Issue #, if available:
fix: #788

Description of changes:

Use command.resolveMiddleware() to generate request instead of
concatenating middleware stacks manually. This fix
also includes build stage to creating request. Because build
stage sometimes contains necessary middleware to build a correct
request. For example, S3's bucket endpoint middleware is located
in build stage. Host header is also necessary, if users want to
sign the generated request directly.

Verify it works with s3 presigned url:

const { createRequest } = require("@aws-sdk/util-create-request");
const {formatUrl} = require("@aws-sdk/util-format-url");
const {S3RequestPresigner} = require("@aws-sdk/s3-request-presigner");
const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3");

(async () => {
  const client = new S3Client({region: "us-west-2"});
  const command = new GetObjectCommand({
    Bucket: "bucket",
    Key: "test"
  });

  try {
    const request = await createRequest(
      client,
      command
    );
    const presigner = new S3RequestPresigner({...client.config});
    const signed = await presigner.presignRequest(request, new Date(Date.now() + 900 * 1000));
    console.log(formatUrl(signed))
  } catch(e) {
    console.log(e)
  }
})();

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

Use command.resolveMiddleware() to generate request instead of
concatenating middleware stacks manually. This fixes gh issue
also include `build` stage to creating request. Because build
stage sometimes contains necessary middleware to build a correct
request. For example, S3's bucket endpoint middleware is located
in build stage. Host header is also necessary, if users want to
sign the generated request directly.
@AllanZhengYP AllanZhengYP requested a review from srchase January 28, 2020 18:56
@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@codecov-io
Copy link

Codecov Report

Merging #803 into smithy-codegen will increase coverage by 0.03%.
The diff coverage is 83.33%.

Impacted file tree graph

@@                Coverage Diff                 @@
##           smithy-codegen     #803      +/-   ##
==================================================
+ Coverage           92.21%   92.24%   +0.03%     
==================================================
  Files                 144      144              
  Lines                2851     2851              
  Branches              489      489              
==================================================
+ Hits                 2629     2630       +1     
+ Misses                222      221       -1
Impacted Files Coverage Δ
packages/util-create-request/src/index.ts 100% <100%> (ø) ⬆️
packages/util-create-request/src/foo.fixture.ts 78.57% <66.66%> (+11.9%) ⬆️

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 120c70d...0f0e216. Read the comment docs.

@AllanZhengYP AllanZhengYP merged commit b6a96c0 into aws:smithy-codegen Jan 28, 2020
@lock
Copy link

lock bot commented Feb 4, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants