How to use the @cumulus/common/aws.lambda 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 / parallel / testAPI / snsRuleSpec.js View on Github external
afterAll(async () => {
    await SNS.deleteTopic({ TopicArn: snsTopicArn }).promise();

    try {
      const permissionParams = {
        FunctionName: consumerName,
        StatementId: `${ruleName}Permission`
      };
      await lambda().removePermission(permissionParams).promise();
    } catch (err) {
      // If the deletion test passed, this _should_ fail.  This is just handling
      // the case where the deletion test did not properly clean this up.
    }
  });
github nasa / cumulus / packages / api / models / rules.js View on Github external
async addKinesisEventSource(item, lambda) {
    // use the existing event source mapping if it already exists and is enabled
    const listParams = {
      FunctionName: lambda.name,
      EventSourceArn: item.rule.value
    };
    const listData = await aws.lambda().listEventSourceMappings(listParams).promise();
    if (listData.EventSourceMappings && listData.EventSourceMappings.length > 0) {
      const currentMapping = listData.EventSourceMappings[0];

      // This is for backwards compatibility. Mappings should no longer be disabled.
      if (currentMapping.State === 'Enabled') {
        return currentMapping;
      }
      return aws.lambda().updateEventSourceMapping({
        UUID: currentMapping.UUID,
        Enabled: true
      }).promise();
    }

    // create event source mapping
    const params = {
      EventSourceArn: item.rule.value,
      FunctionName: lambda.name,
      StartingPosition: 'TRIM_HORIZON',
      Enabled: true
    };
    return aws.lambda().createEventSourceMapping(params).promise();
  }
github nasa / cumulus / packages / api / models / rules.js View on Github external
async addKinesisEventSource(item, lambda) {
    // use the existing event source mapping if it already exists and is enabled
    const listParams = {
      FunctionName: lambda.name,
      EventSourceArn: item.rule.value
    };
    const listData = await aws.lambda().listEventSourceMappings(listParams).promise();
    if (listData.EventSourceMappings && listData.EventSourceMappings.length > 0) {
      const currentMapping = listData.EventSourceMappings[0];

      // This is for backwards compatibility. Mappings should no longer be disabled.
      if (currentMapping.State === 'Enabled') {
        return currentMapping;
      }
      return aws.lambda().updateEventSourceMapping({
        UUID: currentMapping.UUID,
        Enabled: true
      }).promise();
    }

    // create event source mapping
    const params = {
      EventSourceArn: item.rule.value,
github nasa / cumulus / packages / api / models / rules.js View on Github external
Protocol: 'lambda',
        Endpoint: process.env.messageConsumer,
        ReturnSubscriptionArn: true
      };
      const r = await aws.sns().subscribe(subscriptionParams).promise();
      subscriptionArn = r.SubscriptionArn;
    }
    // create permission to invoke lambda
    const permissionParams = {
      Action: 'lambda:InvokeFunction',
      FunctionName: process.env.messageConsumer,
      Principal: 'sns.amazonaws.com',
      SourceArn: item.rule.value,
      StatementId: `${item.name}Permission`
    };
    await aws.lambda().addPermission(permissionParams).promise();
    return subscriptionArn;
  }
github nasa / cumulus / packages / api / models / rules.js View on Github external
return currentMapping;
      }
      return aws.lambda().updateEventSourceMapping({
        UUID: currentMapping.UUID,
        Enabled: true
      }).promise();
    }

    // create event source mapping
    const params = {
      EventSourceArn: item.rule.value,
      FunctionName: lambda.name,
      StartingPosition: 'TRIM_HORIZON',
      Enabled: true
    };
    return aws.lambda().createEventSourceMapping(params).promise();
  }
github nasa / cumulus / packages / api / models / rules.js View on Github external
async deleteSnsTrigger(item) {
    // delete permission statement
    const permissionParams = {
      FunctionName: process.env.messageConsumer,
      StatementId: `${item.name}Permission`
    };
    await aws.lambda().removePermission(permissionParams).promise();
    // delete sns subscription
    const subscriptionParams = {
      SubscriptionArn: item.rule.arn
    };
    return aws.sns().unsubscribe(subscriptionParams).promise();
  }
github nasa / cumulus / packages / integration-tests / lambda.js View on Github external
async function getLambdaAliases(lambdaFunctionName) {
  const config = {
    MaxItems: 10000,
    FunctionName: lambdaFunctionName
  };
  return getAllPages(config, 'Aliases', lambda().listAliases.bind(lambda()));
}
github nasa / cumulus / packages / api / bin / cli.js View on Github external
.action((cmd) => {
    if (!cmd.migrationVersion) {
      throw new Error('version argument is missing');
    }
    if (!cmd.stack) {
      throw new Error('stack name is missing');
    }
    const l = lambda();
    console.log(`Invoking migration: ${cmd.migrationVersion}`);
    l.invoke({
      FunctionName: `${cmd.stack}-executeMigrations`,
      Payload: `{ "migrations": ["${cmd.migrationVersion}"] }`
    }).promise().then(console.log).catch(console.error);
  });
github nasa / cumulus / packages / api / models / rules.js View on Github external
async deleteKinesisEventSource(item, eventType) {
    if (await this.isEventSourceMappingShared(item, eventType)) {
      return undefined;
    }
    const params = {
      UUID: item.rule[this.eventMapping[eventType]]
    };
    return aws.lambda().deleteEventSourceMapping(params).promise();
  }