Skip to content

Instantly share code, notes, and snippets.

@zoellner
Last active February 19, 2019 19:48
Show Gist options
  • Save zoellner/09631a770cefd3fec272268c41cf5ff6 to your computer and use it in GitHub Desktop.
Save zoellner/09631a770cefd3fec272268c41cf5ff6 to your computer and use it in GitHub Desktop.

Revisions

  1. zoellner revised this gist Nov 26, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion deleteTaskDefinition.js
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@ const deregisterAll = (familyPrefix, callback) => {
    return callback();
    });
    }))
    .ratelimit(30, 10000) //just a guess - can't find documentation about actual rate limit
    .ratelimit(20, 15000) //just a guess - can't find documentation about actual rate limit
    .collect()
    .toCallback(callback);
    };
  2. zoellner revised this gist Sep 22, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions deleteTaskDefinition.js
    Original file line number Diff line number Diff line change
    @@ -55,6 +55,7 @@ const deregisterAll = (familyPrefix, callback) => {
    return callback();
    });
    }))
    .ratelimit(30, 10000) //just a guess - can't find documentation about actual rate limit
    .collect()
    .toCallback(callback);
    };
  3. zoellner created this gist Sep 22, 2017.
    75 changes: 75 additions & 0 deletions deleteTaskDefinition.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,75 @@
    'use strict';

    const AWS = require('aws-sdk');
    const _h = require('highland');

    const ecs = new AWS.ECS({region: process.env.AWS_REGION || 'us-east-1'});

    let familyPrefix = null;

    if (process.argv.length >= 3){
    familyPrefix = process.argv[2];
    } else {
    return(console.error('Error: No familyPrefix provided. Usage: node sctiptName familyPrefix'));
    }

    const checkFamily = (familyPrefix, callback) => {
    ecs.listTaskDefinitionFamilies({status: 'ACTIVE', familyPrefix}, (err, data) => {
    if (err) {return callback(err);}
    if (!(data && data.families && data.families.indexOf(familyPrefix) > -1)) {
    return callback(new Error('taskDefinitionFamily not found'));
    }
    return callback();
    });
    };

    const deregisterAll = (familyPrefix, callback) => {
    let nextToken = null;
    _h((push, next) => {
    const params = {
    familyPrefix,
    nextToken
    };

    ecs.listTaskDefinitions(params, function(err, data) {
    if (err) {
    push(err);
    return next();
    }

    if (data && data.taskDefinitionArns) {
    push(null, data.taskDefinitionArns);
    }
    if (data.nextToken) {
    nextToken = data.nextToken;
    return next();
    };
    return push(null, _h.nil); //end stream
    });
    })
    .flatten()
    .flatMap(_h.wrapCallback((taskDefinition, callback) => {
    ecs.deregisterTaskDefinition({taskDefinition}, (err, result) => {
    if (err) {return callback(err);}
    console.log(`${taskDefinition} ${(result && result.taskDefinition && result.taskDefinition.status === 'INACTIVE') ? 'deregistered' : 'check again <--' }`);
    return callback();
    });
    }))
    .collect()
    .toCallback(callback);
    };

    checkFamily(familyPrefix, (err) => {
    if (err) {
    console.error(err);
    process.exit(1);
    }
    deregisterAll(familyPrefix, (err) => {
    if (err) {
    console.error(err);
    process.exit(1);
    }
    console.log('done');
    process.exit();
    });
    });