Skip to content

Commit

Permalink
chore: move hosted ui labmda to node18.x
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolk committed Jul 18, 2023
1 parent 343b9ea commit 1287280
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const response = require('cfn-response');
const aws = require('aws-sdk');
const identity = new aws.CognitoIdentityServiceProvider();
const {
CognitoIdentityProviderClient,
DescribeUserPoolCommand,
CreateUserPoolDomainCommand,
DeleteUserPoolDomainCommand,
DescribeUserPoolDomainCommand,
} = require('@aws-sdk/client-cognito-identity-provider');
const identity = new CognitoIdentityProviderClient({});

exports.handler = (event, context) => {
// Don't return promise, response.send() marks context as done internally
Expand All @@ -10,7 +16,7 @@ exports.handler = (event, context) => {
async function checkDomainAvailability(domainName) {
const params = { Domain: domainName };
try {
const res = await identity.describeUserPoolDomain(params).promise();
const res = await identity.send(new DescribeUserPoolDomainCommand(params));
if (res.DomainDescription && res.DomainDescription.UserPool) {
return false;
}
Expand All @@ -22,15 +28,15 @@ async function checkDomainAvailability(domainName) {

async function deleteUserPoolDomain(domainName, userPoolId) {
const params = { Domain: domainName, UserPoolId: userPoolId };
await identity.deleteUserPoolDomain(params).promise();
await identity.send(new DeleteUserPoolDomainCommand(params));
}

async function createUserPoolDomain(domainName, userPoolId) {
const params = {
Domain: domainName,
UserPoolId: userPoolId,
};
await identity.createUserPoolDomain(params).promise();
await identity.send(new CreateUserPoolDomainCommand(params));
}

async function handleEvent(event, context) {
Expand All @@ -40,7 +46,7 @@ async function handleEvent(event, context) {
if (event.RequestType === 'Delete') {
await deleteUserPoolDomain(inputDomainName, userPoolId);
} else if (event.RequestType === 'Update' || event.RequestType === 'Create') {
const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise();
const result = await identity.send(new DescribeUserPoolCommand({ UserPoolId: userPoolId }));
if (inputDomainName) {
if (result.UserPool.Domain === inputDomainName) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,14 @@ exports[`Check Auth Template Generated authstack template in manual flow 1`] = `
"Properties": {
"Code": {
"ZipFile": "const response = require('cfn-response');
const aws = require('aws-sdk');
const identity = new aws.CognitoIdentityServiceProvider();
const {
CognitoIdentityProviderClient,
DescribeUserPoolCommand,
CreateUserPoolDomainCommand,
DeleteUserPoolDomainCommand,
DescribeUserPoolDomainCommand,
} = require('@aws-sdk/client-cognito-identity-provider');
const identity = new CognitoIdentityProviderClient({});
exports.handler = (event, context) => {
// Don't return promise, response.send() marks context as done internally
Expand All @@ -795,7 +801,7 @@ exports.handler = (event, context) => {
async function checkDomainAvailability(domainName) {
const params = { Domain: domainName };
try {
const res = await identity.describeUserPoolDomain(params).promise();
const res = await identity.send(new DescribeUserPoolDomainCommand(params));
if (res.DomainDescription && res.DomainDescription.UserPool) {
return false;
}
Expand All @@ -807,15 +813,15 @@ async function checkDomainAvailability(domainName) {
async function deleteUserPoolDomain(domainName, userPoolId) {
const params = { Domain: domainName, UserPoolId: userPoolId };
await identity.deleteUserPoolDomain(params).promise();
await identity.send(new DeleteUserPoolDomainCommand(params));
}
async function createUserPoolDomain(domainName, userPoolId) {
const params = {
Domain: domainName,
UserPoolId: userPoolId,
};
await identity.createUserPoolDomain(params).promise();
await identity.send(new CreateUserPoolDomainCommand(params));
}
async function handleEvent(event, context) {
Expand All @@ -825,7 +831,7 @@ async function handleEvent(event, context) {
if (event.RequestType === 'Delete') {
await deleteUserPoolDomain(inputDomainName, userPoolId);
} else if (event.RequestType === 'Update' || event.RequestType === 'Create') {
const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise();
const result = await identity.send(new DescribeUserPoolCommand({ UserPoolId: userPoolId }));
if (inputDomainName) {
if (result.UserPool.Domain === inputDomainName) {
return;
Expand Down Expand Up @@ -868,7 +874,7 @@ async function handleEvent(event, context) {
"Arn",
],
},
"Runtime": "nodejs16.x",
"Runtime": "nodejs18.x",
"Timeout": 300,
},
"Type": "AWS::Lambda::Function",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ export class AmplifyAuthCognitoStack extends cdk.Stack implements AmplifyAuthCog
},
handler: 'index.handler',
role: cdk.Fn.getAtt('UserPoolClientRole', 'Arn').toString(),
runtime: 'nodejs16.x',
runtime: 'nodejs18.x',
timeout: 300,
});

Expand Down

0 comments on commit 1287280

Please sign in to comment.