public async Task <ListUserPoolsResponse> GetUserPool(ListUserPoolsRequest listUserPoolsRequest) { using (var amazonCognitoIdentityProviderClient = new AmazonCognitoIdentityProviderClient(awsCredentials, RegionEndpoint.GetBySystemName(Region))) { var response = await amazonCognitoIdentityProviderClient.ListUserPoolsAsync(listUserPoolsRequest); return(response); } }
public static async Task <(bool exists, string id)> CognitoUserPoolExists( this AmazonCognitoIdentityProviderClient client, string name) { var userPools = await client.ListUserPoolsAsync(new ListUserPoolsRequest()); var matchingPool = userPools.UserPools.FirstOrDefault(x => x.Name == name); return(matchingPool != null, matchingPool?.Id); }
public async Task TearDownResourcesAsync() { using (var cfClient = new AmazonCloudFormationClient()) { var request = new DeleteStackRequest { StackName = this.FrontendCloudFormationStack }; try { await cfClient.DeleteStackAsync(request); Console.WriteLine($"Frontend CloudFormation Stack {this.FrontendCloudFormationStack} is deleted"); } catch (Exception e) { Console.WriteLine($"Frontend CloudFormation Stack {this.FrontendCloudFormationStack} was not deleted: {e.Message}"); } } using (var lambdaClient = new AmazonLambdaClient()) { var request = new DeleteFunctionRequest { FunctionName = this.DynanmoDBStreamLambdaFunction }; try { await lambdaClient.DeleteFunctionAsync(request); Console.WriteLine($"Function {this.DynanmoDBStreamLambdaFunction} is deleted"); } catch (Exception e) { Console.WriteLine($"Function {this.DynanmoDBStreamLambdaFunction} was not deleted: {e.Message}"); } } using (var cognitoClient = new AmazonCognitoIdentityProviderClient()) { var userPool = (await cognitoClient.ListUserPoolsAsync(new ListUserPoolsRequest { MaxResults = 60 })).UserPools .FirstOrDefault(x => string.Equals(this.CognitoUserPool, x.Name)); if (userPool != null) { var request = new DeleteUserPoolRequest { UserPoolId = userPool.Id }; try { await cognitoClient.DeleteUserPoolAsync(request); Console.WriteLine($"Cognito User Pool {this.CognitoUserPool} is deleted"); } catch (Exception e) { Console.WriteLine($"Cognito User Pool {this.CognitoUserPool} was not deleted: {e.Message}"); } } } using (var ssmClient = new AmazonSimpleSystemsManagementClient()) { try { var parameters = (await ssmClient.GetParametersByPathAsync(new GetParametersByPathRequest { Path = this.ParameterStorePrefix, Recursive = true })).Parameters; Console.WriteLine($"Found {parameters.Count} SSM parameters starting with {this.ParameterStorePrefix}"); foreach (var parameter in parameters) { try { await ssmClient.DeleteParameterAsync(new DeleteParameterRequest { Name = parameter.Name }); Console.WriteLine($"Parameter {parameter.Name} is deleted"); } catch (Exception e) { Console.WriteLine($"Parameter {parameter.Name} was not deleted: {e.Message}"); } } } catch (Exception e) { Console.WriteLine($"Error deleting SSM Parameters: {e.Message}"); } } using (var ddbClient = new AmazonDynamoDBClient()) { var request = new DeleteTableRequest { TableName = this.DynamoDBTableName }; try { await ddbClient.DeleteTableAsync(request); Console.WriteLine($"Table {this.DynamoDBTableName} is deleted"); } catch (Exception e) { Console.WriteLine($"Table {this.DynamoDBTableName} was not deleted: {e.Message}"); } } }