Jack Danger 28d38c5ae2 fixing typos in variable names
nane -> name
resouce -> resource
2019-09-24 19:21:00 -07:00

78 lines
2.2 KiB
JavaScript

'use strict';
const { addPermission, removePermission } = require('./lib/permissions');
const { updateConfiguration, removeConfiguration, findUserPoolByName } = require('./lib/userPool');
const { getEnvironment, getLambdaArn, handlerWrapper } = require('../utils');
function handler(event, context) {
if (event.RequestType === 'Create') {
return create(event, context);
} else if (event.RequestType === 'Update') {
return update(event, context);
} else if (event.RequestType === 'Delete') {
return remove(event, context);
}
throw new Error(`Unhandled RequestType ${event.RequestType}`);
}
function create(event, context) {
const { FunctionName, UserPoolName, UserPoolConfigs } = event.ResourceProperties;
const { Region, AccountId } = getEnvironment(context);
const lambdaArn = getLambdaArn(Region, AccountId, FunctionName);
return findUserPoolByName({ userPoolName: UserPoolName, region: Region }).then(userPool =>
addPermission({
functionName: FunctionName,
userPoolName: UserPoolName,
region: Region,
accountId: AccountId,
userPoolId: userPool.Id,
}).then(() =>
updateConfiguration({
lambdaArn,
userPoolName: UserPoolName,
userPoolConfigs: UserPoolConfigs,
region: Region,
})
)
);
}
function update(event, context) {
const { Region, AccountId } = getEnvironment(context);
const { FunctionName, UserPoolName, UserPoolConfigs } = event.ResourceProperties;
const lambdaArn = getLambdaArn(Region, AccountId, FunctionName);
return updateConfiguration({
lambdaArn,
userPoolName: UserPoolName,
userPoolConfigs: UserPoolConfigs,
region: Region,
});
}
function remove(event, context) {
const { Region, AccountId } = getEnvironment(context);
const { FunctionName, UserPoolName } = event.ResourceProperties;
const lambdaArn = getLambdaArn(Region, AccountId, FunctionName);
return removePermission({
functionName: FunctionName,
userPoolName: UserPoolName,
region: Region,
}).then(() =>
removeConfiguration({
lambdaArn,
userPoolName: UserPoolName,
region: Region,
})
);
}
module.exports = {
handler: handlerWrapper(handler, 'CustomResourceExistingCognitoUserPool'),
};