npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@slmdevs/aws-tooling

v1.0.3

Published

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

Downloads

9

Readme

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

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

import { S3 } from 'slm-aws-tooling'

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

Response

[{
	"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

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

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

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

import { SecretsManager } from 'slm-aws-tooling'

const data = await SecretsManager.listSecrets()

Response

[{
	"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

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

[{
	"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

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

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

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

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

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')
}