From 7414b384dcace59ac218f6f8a8148785f68ef467 Mon Sep 17 00:00:00 2001 From: Elliot Segler Date: Sun, 26 May 2024 16:20:16 +0800 Subject: [PATCH] Fix region config for user-pool-domain lambda, fixes #211 --- .../src/lambdas/user-pool-domain/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cdk-cloudfront-authorization/src/lambdas/user-pool-domain/index.ts b/packages/cdk-cloudfront-authorization/src/lambdas/user-pool-domain/index.ts index e79239ae..ba722b47 100644 --- a/packages/cdk-cloudfront-authorization/src/lambdas/user-pool-domain/index.ts +++ b/packages/cdk-cloudfront-authorization/src/lambdas/user-pool-domain/index.ts @@ -7,8 +7,9 @@ import type { } from 'aws-lambda'; import axios from 'axios'; +const awsRegion = process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION; const COGNITO_CLIENT = new CognitoIdentityProvider({ - region: process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION, + region: awsRegion, }); async function ensureCognitoUserPoolDomain(userPoolId: string): Promise { @@ -28,7 +29,7 @@ async function ensureCognitoUserPoolDomain(userPoolId: string): Promise throw new Error('Cognito auth domain is missing! Either a domain prefix or a custom domain must be configured.'); } - return userPool.CustomDomain ?? `${userPool.Domain}.auth.${COGNITO_CLIENT.config.region}.amazoncognito.com`; + return userPool.CustomDomain ?? `${userPool.Domain}.auth.${awsRegion}.amazoncognito.com`; } export const handler: CloudFormationCustomResourceHandler = async (event) => {