1.1.1 • Published 4 years ago

@travetto/asset-s3 v1.1.1

Weekly downloads
131
License
MIT
Repository
github
Last release
4 years ago

S3 Asset Source

AWS S3 backend for the travetto asset module

Install: @travetto/asset-s3

npm install @travetto/asset-s3

This provides a s3 implementation of the AssetSource which is a backend for the Asset module.

Code: S3 backend wiring

import { InjectableFactory } from '@travetto/di';
import { S3AssetSource, S3AssetConfig } from '@travetto/asset-s3';

class AppConfig {
  @InjectableFactory()
  static getSource(cfg: S3AssetConfig) {
    return new S3AssetSource(cfg);
  }
}

There is a default configuration that you can easily use, with some sensible defaults.

Code: S3 Configuration

import { fromIni } from '@aws-sdk/credential-provider-ini';
import * as S3 from '@aws-sdk/client-s3';
import { EnvUtil } from '@travetto/boot';
import { Config } from '@travetto/config';

/**
 * S3 Support as an Asset Source
 */
@Config('s3.asset')
export class S3AssetConfig {
  region = 'us-east-1'; // AWS Region
  namespace = ''; // S3 Bucket folder
  bucket = ''; // S3 bucket

  accessKeyId = EnvUtil.get('AWS_ACCESS_KEY_ID') ?? '';
  secretAccessKey = EnvUtil.get('AWS_SECRET_ACCESS_KEY') ?? '';
  config: S3.S3ClientConfig; // Additional s3 config

  chunkSize = 5 * 2 ** 20; // Chunk size in bytes

  /**
   * Provide host to bucket
   */
  get hostName() {
    return `${this.bucket}.s3.amazonaws.com`;
  }

  /**
   * Produces the s3 config from the provide details, post construction
   */
  async postConstruct() {
    if (!this.accessKeyId && !this.secretAccessKey) {
      const creds = await fromIni({ profile: EnvUtil.get('AWS_PROFILE') })();
      this.accessKeyId = creds.accessKeyId;
      this.secretAccessKey = creds.secretAccessKey;
    }

    this.config = {
      credentials: {
        accessKeyId: this.accessKeyId,
        secretAccessKey: this.secretAccessKey
      }
    };
  }
}

Additionally, you can see that the class is registered with the @Config annotation, and so these values can be overridden using the standard Configuration resolution paths.

Note: Do not commit your accessKeyId or secretAccessKey values to your source repository, especially if it is public facing. Not only is it a security risk, but Amazon will scan public repos, looking for keys, and if found will react swiftly.

1.1.1

4 years ago

1.1.0

4 years ago

1.1.0-rc.0

4 years ago

1.1.0-alpha.6

4 years ago

1.1.0-alpha.5

4 years ago

1.1.0-alpha.3

4 years ago

1.1.0-alpha.4

4 years ago

1.1.0-alpha.2

4 years ago

1.1.0-alpha.1

4 years ago

1.1.0-alpha.0

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-rc.9

4 years ago

1.0.0-rc.8

4 years ago

1.0.0-rc.7

4 years ago

1.0.0-rc.6

4 years ago

1.0.0-rc.5

4 years ago

1.0.0-rc.4

4 years ago

1.0.0-rc.3

4 years ago

1.0.0-rc.2

4 years ago

1.0.0-rc.1

4 years ago

1.0.0-rc.0

4 years ago

1.0.0-beta.3

5 years ago

1.0.0-beta.2

5 years ago

1.0.0-beta.1

5 years ago

0.7.4

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.1-alpha.6

5 years ago

0.7.1-alpha.5

5 years ago

0.7.1-alpha.4

5 years ago

0.7.1-alpha.3

5 years ago

0.7.1-alpha.2

5 years ago

0.7.1-alpha.1

5 years ago

0.7.1-alpha.0

5 years ago

0.7.0-alpha.0

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.6.0-rc.10

5 years ago

0.6.0-rc.9

5 years ago

0.6.0-rc.8

5 years ago

0.6.0-rc.7

5 years ago

0.6.0-rc.6

5 years ago

0.6.0-rc.4

5 years ago

0.6.0-rc.3

5 years ago

0.6.0-rc.2

5 years ago

0.6.0-rc.1

5 years ago

0.6.0-rc.0

5 years ago

0.5.12

5 years ago

0.5.11

5 years ago

0.5.10

5 years ago

0.5.9

5 years ago

0.5.8

5 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.12

5 years ago

0.4.11

5 years ago

0.4.10

5 years ago

0.4.9

5 years ago

0.4.8

6 years ago

0.4.7

6 years ago

0.4.6

6 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.21

6 years ago

0.3.20

6 years ago

0.3.19

6 years ago

0.3.18

6 years ago

0.3.17

6 years ago

0.3.16

6 years ago

0.3.15

6 years ago

0.3.14

6 years ago

0.3.13

6 years ago

0.3.12

6 years ago

0.3.11

6 years ago

0.3.10

6 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.0

6 years ago

0.2.14

6 years ago

0.2.13

6 years ago

0.2.12

6 years ago

0.2.11

6 years ago

0.2.10

6 years ago

0.2.9

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.5

6 years ago

0.2.2

6 years ago

0.2.0

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago