Skip to content

Commit

Permalink
Fix region config for user-pool-domain lambda, fixes cloudcomponents#211
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotsegler committed May 26, 2024
1 parent 60f1d89 commit 7414b38
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
Expand All @@ -28,7 +29,7 @@ async function ensureCognitoUserPoolDomain(userPoolId: string): Promise<string>
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) => {
Expand Down

0 comments on commit 7414b38

Please sign in to comment.