ah-s3-interface

0.2.0 • Public • Published

Anthill AWS S3 / Multiple Module

build status coverage report

This module makes it easy to integrate with the artifacts generated from Anthill CI jobs.

Usage

Add a config file to your project with AWS info.

Require the module and provide path to the AWS config file from module folder.

Example:

aws_config.json

{ "accessKeyId": "XXXXXXXXXXXXXX", "secretAccessKey": "XXXXXXXXXXXXXXXXXXXX", "region": "eu-central-1" }
var s3 = require('ah-s3-interface')('../../aws_config.json');

s3.getJobs('s3-bucket-name', 'my-project-slug', function(err, jobs) {
    console.log('S3 artifacts from jobs for project', jobs);
});

API

getBucketFolders(bucket, next)

List all the folders inside a bucket.

deleteFolder(bucket, project, folders, next)

List all the jobs for a project. Note: folders arguments should be a non-empty array.

getJobs(bucket, project, next)

List all the jobs for a project.

The project parameter is the project name. - in Buildkite: the pipeline slug

Example output:

[ 'jobs/acme-placebo-2016/20/',
  'jobs/acme-placebo-2016/21/' ]

getSignedUrl(bucket, key, next)

Get a signed url for a PDF report.

The key parameter is the AWS file key, e.g. 'jobs/acme-placebo-2016/21/pdf/report.pdf'.

Example:

s3.getSignedUrl('s3-bucket-name', 'jobs/acme-placebo-2016/21/pdf/report.pdf', function(err, url) {
  console.log('Signed URL for report', url);
});

getMetaData(bucket, key, next)

Get a signed url for a PDF report.

The key parameter is the AWS file key, e.g. 'jobs/acme-placebo-2016/21/pdf/report.pdf'.

Example:

s3.getMetaData('s3-bucket-name', 'jobs/acme-placebo-2016/21/pdf/report.pdf', function(err, data) {
  console.log('Signed URL for report', data);
});

Example of meta-data returned:

{ AcceptRanges: 'bytes',
  LastModified: 'Fri, 24 Sep 2017 08:01:20 GMT',
  ContentLength: '17477366',
  ETag: '"9d5025edc4f1ddbe6b3787d9d462cb6a-4"',
  ContentType: 'application/pdf',
  Metadata: {} }

Test

Config

Add AWS key and secret to config_template.json file and rename the file to config.json.

Run

Normal test run:

npm test

Coverage info:

npm run cover

Package Sidebar

Install

npm i ah-s3-interface

Weekly Downloads

1

Version

0.2.0

License

ISC

Last publish

Collaborators

  • sinahwz