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-endpoints): augment endpointFunctions inline in endpointResolver functions #5933

Merged
merged 2 commits into from Mar 21, 2024

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Mar 21, 2024

Issue

Related to #5925
#5889
#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.

  • full codegen
  • full build
  • unit
  • integ

@kuhe kuhe requested review from a team as code owners March 21, 2024 19:55
@kuhe
Copy link
Contributor Author

kuhe commented Mar 21, 2024

// 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;

@trivikr trivikr merged commit 42a791d into aws:main Mar 21, 2024
4 checks passed
@kuhe kuhe deleted the fix/endpoints branch March 22, 2024 14:35
@kuhe kuhe mentioned this pull request Mar 22, 2024
3 tasks
Copy link

github-actions bot commented Apr 6, 2024

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 Apr 6, 2024
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.

None yet

2 participants