NPM Package containing utility functions for interaction with AWS services from within other AWS services.

If used on more than one lambda, consider adding this package to an AWS Layer and adding that layer to your Lambda function, instead of adding this package to each lambda individually. This will reduce bundlesize and make versioning much easier.

****

#	S3



##	listBuckets

Async function that returns a list of buckets belonging to the current account / organisation.

**Execution**
```javascript 
import { S3 } from 'slm-aws-tooling'

const data = await S3.listBuckets()
console.log(data)	// [{ bucketName: '<bucketName>', created: '<creationDate>' }]
```




## listBucketObjects

Async function that returns a list of the objects stored in the specified bucket

**Parameters**

| Name | Type | Example | Description |
|------|------|---------|-------------|
| bucketName | String | myBucketName | The name of the target S3 Bucket |
| maxObjects (optional) | Number | 5 | The maximum amount of objects listed |

**Execution**
```javascript 
import { S3 } from 'slm-aws-tooling'

const data = await S3.listBucketObjects('myBucket')
```

**Response**

```json 
[{
	"name": "data.zip",
	"lastModified": "21-02-202",
	"size": "2kb",
	"storage": "standard",
	"owner": "SLM"
}]
```


##	readFromBucket

Function responsible for reading a single object from the specified S3 Bucket. Returns the content as a Buffer.

**Parameters**

| Name | Type | Example | Description |
|------|------|---------|-------------|
| bucketName | String | myBucketName | The name of the target S3 Bucket |
| objectKey | String | data.json | The name of the target object, including file extension |

**Execution**
```javascript 
import { S3 } from 'slm-aws-tooling'

const data = await S3.readFromBucket('myBucketName', 'data.json')
console.log(data)	// Contents of file "data.json" in Bucket "myBucketName"
```




##	writeToBucket

Async function responsible for writing the provided data to a file inside the specified S3 Bucket. **IMPORTANT** - If the file already exists, it is overwritten.

**Parameters**

| Name | Type | Example | Description |
|------|------|---------|-------------|
| bucketName | String | myBucketName | The name of the target S3 Bucket |
| objectKey | String | data.json | The name of the target object, including file extension |
| data | any | "I love Javascript" | The content that is written into the file |

**Execution**
```javascript 
import { S3 } from 'slm-aws-tooling'

const data = await S3.writeToBucket(
	'myBucketName',
	'data.json',
	JSON.stringify({ message: 'My name is Slim Shady' }
)
```





##	deleteFromBucket

Async function responsible for deleting an object with the specified key from the specified S3 Bucket.

**Parameters**

| Name | Type | Example | Description |
|------|------|---------|-------------|
| bucketName | String | myBucketName | The name of the target S3 Bucket |
| objectKey | String | data.json | The name of the target object, including file extension |

**Execution**
```javascript 
import { S3 } from 'slm-aws-tooling'

const data = await S3.deleteFromBucket('myBucketName', 'data.json')
console.log(data)	// [{ bucketName: '<bucketName>', created: '<creationDate>' }]
```

****



#	SecretsManager


## 	listSecrets

Async function that returns a list of secrets available in the provided region

**Parameters**

| Name | Type | Example | Description |
|------|------|---------|-------------|
| region (optional) | String | eu-north-1 | The targeted AWS region. Defaults to **eu-north-1** |

**Execution**
```javascript 
import { SecretsManager } from 'slm-aws-tooling'

const data = await SecretsManager.listSecrets()
```

**Response**
```json
[{
	"name": "API_SECRETS",
	"description": "Secret that holds our API secrets",
	"arn": "<secret ARN>",
	"lastAccessed": "<lastaccessedDates>"
}]
```



##	readSecret

Async function that returns the requested secret as a JSON string

| Name | Type | Example | Description |
|------|------|---------|-------------|
| secretId | String | API_SECRETS | The ID / Name of the secret requested |
| region (optional) | String | eu-north-1 | The targeted AWS region. Defaults to **eu-north-1** |

**Execution**
```javascript 
import { SecretsManager } from 'slm-aws-tooling'

const data = await SecretsManager.readSecret('API_SECRETS')
console.log(JSON.parse(data)) // { API_KEY: 'aqwcs23rqh2', API_URL: 'https://swapi.co/' }
```

**Response**
```json
[{
	"API_KEY": "aqwcs23rqh2",
	"API_URL": "https://swapi.co/"
}]
```



****


#	DynamoDB


##	getTableData

Returns data about the specified table, if it exists

**Parameters**

| Name | Type | Example | Description |
|------|------|---------|-------------|
| tableName | String | myTable | The name of thet targeted DynamoDB Table |

**Execution**

```javascript 
import { DynamoDB } from 'slm-aws-tooling'

const data = await DynamoDB
	.getTableData('tableName')
```



##	getItemsFromTable

Queries the specified table for items matching the provided query and returns them in an array

**Parameters**

| Name | Type | Example | Description |
|------|------|---------|-------------|
| tableName | String | users | The name of thet targeted DynamoDB Table |
| query | object | { userIsActive: true } | The query to filter items by |

**Execution**

```javascript 
import { DynamoDB } from 'slm-aws-tooling'

const data = await DynamoDB
	.getItemsFromTable('users', { userIsActive: true })
console.log(data)	// [{ userId: '123', userIsActive: true }, { userId: '4332', userIsActive: true }]
```



##	getSingleItemFromTable

Queries the specified table for an item matching the provided query and returns it

**Parameters**

| Name | Type | Example | Description |
|------|------|---------|-------------|
| tableName | String | users | The name of thet targeted DynamoDB Table |
| query | object | { userIsActive: true } | The query to filter items by |

**Execution**

```javascript 
import { DynamoDB } from 'slm-aws-tooling'

const data = await DynamoDB
	.getSingleItemFromTable('users', { userIsActive: true })
console.log(data)	// [{ userId: '123', userIsActive: true }]
```




##	putItemstoTable

Queries the specified table for an item matching the provided query and returns it

**Parameters**

| Name | Type | Example | Description |
|------|------|---------|-------------|
| tableName | String | tags | The name of thet targeted DynamoDB Table |
| data | object | { tagId: 'x-im-tag-12', tagName: 'polis' } | The item to be written into the table |

**Execution**

```javascript 
import { DynamoDB } from 'slm-aws-tooling'

try {
	await DynamoDB
		.putItemstoTable('tags', { tagId: 'x-im-tag-12', tagName: 'polis' })
} catch (err) {
	console.log('Something went wrong')
}
```




##	deleteItemsFromTable

Queries the specified table for an item matching the provided query and returns it

**Parameters**

| Name | Type | Example | Description |
|------|------|---------|-------------|
| tableName | String | tags | The name of thet targeted DynamoDB Table |
| query | object Array | { tagId: 'x-im-tag-12', tagName: 'polis' } | A list of filter objects to match and delete |

**Execution**

```javascript 
import { DynamoDB } from 'slm-aws-tooling'

try {
	await DynamoDB
		.deleteItemsFromTable('tags', [{ tagId: 'x-im-tag-12', tagName: 'polis' }])
} catch (err) {
	console.log('Something went wrong')
}
```

