How to use the @cumulus/common/aws.ecs function in @cumulus/common

To help you get started, we’ve selected a few @cumulus/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nasa / cumulus / example / spec / scaling / activityScalingSpec.js View on Github external
HonorCooldown: true
        };
        await autoscaling().setDesiredCapacity(setDesiredCapacityParams).promise()
          .catch((err) => {
            console.log(`err ${JSON.stringify(err, null, 2)}`);
            if (err.code === 'ScalingActivityInProgress') {
              console.log('ScalingActivityInProgress. Cannot make update.');
            }
            else {
              throw (err);
            }
          });

        // wait for instances to be active
        const listContainerInstancesParams = { cluster: clusterArn };
        let containerInstanceIds = (await ecs().listContainerInstances(listContainerInstancesParams).promise()).containerInstanceArns;
        const waitTime = 30000;
        /* eslint-disable no-await-in-loop */
        while (containerInstanceIds.length < 2) {
          console.log('waiting for instances to become active');
          await sleep(waitTime);
          containerInstanceIds = (await ecs().listContainerInstances(listContainerInstancesParams).promise()).containerInstanceArns;
        }
        /* eslint-enable no-await-in-loop */

        // set desired tasks to 2
        const services = await ecs().listServices({ cluster: clusterArn }).promise();
        const serviceName = services.serviceArns[0].split('/').pop();
        const updateServiceParams = {
          desiredCount: 2,
          cluster: clusterArn,
          service: serviceName
github nasa / cumulus / example / spec / scaling / activityScalingSpec.js View on Github external
});

        // wait for instances to be active
        const listContainerInstancesParams = { cluster: clusterArn };
        let containerInstanceIds = (await ecs().listContainerInstances(listContainerInstancesParams).promise()).containerInstanceArns;
        const waitTime = 30000;
        /* eslint-disable no-await-in-loop */
        while (containerInstanceIds.length < 2) {
          console.log('waiting for instances to become active');
          await sleep(waitTime);
          containerInstanceIds = (await ecs().listContainerInstances(listContainerInstancesParams).promise()).containerInstanceArns;
        }
        /* eslint-enable no-await-in-loop */

        // set desired tasks to 2
        const services = await ecs().listServices({ cluster: clusterArn }).promise();
        const serviceName = services.serviceArns[0].split('/').pop();
        const updateServiceParams = {
          desiredCount: 2,
          cluster: clusterArn,
          service: serviceName
        };
        await ecs().updateService(updateServiceParams).promise();

        // Check there is a task running on each instance
        const describeContainerInstanceParams = {
          cluster: clusterArn,
          containerInstances: containerInstanceIds
        };
        let instanceData = await ecs().describeContainerInstances(describeContainerInstanceParams).promise();
        let firstInstanceRunningTasks = instanceData.containerInstances[0].runningTasksCount;
        let secondInstanceRunningTasks = instanceData.containerInstances[1].runningTasksCount;
github nasa / cumulus / example / spec / scaling / activityScalingSpec.js View on Github external
while (containerInstanceIds.length < 2) {
          console.log('waiting for instances to become active');
          await sleep(waitTime);
          containerInstanceIds = (await ecs().listContainerInstances(listContainerInstancesParams).promise()).containerInstanceArns;
        }
        /* eslint-enable no-await-in-loop */

        // set desired tasks to 2
        const services = await ecs().listServices({ cluster: clusterArn }).promise();
        const serviceName = services.serviceArns[0].split('/').pop();
        const updateServiceParams = {
          desiredCount: 2,
          cluster: clusterArn,
          service: serviceName
        };
        await ecs().updateService(updateServiceParams).promise();

        // Check there is a task running on each instance
        const describeContainerInstanceParams = {
          cluster: clusterArn,
          containerInstances: containerInstanceIds
        };
        let instanceData = await ecs().describeContainerInstances(describeContainerInstanceParams).promise();
        let firstInstanceRunningTasks = instanceData.containerInstances[0].runningTasksCount;
        let secondInstanceRunningTasks = instanceData.containerInstances[1].runningTasksCount;
        /* eslint-disable no-await-in-loop */
        while (!(firstInstanceRunningTasks === 1 && secondInstanceRunningTasks === 1)) {
          await sleep(waitTime);
          instanceData = await ecs().describeContainerInstances(describeContainerInstanceParams).promise();
          firstInstanceRunningTasks = instanceData.containerInstances[0].runningTasksCount;
          secondInstanceRunningTasks = instanceData.containerInstances[1].runningTasksCount;
        }
