-
Notifications
You must be signed in to change notification settings - Fork 0
/
CloudFormationCognitoUserPoolClientSettings.js
57 lines (49 loc) · 2.33 KB
/
CloudFormationCognitoUserPoolClientSettings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const AWS = require('aws-sdk');
exports.handler = async (event) => {
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,
CallbackURLs: [event.ResourceProperties.CallbackURL],
LogoutURLs: [event.ResourceProperties.LogoutURL],
AllowedOAuthFlowsUserPoolClient: (event.ResourceProperties.AllowedOAuthFlowsUserPoolClient == 'true'),
AllowedOAuthFlows: event.ResourceProperties.AllowedOAuthFlows,
AllowedOAuthScopes: event.ResourceProperties.AllowedOAuthScopes
}).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: '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);
}
}