|
| 1 | +# Systemic AWS S3 |
| 2 | + |
| 3 | +A [Systemic](https://guidesmiths.github.io/systemic/#/) component for the [AWS S3 SDK v3](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/index.html). |
| 4 | + |
| 5 | +## How to use it |
| 6 | + |
| 7 | +### Configuration |
| 8 | + |
| 9 | +A typical, simple configuration looks like this: |
| 10 | + |
| 11 | +```json |
| 12 | +{ |
| 13 | + "region": "us-east-1", |
| 14 | + "credentials": { |
| 15 | + "secretAccessKey": "test", |
| 16 | + "accessKeyId": "test" |
| 17 | + } |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +[Here](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html) you can finde the complete configuration interface of S3Client class constructor that set the region, credentials and other options. |
| 22 | + |
| 23 | +### Initialize the component |
| 24 | + |
| 25 | +As with any other [Systemic component](https://guidesmiths.github.io/systemic/#/?id=components), you can run it with the `start` method: |
| 26 | + |
| 27 | +```js |
| 28 | +const initAWSS3 = require('systemic-aws-s3'); |
| 29 | +const { start } = initAWSS3(); |
| 30 | + |
| 31 | +const api = await start({ config }); // configuration similar to the one above |
| 32 | +``` |
| 33 | + |
| 34 | +### Call the API commands |
| 35 | + |
| 36 | +As the AWS API has dozens of commands, intead of having one wrapper for each of them, the component exposes one single command `commandExecutor` that can be used to call any of the commands exposed by the api: |
| 37 | + |
| 38 | +For example, to list all the objects in a specific bucket: |
| 39 | + |
| 40 | +```js |
| 41 | +const listObjectConfig = { |
| 42 | + commandParams: { Bucket: bucketName }, |
| 43 | + commandName: 'listObjects' |
| 44 | +} |
| 45 | +const res = await api.commandExecutor(listObjectConfig); |
| 46 | +``` |
| 47 | + |
| 48 | +You can check all the available commands [here](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/s3.html). |
| 49 | + |
| 50 | +### Custom commands |
| 51 | + |
| 52 | +In the future, this component will also expose some custom commands not supported by the official API. |
| 53 | + |
| 54 | +## Guide for developers |
| 55 | + |
| 56 | +### How to test it |
| 57 | + |
| 58 | +You can test the whole test suite running one of these commands: |
| 59 | + |
| 60 | +```bash |
| 61 | +# all tests will be executed once |
| 62 | +npm run test |
| 63 | + |
| 64 | +# tests will be executed every time code changes (useful when coding) |
| 65 | +npm run test:watch |
| 66 | +``` |
| 67 | + |
| 68 | +In case that you want to just execute a certain test case, you can also use these scripts to up / tear down the infra. |
| 69 | + |
| 70 | +```bash |
| 71 | +npm run infra:up |
| 72 | +npm run infra:down |
| 73 | +``` |
0 commit comments