private static async Task <bool> DeleteLambda(FunctionConfiguration lambda, AWSEnvironment environment) { try { var awsConfiguration = new AmazonLambdaConfig() { RegionEndpoint = RegionEndpoint.GetBySystemName(environment.Region) }; var awsCredentials = new BasicAWSCredentials(environment.AccessKey, environment.SecretKey); using (var awsClient = new AmazonLambdaClient(awsCredentials, awsConfiguration)) { var response = await awsClient.DeleteFunctionAsync(new DeleteFunctionRequest { FunctionName = lambda.FunctionName, Qualifier = lambda.Version //ARN }); Console.WriteLine($"Lamba {lambda.FunctionName} deleted."); return(response.HttpStatusCode == HttpStatusCode.NoContent); //204 }; } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine($"Error: {ex.Message}"); Console.ForegroundColor = ConsoleColor.White; } return(false); }
private static async Task DeleteOldVersionsForTheFunction(string functionName, int count) { var _versionList = (await _lambdaClient.ListVersionsByFunctionAsync(new ListVersionsByFunctionRequest { FunctionName = functionName })) .Versions .Where(q => !(q.FunctionArn.EndsWith("LATEST"))) .OrderByDescending(q => q.LastModified); Console.WriteLine("The Function has " + _versionList.Count() + " versions"); if (_versionList.Count() > count) { foreach (var _version in _versionList.Skip(count)) { Console.WriteLine("Deleting " + _version.FunctionArn); if (!_debugMode) { await _lambdaClient.DeleteFunctionAsync(new DeleteFunctionRequest { FunctionName = _version.FunctionName, Qualifier = _version.Version }); } } } else { Console.WriteLine("The Version Count is lower than " + count + ". The function is skipped."); } }
/// <summary> /// Deletes function from name/arn and qualifier /// use qualifier to specify version /// cannot specify $LATEST /// Qualifier in required to prevent accidental deletion of entire function /// </summary> /// <param name="functionName"></param> /// <param name="qualifier"></param> /// <returns></returns> public DeleteFunctionResponse DeleteFunction(string functionName, string qualifier) { var response = _client.DeleteFunctionAsync(new DeleteFunctionRequest { FunctionName = functionName, Qualifier = qualifier }); return(response.Result); }
private async Task DeleteFunctionIfExistsAsync() { try { await _lambdaClient.DeleteFunctionAsync(new DeleteFunctionRequest { FunctionName = _functionName }); } catch (ResourceNotFoundException) { // No action required } }
private static async Task DeleteFunctionIfExistsAsync(AmazonLambdaClient lambdaClient) { var request = new DeleteFunctionRequest { FunctionName = FunctionName }; try { var response = await lambdaClient.DeleteFunctionAsync(request); } catch (ResourceNotFoundException) { // no problem } }
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}"); } } }