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

[@aws-sdk/client-sns]: custom endpoint.path is not taken into account when making requests #1399

Closed
vvo opened this issue Jul 24, 2020 · 5 comments · Fixed by smithy-lang/smithy-typescript#406 or #2722
Assignees
Labels
bug This issue is a bug. High Priority

Comments

@vvo
Copy link
Contributor

vvo commented Jul 24, 2020

Describe the bug
When using this kind of code:

const snsClient = new SNS({
  apiVersion: "2010-03-31",
  endpoint: "https://example.com/sns"
});

snsClient.publish({
  TopicArn: "some:topic",
  Message: "hello world",
});

Then the request is made to https://example.com/ instead of https://example.com/sns. I believe because of:

const buildHttpRpcRequest = async (
context: __SerdeContext,
headers: __HeaderBag,
path: string,
resolvedHostname: string | undefined,
body: any
): Promise<__HttpRequest> => {
const { hostname, protocol = "https", port } = await context.endpoint();
const contents: any = {
protocol,
hostname,
port,
method: "POST",
path,
headers,
};
if (resolvedHostname !== undefined) {
contents.hostname = resolvedHostname;
}
if (body !== undefined) {
contents.body = body;
}
return new __HttpRequest(contents);
};

SDK version number v1.0.0-gamma.5

Is the issue in the browser/Node.js/ReactNative?
All

Details of the Node.js version
v12.18.2

To Reproduce (observed behavior)
Steps to reproduce the behavior (please share code or minimal repo)

const snsClient = new SNS({
  apiVersion: "2010-03-31",
  endpoint: "https://example.com/sns"
});

snsClient.publish({
  TopicArn: "some:topic",
  Message: "hello world",
});

Expected behavior
Request should be made to https://example.com/sns

Screenshots
n/a

Additional context

@AllanZhengYP AllanZhengYP added the bug This issue is a bug. label Jul 27, 2020
@ajredniwja
Copy link
Contributor

Hey @vvo thanks for opening this, I was able to confirm this,

V2 Code used:
var AWS = require('aws-sdk');

const snsClient = new AWS.SNS({
    apiVersion: "2010-03-31",
    endpoint: "https://example.com/sns"
  });


  const req = snsClient.publish({
    TopicArn: "some:topic",
    Message: "hello world",
  });

  console.log(req.httpRequest)

Output:

HttpRequest {
  method: 'POST',
  path: '/sns',
  headers: { 'User-Agent': 'aws-sdk-nodejs/2.781.0 darwin/v10.16.3' },
  body: '',
  endpoint:
   Endpoint {
     protocol: 'https:',
     host: 'example.com',
     port: 443,
     hostname: 'example.com',
     pathname: '/sns',
     path: '/sns',
     href: 'https://example.com/sns',
     constructor: { [Function: Endpoint] __super__: [Function: Object] } },
  region: undefined,
  _userAgent: 'aws-sdk-nodejs/2.781.0 darwin/v10.16.3' }
V3 Code used:
const {SNS} = require("@aws-sdk/client-sns");

const snsClient = new SNS({
    apiVersion: "2010-03-31",
    endpoint: "https://example.com/sns"
  });

snsClient.middlewareStack.add(next => async (args) => {
    console.log("HTTP Request: ", args.request);
}, {
    step: "build"
});

snsClient.publish({
    TopicArn: "some:topic",
    Message: "hello world",
  });

Output:

HttpRequest {
  method: 'POST',
  hostname: 'example.com',
  port: undefined,
  query: {},
  headers:
   { 'Content-Type': 'application/x-www-form-urlencoded',
     'user-agent':
      'aws-sdk-nodejs-v3-@aws-sdk/client-sns/1.0.0-rc.7 darwin/v10.16.3',
     'content-length': '77' },
  body:
   'TopicArn=some%3Atopic&Message=hello%20world&Action=Publish&Version=2010-03-31',
  protocol: 'https:',
  path: '/' }

@AllanZhengYP
Copy link
Contributor

The path is generated from the service model, like here, so even we support overriding the hostname for now, we don't support overriding the path. But I can see the value of it.

To support this, we need to add a middleware to override the request after the serialization middleware. I put this to the TODO list, will provide more update as we progress.

@AllanZhengYP
Copy link
Contributor

Hi, @vvo to provide more information: setting path in the custom endpoint does not always work in v2 SDK. For all REST services except for S3, the path you supplied will be overwritten by the path infered from the service API. Granted, in v3 we can forcely overwrite the path and port if user supplies a custom endpoint. But we could break the users by the some edge cases:

If someone supply an endpoint as http://abc.com, the global URL class will parse the endpoint with default "/" pathname, then whether users intend to override the pathname generated from model to "/" is hard to infer.

@egorFiNE
Copy link

egorFiNE commented Jun 4, 2021

Does a quick workaround exist for the moment?

@github-actions
Copy link

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 Sep 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. High Priority
Projects
None yet
6 participants