github nasa / cumulus / example / spec / scaling / activityScalingSpec.js View on Github external
// set desired tasks to 2
        const services = await ecs().listServices({ cluster: clusterArn }).promise();
        const serviceName = services.serviceArns[0].split('/').pop();
        const updateServiceParams = {
          desiredCount: 2,
          cluster: clusterArn,
          service: serviceName
        };
        await ecs().updateService(updateServiceParams).promise();

        // Check there is a task running on each instance
        const describeContainerInstanceParams = {
          cluster: clusterArn,
          containerInstances: containerInstanceIds
        };
        let instanceData = await ecs().describeContainerInstances(describeContainerInstanceParams).promise();
        let firstInstanceRunningTasks = instanceData.containerInstances[0].runningTasksCount;
        let secondInstanceRunningTasks = instanceData.containerInstances[1].runningTasksCount;
        /* eslint-disable no-await-in-loop */
        while (!(firstInstanceRunningTasks === 1 && secondInstanceRunningTasks === 1)) {
          await sleep(waitTime);
          instanceData = await ecs().describeContainerInstances(describeContainerInstanceParams).promise();
          firstInstanceRunningTasks = instanceData.containerInstances[0].runningTasksCount;
          secondInstanceRunningTasks = instanceData.containerInstances[1].runningTasksCount;
        }
        /* eslint-enable no-await-in-loop */

        for (let i = 0; i < numExecutions; i += 1) {
          workflowExecutionPromises.push(buildAndStartWorkflow(
            stackName,
            config.bucket,
            workflowName,
github nasa / cumulus / packages / api / models / async-operation.js View on Github external
description,
      operationType
    });

    // Store the payload to S3
    const payloadBucket = this.systemBucket;
    const payloadKey = `${this.stackName}/async-operation-payloads/${id}.json`;

    await s3().putObject({
      Bucket: payloadBucket,
      Key: payloadKey,
      Body: JSON.stringify(payload)
    }).promise();

    // Start the task in ECS
    const runTaskResponse = await ecs().runTask({
      cluster,
      taskDefinition: asyncOperationTaskDefinition,
      launchType: 'EC2',
      overrides: {
        containerOverrides: [
          {
            name: 'AsyncOperation',
            environment: [
              { name: 'asyncOperationId', value: id },
              { name: 'asyncOperationsTable', value: this.tableName },
              { name: 'lambdaName', value: lambdaName },
              { name: 'payloadUrl', value: `s3://${payloadBucket}/${payloadKey}` }
            ]
          }
        ]
      }
github nasa / cumulus / packages / integration-tests / index.js View on Github external
async function getClusterArn(stackName) {
  const { clusterArns } = await ecs().listClusters().promise();

  const matchingArns = clusterArns.filter((arn) => arn.includes(`${stackName}-CumulusECSCluster`));

  if (matchingArns.length !== 1) {
    throw new Error(`Expected to find 1 cluster but found: ${matchingArns}`);
  }

  return matchingArns[0];
}
github nasa / cumulus / example / spec / scaling / ec2EcsScalingSpec.js View on Github external
it('does not remove all resources', async () => {
      const instances = await ecs().listContainerInstances({ cluster: clusterArn }).promise();
      console.log(`instances : ${JSON.stringify(instances, 2)}`);
      expect(instances.containerInstanceArns.length).toEqual(minInstancesCount);
    });
  });
github nasa / cumulus / packages / tf-inventory / src / stateFile.js View on Github external
async function listClusterEC2Intances(clusterArn) {
  const clusterContainerInstances = await aws.ecs().listContainerInstances({
    cluster: clusterArn
  }).promise()
    .catch((e) => {
      console.log(`Error listing container instances for cluster ${clusterArn}: ${e}`);
      return [];
    });

  if (!clusterContainerInstances || !clusterContainerInstances.containerInstanceArns) {
    return [];
  }

  const containerInstances = await aws.ecs().describeContainerInstances({
    cluster: clusterArn,
    containerInstances: clusterContainerInstances.containerInstanceArns
  }).promise();
github nasa / cumulus / example / spec / scaling / scalingSpec.js View on Github external
async function getClusterStats({
  statTypes = ['runningEC2TasksCount', 'pendingEC2TasksCount']
}) {
  const stats = (await ecs().describeClusters({
    clusters: [clusterArn],
    include: ['STATISTICS']
  }).promise()).clusters[0].statistics;
  const returnedStats = {};
  statTypes.forEach((statType) => {
    returnedStats[statType] = parseInt(find(stats, ['name', statType]).value, 10);
  });
  return returnedStats;
}