diff --git a/packages/aws-cdk/lib/api/aws-auth/sdk.ts b/packages/aws-cdk/lib/api/aws-auth/sdk.ts index 6a78965620c01..3e76b2c1016e2 100644 --- a/packages/aws-cdk/lib/api/aws-auth/sdk.ts +++ b/packages/aws-cdk/lib/api/aws-auth/sdk.ts @@ -1,3 +1,4 @@ +import * as region_info from '@aws-cdk/region-info'; import * as AWS from 'aws-sdk'; import type { ConfigurationOptions } from 'aws-sdk/lib/config-base'; import { debug, trace } from './_env'; @@ -6,21 +7,6 @@ import { cached } from './cached'; import { Account } from './sdk-provider'; import { traceMethods } from '../../util/tracing'; -// We need to map regions to domain suffixes, and the SDK already has a function to do this. -// It's not part of the public API, but it's also unlikely to go away. -// -// Reuse that function, and add a safety check, so we don't accidentally break if they ever -// refactor that away. - -/* eslint-disable @typescript-eslint/no-require-imports */ -const regionUtil = require('aws-sdk/lib/region_config'); -require('aws-sdk/lib/maintenance_mode_message').suppress = true; -/* eslint-enable @typescript-eslint/no-require-imports */ - -if (!regionUtil.getEndpointSuffix) { - throw new Error('This version of AWS SDK for JS does not have the \'getEndpointSuffix\' function!'); -} - export interface ISDK { /** * The region this SDK has been instantiated for @@ -291,7 +277,11 @@ export class SDK implements ISDK { } public getEndpointSuffix(region: string): string { - return regionUtil.getEndpointSuffix(region); + const suffix = region_info.RegionInfo.get(region).domainSuffix; + if (!suffix) { + throw new Error(`Could not find domainSuffix in RegionInfo for ${region}`); + } + return suffix; } /** diff --git a/packages/aws-cdk/test/api/logs/logs-monitor.test.ts b/packages/aws-cdk/test/api/logs/logs-monitor.test.ts index 5d35455b0c846..3d073c1626b56 100644 --- a/packages/aws-cdk/test/api/logs/logs-monitor.test.ts +++ b/packages/aws-cdk/test/api/logs/logs-monitor.test.ts @@ -44,8 +44,8 @@ test('process events', async () => { // THEN const expectedLocaleTimeString = eventDate.toLocaleTimeString(); - expect(stderrMock).toHaveBeenCalledTimes(1); - expect(stderrMock.mock.calls[0][0]).toContain( + expect(stderrMock).toHaveBeenCalledTimes(2); + expect(stderrMock.mock.calls[1][0]).toContain( `[${blue('loggroup')}] ${yellow(expectedLocaleTimeString)} message`, ); });