Created
January 30, 2020 20:40
-
-
Save RyPope/f3b7bb547a1fdfc4777c60a830d6af8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Callback, Context } from 'aws-lambda'; | |
import AWS from 'aws-sdk'; | |
import sendResponse from './CloudFormationSendResponse'; | |
export default async ( | |
event: any, | |
context: Context, | |
callback: Callback<any>) => { | |
try { | |
switch (event.RequestType) { | |
case 'Create': | |
case 'Update': | |
const 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', context.logStreamName); | |
break; | |
case 'Delete': | |
await sendCloudFormationResponse(event, 'SUCCESS', context.logStreamName); | |
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', context.logStreamName); | |
} | |
}; | |
async function sendCloudFormationResponse( | |
event: any, | |
responseStatus: any, | |
logStreamName: string, | |
responseData?: any, | |
) { | |
const request = { | |
StackId: event.StackId, | |
RequestId: event.RequestId, | |
LogicalResourceId: event.LogicalResourceId, | |
ResponseURL: event.ResponseURL, | |
ResponseStatus: responseStatus, | |
ResponseData: responseData, | |
}; | |
await sendResponse(request, logStreamName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment