Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
Rate exceeded while running stop services script Fargate

Really need help with this AWS Fargate stopping script, Im receiving an error called "Rate exceeded" "ThrottilingException", is there a way to add that my script detects the error and if it sees the error, it will pause for a little bit and continue where it was left off?

var AWS  = require("aws-sdk");
AWS.config.update({region: "eu-central-1"});

var s3 = new AWS.S3({apiVersion: '2006-03-01'});
var ecs = new AWS.ECS({apiVersion: '2014-11-13'});


 
async function getServiceArns(token) {
  var params = {
    cluster: 'my-cluster',
    launchType: "FARGATE",
    maxResults: 100,
    nextToken: '',
    schedulingStrategy: "REPLICA"
  };


  return new Promise(function(resolve) {
    var services = []
    if (token) {
      params.nextToken = token
    }
    ecs.listServices(params, async function(err, data) {
      if(data.nextToken) {
        services.push(...(await getServiceArns(data.nextToken)))
      }
      services.push(...data.serviceArns)
      resolve(services)
    });
  })
}

async function main(){

  var arns =  await getServiceArns()
  
  var services = await Promise.all(arns.map(function(arn) {
    return new Promise(function(resolve) {
      ecs.describeServices({cluster: 'my-cluster', services:[arn]}, function(err, data) {
        resolve({arn, count: data.services[0].desiredCount})
      });
    })
  }))

  var filtered = services.filter(item => item.count > 0)
  var base64data = Buffer.from(JSON.stringify(filtered), 'binary');

  await s3.putObject({
    Bucket: 'my-bucket',
    Key: 'services.txt',
    Body: base64data,
  }).promise();
  await Promise.all(filtered.map(function(service) {
    var params = {
      desiredCount: 0,
      cluster: "my-cluster",
      service: service.arn,
    };
    console.log(service.arn)
    // return ecs.updateService(params).promise()
  }))


  console.log('successfully shutdown all services')
}
exports.handler = main
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!