How to use the @cumulus/common/aws.dynamodb 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 / packages / integration-tests / index.js View on Github external
async function waitForAsyncOperationStatus({
  TableName,
  id,
  status,
  retries = 10
}) {
  const { Item } = await dynamodb().getItem({
    TableName,
    Key: { id: { S: id } }
  }).promise();

  if (Item.status.S === status || retries <= 0) return Item;

  await sleep(2000);
  return waitForAsyncOperationStatus({
    TableName,
    id,
    status,
    retries: retries - 1
  });
}
github nasa / cumulus / packages / api / models / base.js View on Github external
params.AttributeDefinitions.push({
      AttributeName: range.name,
      AttributeType: range.type
    });
  }

  if (attributes) {
    attributes.forEach((attribute) => {
      params.AttributeDefinitions.push({
        AttributeName: attribute.name,
        AttributeType: attribute.type
      });
    });
  }

  const output = await aws.dynamodb().createTable(params).promise();
  await aws.dynamodb().waitFor('tableExists', { TableName: tableName }).promise();

  if (!inTestMode()) await enableStream(tableName);

  return output;
}
github nasa / cumulus / packages / api / models / base.js View on Github external
};

  if (range) {
    params.KeySchema.push({
      AttributeName: range.name,
      KeyType: 'RANGE'
    });

    params.AttributeDefinitions.push({
      AttributeName: range.name,
      AttributeType: range.type
    });
  }

  const output = await aws.dynamodb().createTable(params).promise();
  await aws.dynamodb().waitFor('tableExists', { TableName: tableName }).promise();

  if (!inTestMode()) await enableStream(tableName);

  return output;
}
github nasa / cumulus / packages / api / es / indexer.js View on Github external
const recordsCount = flatten([executionRecord, granuleRecords, pdrRecord]).length;

  if (recordsCount > 10 || inTestMode()) {
    if (executionRecord) await executionModel.create(executionRecord);
    if (pdrRecord) await pdrModel.create(pdrRecord);
    await granuleModel.create(granuleRecords);
  }
  else if (recordsCount > 0) {
    const TransactItems = flatten([
      buildTransactPut(executionModel.tableName, executionRecord),
      buildTransactPut(pdrModel.tableName, pdrRecord),
      granuleRecords.map(buildTransactPut(granuleModel.tableName))
    ]).filter(isNotNil);

    await dynamodb().transactWriteItems({ TransactItems }).promise();
  }

  return {
    sf: executionRecord,
    pdr: pdrRecord,
    granule: isEmpty(granuleRecords) ? null : granuleRecords
  };
}
github nasa / cumulus / packages / api / models / base.js View on Github external
async () =>
      aws.dynamodb().describeTable({ TableName: tableName }).promise()
        .then((response) => response.TableStatus !== 'UPDATING'),
    { interval: 5 * 1000 }
github nasa / cumulus / packages / api / models / base.js View on Github external
async function enableStream(tableName) {
  const params = {
    TableName: tableName,
    StreamSpecification: {
      StreamEnabled: true,
      StreamViewType: 'NEW_AND_OLD_IMAGES'
    }
  };

  await aws.dynamodb().updateTable(params).promise();

  await pWaitFor(
    async () =>
      aws.dynamodb().describeTable({ TableName: tableName }).promise()
        .then((response) => response.TableStatus !== 'UPDATING'),
    { interval: 5 * 1000 }
  );
}
github nasa / cumulus / packages / api / models / base.js View on Github external
async function deleteTable(tableName) {
  const output = await aws.dynamodb().deleteTable({
    TableName: tableName
  }).promise();

  await aws.dynamodb().waitFor('tableNotExists', { TableName: tableName }).promise();
  return output;
}
github nasa / cumulus / packages / api / models / base.js View on Github external
AttributeName: range.name,
      AttributeType: range.type
    });
  }

  if (attributes) {
    attributes.forEach((attribute) => {
      params.AttributeDefinitions.push({
        AttributeName: attribute.name,
        AttributeType: attribute.type
      });
    });
  }

  const output = await aws.dynamodb().createTable(params).promise();
  await aws.dynamodb().waitFor('tableExists', { TableName: tableName }).promise();

  if (!inTestMode()) await enableStream(tableName);

  return output;
}
github nasa / cumulus / packages / api / models / base.js View on Github external
}
  };

  if (range) {
    params.KeySchema.push({
      AttributeName: range.name,
      KeyType: 'RANGE'
    });

    params.AttributeDefinitions.push({
      AttributeName: range.name,
      AttributeType: range.type
    });
  }

  const output = await aws.dynamodb().createTable(params).promise();
  await aws.dynamodb().waitFor('tableExists', { TableName: tableName }).promise();

  if (!inTestMode()) await enableStream(tableName);

  return output;
}