async function removeAWSpipelineResources()

in src/pipelineResources.js [724:878]


async function removeAWSpipelineResources(resources, quietI) {
    quiet = quietI;
    const appSyncClient = new AppSyncClient({region: resources.region});
    const lambdaClient = new LambdaClient({region: resources.region});
    const iamClient = new IAMClient({region: resources.region});
    
    // Appsync API
    startSpinner('Deleting AppSync API ...', true);

    try {
        const input = { 
            apiId:  resources.AppSyncAPI
        };
        const command = new DeleteGraphqlApiCommand(input);
        await appSyncClient.send(command);
        succeedSpinner('Deleted API id: ' + yellow(resources.AppSyncAPI), {logLevel: 'debug'});
        loggerInfo('Deleted AppSync API')
    } catch (error) {
        const message = 'AppSync API delete failed';
        failSpinner(message);
        loggerError(message, error);
    }
    
    // Lambda
    startSpinner('Deleting Lambda function ...', true);
    try {
        const input = {
            FunctionName: resources.LambdaFunction 
        };
        const command = new DeleteFunctionCommand(input);        
        await lambdaClient.send(command);
        succeedSpinner('Deleted Lambda function: ' + yellow(resources.LambdaFunction), {logLevel: 'debug'});
        loggerInfo('Deleted Lambda')
    } catch (error) {
        const message = 'Lambda function failed to delete';
        failSpinner(message);
        loggerError(message, error);
    }    
    
    // Lambda execution role
    startSpinner('Detaching first IAM policy from role ...', true);
    try {
        let input = { 
            PolicyArn: resources.LambdaExecutionPolicy1,
            RoleName: resources.LambdaExecutionRole
        };
        let command = new DetachRolePolicyCommand(input);        
        await iamClient.send(command);
        succeedSpinner('Detached policy: ' + yellow(resources.LambdaExecutionPolicy1) + " from role: " + yellow(resources.LambdaExecutionRole), {logLevel: 'debug'});
        loggerInfo('Detached first IAM policy from role');
    } catch (error) {
        let message = 'Detach first policy failed';
        failSpinner(message);
        loggerError(message, error);
    }

    startSpinner('Detaching second IAM policy from role ...', true);
    try {
        let input = { 
            PolicyArn: resources.LambdaExecutionPolicy2,
            RoleName: resources.LambdaExecutionRole
        };
        let command = new DetachRolePolicyCommand(input);        
        await iamClient.send(command);
        succeedSpinner('Detached IAM policy: ' + yellow(resources.LambdaExecutionPolicy2) + " from role: " + yellow(resources.LambdaExecutionRole), {logLevel: 'debug'});
        loggerInfo('Detached second IAM policy from role');
    } catch (error) {
        const message = 'Detach second IAM policy failed';
        failSpinner(message);
        loggerError(message, error);
    }
    
    // Delete Neptune query Policy
    if (resources.NeptuneQueryPolicy != undefined) {
        startSpinner('Deleting query policy ...', true);
        try {
            const input = {
                PolicyArn: resources.NeptuneQueryPolicy,
            };
            const command = new DeletePolicyCommand(input);     
            await iamClient.send(command);
            succeedSpinner('Deleted query policy: ' + yellow(resources.NeptuneQueryPolicy), {logLevel: 'debug'});
            loggerInfo('Deleted query policy');
        } catch (error) {
            const message = 'Delete query policy failed';
            failSpinner(message);
            loggerError(message, error);
        }
    }

    // Delete Role
    startSpinner('Deleting execution role ...', true);
    try {
        const input = {
            RoleName: resources.LambdaExecutionRole,
        };
        const command = new DeleteRoleCommand(input);        
        await iamClient.send(command);
        succeedSpinner('Deleted execution role: ' + yellow(resources.LambdaExecutionRole), {logLevel: 'debug'});
        loggerInfo('Deleted execution role');
    } catch (error) {
        const message = 'Delete execution role failed';
        failSpinner(message);
        loggerError(message, error);
    }
    
    // AppSync Lambda role
    startSpinner('Detaching invoke policy from AppSync Lambda role ...', true);
    try {
        let input = { 
            PolicyArn: resources.LambdaInvokePolicy,
            RoleName: resources.LambdaInvokeRole
        };
        let command = new DetachRolePolicyCommand(input);        
        await iamClient.send(command);
        succeedSpinner('Detached invoke policy: ' + yellow(resources.LambdaInvokePolicy) + " from role: " + yellow(resources.LambdaInvokeRole), {logLevel: 'debug'});
        loggerInfo('Detached invoke policy');
    } catch (error) {
        const message = 'Detach invoke policy failed';
        failSpinner(message);
        loggerError(message, error);
    }

    // Delete Policy
    startSpinner('Deleting invoke policy ...', true);
    try {
        const input = {
            PolicyArn: resources.LambdaInvokePolicy,
        };
        const command = new DeletePolicyCommand(input);     
        await iamClient.send(command);
        succeedSpinner('Deleted invoke policy: ' + yellow(resources.LambdaInvokePolicy), {logLevel: 'debug'});
        loggerInfo('Deleted invoke policy');
    } catch (error) {
        const message = 'Delete invoke policy failed';
        failSpinner(message);
        loggerError(message, error);
    }
   
    // Delete Role
    startSpinner('Deleting invoke role ...', true);
    try {
        const input = {
            RoleName: resources.LambdaInvokeRole,
        };
        const command = new DeleteRoleCommand(input);        
        await iamClient.send(command);
        succeedSpinner('Deleted invoke role: ' + yellow(resources.LambdaInvokeRole), {logLevel: 'debug'});
        loggerInfo('Deleted invoke role');
    } catch (error) {
        const message = 'Delete invoke role failed';
        failSpinner(message);
        loggerError(message, error);
    }    
}