From 5a4ad4e5b4d02cc2f47b23e8b1a9f8f77771bd7c Mon Sep 17 00:00:00 2001 From: Billy Bromell Date: Fri, 2 Aug 2024 11:19:26 +0100 Subject: [PATCH 1/3] chore(aws-cdk): use RegionInfo instead of aws-sdk v2 for region domain suffix --- packages/aws-cdk/lib/api/aws-auth/sdk.ts | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) 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; } /** From 1869fdf0ed734d412f0a5a48bf15b59106127c20 Mon Sep 17 00:00:00 2001 From: Billy Bromell Date: Fri, 2 Aug 2024 11:19:26 +0100 Subject: [PATCH 2/3] chore(aws-cdk): use RegionInfo instead of aws-sdk v2 for region domain suffix --- packages/aws-cdk/lib/api/aws-auth/sdk.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/aws-cdk/lib/api/aws-auth/sdk.ts b/packages/aws-cdk/lib/api/aws-auth/sdk.ts index 6a78965620c01..2ee2625177ef2 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,10 @@ 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 +281,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; } /** From 07d4e30e3b316d9d28eef97b6cb6fdd55abd35aa Mon Sep 17 00:00:00 2001 From: Billy Bromell Date: Tue, 13 Aug 2024 09:07:15 +0100 Subject: [PATCH 3/3] fix: remove suppress deprecation warning message --- packages/aws-cdk/lib/api/aws-auth/sdk.ts | 4 ---- packages/aws-cdk/test/api/logs/logs-monitor.test.ts | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/aws-cdk/lib/api/aws-auth/sdk.ts b/packages/aws-cdk/lib/api/aws-auth/sdk.ts index 2ee2625177ef2..3e76b2c1016e2 100644 --- a/packages/aws-cdk/lib/api/aws-auth/sdk.ts +++ b/packages/aws-cdk/lib/api/aws-auth/sdk.ts @@ -7,10 +7,6 @@ import { cached } from './cached'; import { Account } from './sdk-provider'; import { traceMethods } from '../../util/tracing'; -/* eslint-disable @typescript-eslint/no-require-imports */ -require('aws-sdk/lib/maintenance_mode_message').suppress = true; -/* eslint-enable @typescript-eslint/no-require-imports */ - export interface ISDK { /** * The region this SDK has been instantiated for 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`, ); });