UNPKG

@smither/aws-user-pool-client-settings

Version:

aws-cdk custom resource to allow setting details for user pool client and integrations.

60 lines (51 loc) 2.54 kB
const AWS = require('aws-sdk'); exports.handler = async (event) => { console.info(event) console.info(event.ResourceProperties) try { switch (event.RequestType) { case 'Create': case 'Update': var cognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider(); await cognitoIdentityServiceProvider.updateUserPoolClient({ UserPoolId: event.ResourceProperties.UserPoolId, ClientId: event.ResourceProperties.UserPoolClientId, SupportedIdentityProviders: event.ResourceProperties.SupportedIdentityProviders.split(","), CallbackURLs: event.ResourceProperties.CallbackURLs.split(","), LogoutURLs: event.ResourceProperties.LogoutURLs.split(","), AllowedOAuthFlowsUserPoolClient: event.ResourceProperties.AllowedOAuthFlowsUserPoolClient == "true", AllowedOAuthFlows: event.ResourceProperties.AllowedOAuthFlows.split(","), AllowedOAuthScopes: event.ResourceProperties.AllowedOAuthScopes.split(",") }).promise(); await sendCloudFormationResponse(event, 'SUCCESS'); break; case 'Delete': await sendCloudFormationResponse(event, 'SUCCESS'); break; } console.info(`CognitoUserPoolClientSettings Success for request type ${event.RequestType}`); } catch (error) { console.error(`CognitoUserPoolClientSettings Error for request type ${event.RequestType}:`, error); await sendCloudFormationResponse(event, 'FAILED'); } } async function sendCloudFormationResponse(event, responseStatus, responseData) { var params = { FunctionName: `${event.ResourceProperties.Domain}-CloudFormationSendResponse`, InvocationType: 'RequestResponse', Payload: JSON.stringify({ StackId: event.StackId, RequestId: event.RequestId, LogicalResourceId: event.LogicalResourceId, ResponseURL: event.ResponseURL, ResponseStatus: responseStatus, ResponseData: responseData }) }; var lambda = new AWS.Lambda(); var response = await lambda.invoke(params).promise(); if (response.FunctionError) { var responseError = JSON.parse(response.Payload); throw new Error(responseError.errorMessage); } }