aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
2.98k stars 560 forks source link

fix(util-endpoints): augment endpointFunctions inline in endpointResolver functions #5933

Closed kuhe closed 3 months ago

kuhe commented 3 months ago

Issue

Related to https://github.com/aws/aws-sdk-js-v3/issues/5925 https://github.com/aws/aws-sdk-js-v3/issues/5889 https://github.com/aws/aws-sdk-js-v3/issues/5435

Description

This changes the way we register awsEndpointFunctions. Instead of calling

import "@aws-sdk/util-endpoints";

We will do this in each individual client's endpointResolver fn:

import { awsEndpointFunctions } from "@aws-sdk/util-endpoints";
import { customEndpointFunctions } from "@smithy/util-endpoints";

export const defaultEndpointResolver = ...

customEndpointFunctions.aws = awsEndpointFunctions;

This aims to work around two issues:

  1. react-native (some versions of the metro bundler?) may ignore an import statement like import "@aws-sdk/util-endpoints"; because it looks like it's unused, even though it's being imported for its side-effects.
  2. in case @smithy/util-endpoints is duplicated due to multiple versions being depended upon, one of those may not receive the augmentation. By running it inline with the client's code, this ensures that whatever version of @smithy/util-endpoints being used by the client is augmented by the same.

Testing

integration tests cover this, because without the AWS endpoint functions, integration tests will fail, due to being unable to resolve endpoints.

kuhe commented 3 months ago
// endpointResolver.ts (before)
// smithy-typescript generated code
import { EndpointV2, Logger } from "@smithy/types";
import { EndpointParams, resolveEndpoint } from "@smithy/util-endpoints";

import { EndpointParameters } from "./EndpointParameters";
import { ruleSet } from "./ruleset";

export const defaultEndpointResolver = (
  endpointParams: EndpointParameters,
  context: { logger?: Logger } = {}
): EndpointV2 => {
  return resolveEndpoint(ruleSet, {
    endpointParams: endpointParams as EndpointParams,
    logger: context.logger,
  });
};
// endpointResolver.ts (after)
// smithy-typescript generated code
import { awsEndpointFunctions } from "@aws-sdk/util-endpoints";
import { EndpointV2, Logger } from "@smithy/types";
import { customEndpointFunctions, EndpointParams, resolveEndpoint } from "@smithy/util-endpoints";

import { EndpointParameters } from "./EndpointParameters";
import { ruleSet } from "./ruleset";

export const defaultEndpointResolver = (
  endpointParams: EndpointParameters,
  context: { logger?: Logger } = {}
): EndpointV2 => {
  return resolveEndpoint(ruleSet, {
    endpointParams: endpointParams as EndpointParams,
    logger: context.logger,
  });
};

customEndpointFunctions.aws = awsEndpointFunctions;
github-actions[bot] commented 3 months ago

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.