How to use the @cumulus/common.aws.buildS3Uri 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 / lambdas / ems-distribution-report.js View on Github external
async function generateAndStoreDistributionReport(params) {
  const {
    reportStartTime,
    reportEndTime
  } = params;

  const distributionReport = await generateDistributionReport({
    reportStartTime,
    reportEndTime
  });

  const { reportsBucket, reportsPrefix } = bucketsPrefixes();
  const reportKey = await determineReportKey(DISTRIBUTION_REPORT, reportStartTime, reportsPrefix);

  const s3Uri = aws.buildS3Uri(reportsBucket, reportKey);
  log.info(`Uploading report to ${s3Uri}`);

  return aws.s3().putObject({
    Bucket: reportsBucket,
    Key: reportKey,
    Body: distributionReport
  }).promise()
    .then(() => ({ reportType: DISTRIBUTION_REPORT, file: s3Uri }));
}
// Export to support testing
github nasa / cumulus / packages / ingest / granule.js View on Github external
async ingestFile(file, destinationBucket, duplicateHandling) {
    const fileRemotePath = path.join(file.path, file.name);
    // place files in the  subdirectory
    const stagingPath = path.join(this.fileStagingDir, this.collectionId);
    const destinationKey = path.join(stagingPath, file.name);

    // the staged file expected
    const stagedFile = Object.assign(cloneDeep(file),
      {
        filename: aws.buildS3Uri(destinationBucket, destinationKey),
        fileStagingDir: stagingPath,
        url_path: this.getUrlPath(file),
        bucket: destinationBucket
      });
    // bind arguments to sync function
    const syncFileFunction = this.sync.bind(this, fileRemotePath);

    const s3ObjAlreadyExists = await aws.s3ObjectExists(
      { Bucket: destinationBucket, Key: destinationKey }
    );
    log.debug(`file ${destinationKey} exists in ${destinationBucket}: ${s3ObjAlreadyExists}`);

    let versionedFiles = [];
    if (s3ObjAlreadyExists) {
      stagedFile.duplicate_found = true;
      const stagedFileKey = `${destinationKey}.${uuidv4()}`;
github nasa / cumulus / packages / cmrjs / cmr-utils.js View on Github external
function generateFileUrl(file, distEndpoint, cmrGranuleUrlType = 'distribution') {
  if (cmrGranuleUrlType === 'distribution') {
    const extension = urljoin(file.bucket, getS3KeyOfFile(file));
    return urljoin(distEndpoint, extension);
  }

  if (cmrGranuleUrlType === 's3') {
    if (file.filename) {
      return file.filename;
    }

    return aws.buildS3Uri(file.bucket, file.key);
  }

  return null;
}
github nasa / cumulus / packages / cmrjs / cmr-utils.js View on Github external
function getS3UrlOfFile(file) {
  if (file.filename) return file.filename;
  if (file.bucket && file.filepath) return aws.buildS3Uri(file.bucket, file.filepath);
  if (file.bucket && file.key) return aws.buildS3Uri(file.bucket, file.key);
  throw new Error(`Unable to determine location of file: ${JSON.stringify(file)}`);
}
github nasa / cumulus / packages / ingest / granule.js View on Github external
return [stagedFile].concat(versionedFiles.map((f) => (
      {
        bucket: destinationBucket,
        name: path.basename(f.Key),
        path: file.path,
        filename: aws.buildS3Uri(f.Bucket, f.Key),
        size: f.size,
        fileStagingDir: stagingPath,
        url_path: this.getUrlPath(file)
      })));
  }
github nasa / cumulus / packages / api / lambdas / ems-ingest-report.js View on Github external
async function uploadReportToS3(filename, reportBucket, reportKey) {
  await aws.s3().putObject({
    Bucket: reportBucket,
    Key: reportKey,
    Body: fs.createReadStream(filename)
  }).promise();

  fs.unlinkSync(filename);
  const s3Uri = aws.buildS3Uri(reportBucket, reportKey);
  log.info(`uploaded ${s3Uri}`);
  return s3Uri;
}