How to use @cumulus/aws-client - 5 common examples

To help you get started, we’ve selected a few @cumulus/aws-client 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 / config.js View on Github external
const loadConfig = async () => {
  await loadEnvFile('./.env');
  verifyRequiredEnvironmentVariables();

  const configFromFile = loadConfigYmlFile(process.env.DEPLOYMENT);

  const buckets = await getJsonS3Object(
    configFromFile.bucket,
    `${configFromFile.stackName}/workflows/buckets.json`
  );

  return { ...configFromFile, buckets };
};
github nasa / cumulus / packages / api / lib / cwSfExecutionEventUtils.js View on Github external
const getFailedExecutionMessage = async (inputMessage) => {
  try {
    const executionArn = getMessageExecutionArn(inputMessage);
    const { events } = await StepFunctions.getExecutionHistory({ executionArn });

    const stepFailedEvents = events.filter(
      (event) =>
        ['ActivityFailed', 'LambdaFunctionFailed'].includes(event.type)
    );
    if (stepFailedEvents.length === 0) {
      log.info(`No failed step events found in execution ${executionArn}`);
      return inputMessage;
    }

    const lastStepFailedEvent = stepFailedEvents[stepFailedEvents.length - 1];
    const failedStepExitedEvent = getStepExitedEvent(events, lastStepFailedEvent);

    if (!failedStepExitedEvent) {
      log.info(
        `Could not retrieve output from last failed step in execution ${executionArn}, falling back to execution input`,
github nasa / cumulus / packages / api / lambdas / manual-consumer.js View on Github external
'use strict';

const awsServices = require('@cumulus/aws-client/services');
const log = require('@cumulus/common/log');

const messageConsumer = require('./message-consumer');

const Kinesis = awsServices.kinesis();
const tallyReducer = (acc, cur) => acc + cur;

/**
 * This function will accept as valid input an event whose `endTimestamp` and `startTimestamp`
 * fields must contain valid input to the `new Date()` constructor if they exist.
 * They will then be populated into `process.env` as ISO strings.
 *
 * @param {Object} event - input object
 */
const configureTimestampEnvs = (event) => {
  if (!process.env.endTimestamp && event.endTimestamp) {
    const dateObj = new Date(event.endTimestamp);
    if (Number.isNaN(dateObj.valueOf())) {
      throw new TypeError(`endTimestamp ${event.endTimestamp} is not a valid input for new Date().`);
    }
    process.env.endTimestamp = dateObj.toISOString();
github nasa / cumulus / packages / api / lambdas / publish-executions.js View on Github external
(record) => {
      const execution = attr.unwrap(record.dynamodb.NewImage);
      return publishSnsMessage(topicArn, execution);
    }
  );
github nasa / cumulus / packages / api / lib / cwSfExecutionEventUtils.js View on Github external
const getCumulusMessageFromExecutionEvent = async (executionEvent) => {
  let cumulusMessage;

  if (executionEvent.detail.status === 'RUNNING') {
    cumulusMessage = JSON.parse(executionEvent.detail.input);
  } else if (executionEvent.detail.status === 'SUCCEEDED') {
    cumulusMessage = JSON.parse(executionEvent.detail.output);
  } else {
    const inputMessage = JSON.parse(get(executionEvent, 'detail.input', '{}'));
    cumulusMessage = await getFailedExecutionMessage(inputMessage);
  }

  const fullCumulusMessage = await pullStepFunctionEvent(cumulusMessage);

  const workflowStatus = executionStatusToWorkflowStatus(executionEvent.detail.status);
  set(fullCumulusMessage, 'meta.status', workflowStatus);

  set(fullCumulusMessage, 'cumulus_meta.workflow_start_time', executionEvent.detail.startDate);
  set(fullCumulusMessage, 'cumulus_meta.workflow_stop_time', executionEvent.detail.stopDate);

  return fullCumulusMessage;
};