How to use the @cumulus/common/aws.s3 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 / api / models / async-operation.js View on Github external
} = params;

    // Create the record in the database
    const id = uuidv4();
    await this.create({
      id,
      status: 'RUNNING',
      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 },
github nasa / cumulus / packages / integration-tests / cmr.js View on Github external
};
  }

  const stagingDir = granule.files[0].fileStagingDir;

  const filename = `${stagingDir}/${granule.granuleId}.cmr.json`;

  const params = {
    Bucket: bucket,
    Key: filename,
    Body: JSON.stringify(jsonObject),
    ContentType: 'application/json',
    Tagging: `granuleId=${granule.granuleId}`
  };

  await s3().putObject(params).promise();

  const granuleFiles = granule.files.map((f) => f.filename);
  granuleFiles.push(`s3://${bucket}/${filename}`);
  log.info(`s3://${bucket}/${filename}`);
  log.info(granuleFiles);
  return granuleFiles;
}
github nasa / cumulus / packages / api / endpoints / distribution.js View on Github external
function getConfigurations() {
  const earthdataLoginClient = EarthdataLogin.createFromEnv({
    redirectUri: process.env.DISTRIBUTION_REDIRECT_ENDPOINT
  });

  return {
    accessTokenModel: new AccessToken(),
    authClient: earthdataLoginClient,
    distributionUrl: process.env.DISTRIBUTION_ENDPOINT,
    s3Client: s3()
  };
}
github nasa / cumulus / cumulus / tasks / validate-pdr / index.js View on Github external
function fetchPdr(bucket, key) {
  return aws.s3().getObject({ Bucket: bucket, Key: key }).promise()
    .then((response) => response.Body.toString());
}
github nasa / cumulus / packages / api / bin / serve.js View on Github external
async function prepareServices(stackName, bucket) {
  setLocalEsVariables(stackName);
  await bootstrap.bootstrapElasticSearch(process.env.ES_HOST, process.env.ES_INDEX);
  await s3().createBucket({ Bucket: bucket }).promise();
}
github nasa / cumulus / tf-modules / distribution / index.js View on Github external
function getConfigurations() {
  const earthdataLoginClient = EarthdataLogin.createFromEnv({
    redirectUri: process.env.DISTRIBUTION_REDIRECT_ENDPOINT
  });

  return {
    accessTokenModel: new AccessToken(),
    authClient: earthdataLoginClient,
    distributionUrl: process.env.DISTRIBUTION_ENDPOINT,
    s3Client: s3()
  };
}
github nasa / cumulus / packages / api / endpoints / dashboard.js View on Github external
async function get(req, res) {
  const [Bucket, Key] = getFileBucketAndKey(req.params[0]);

  return s3().getObject({ Bucket, Key })
    .on('httpHeaders', (code, headers) => {
      res.set('Content-Type', headers['content-type']);
    })
    .createReadStream()
    .pipe(res);
}
github nasa / cumulus / packages / ingest / lock.js View on Github external
async function countLock(bucket, pName) {
  const list = aws.s3().listObjectsV2({
    Bucket: bucket,
    Prefix: `${lockPrefix}/${pName}`
  }).promise();
  const count = checkOldLocks(bucket, list.Contents);
  return count;
}
github nasa / cumulus / example / spec / setup / PopulateProvidersCollections.js View on Github external
function uploadTestDataToS3(file, bucket) {
  const data = fs.readFileSync(require.resolve(file), 'utf8');
  const key = path.basename(file);

  return s3().putObject({
    Bucket: bucket,
    Key: `cumulus-test-data/pdrs/${key}`,
    Body: data
  }).promise();
}