Minimalist AWS Client for Node.js
aws-client is a minimalist Node.js client library providing simplified access to a subset of AWS services. Currently, it supports core operations for DynamoDB (get, batchGet, put, batchPut, query) via `DynamoClient` and SNS (publish) via `SNSClient`. The package is at version 3.0.6 and appears to be actively maintained, with an ongoing migration of "v1 functions" to "v2 functions." A key differentiator is its focus on minimalism and efficiency: v2 functions leverage the modular packages of the AWS SDK v3 internally, reducing the overall dependency footprint compared to requiring the full `aws-sdk` package. However, users employing older "v1 functions" must still explicitly install `aws-sdk` as a peer dependency, a requirement that will be phased out as the migration completes.
Common errors
-
Error: Cannot find module 'aws-sdk'
cause Legacy 'v1' functions were used without installing the `aws-sdk` package, which became an optional peer dependency for those functions starting in v2.fixRun `npm install aws-sdk` if you intend to use 'v1' functions. Otherwise, refactor your code to use 'v2' functions which do not have this dependency. -
TypeError: client.unsupportedMethod is not a function
cause Attempting to call an AWS service method that `aws-client` does not explicitly wrap or support. The library provides a minimalist API.fixVerify that the desired operation is listed in the `aws-client` documentation for the specific client (e.g., `DynamoClient`, `SNSClient`). If not supported, use the official AWS SDK directly for that operation.
Warnings
- gotcha Prior to version 2, `aws-client` functions required the full `aws-sdk` package. With the introduction of 'v2 functions' in version 2, the library began using modular AWS SDK v3 packages internally. However, if you are still using 'v1 functions', you *must* explicitly install `aws-sdk` as a separate dependency.
- gotcha `aws-client` is intentionally minimalist and only supports a limited set of operations for DynamoDB and SNS. It does not provide full coverage of all AWS services or all operations within supported services. Attempting to use an unsupported service or operation will result in runtime errors.
Install
-
npm install aws-client -
yarn add aws-client -
pnpm add aws-client
Imports
- DynamoClient
const DynamoClient = require('aws-client').DynamoClientimport { DynamoClient } from 'aws-client' - SNSClient
const SNSClient = require('aws-client').SNSClientimport { SNSClient } from 'aws-client' - { DynamoClient, SNSClient }
import awsClient from 'aws-client'; const dynamo = new awsClient.DynamoClient(...)
import { DynamoClient, SNSClient } from 'aws-client'
Quickstart
import { DynamoClient } from 'aws-client';
const client = new DynamoClient({
region: 'eu-west-1',
tableName: 'users-prod'
});
const getUser = async (id) => {
try {
const data = await client.get({ id });
console.log('User data:', data);
} catch (error) {
console.error('Error fetching user:', error.message);
}
};
getUser('fred');
// Example: batch operations (if 'users-prod' has items with ids 'fred' and 'jane')
// const getMultipleUsers = async () => {
// const data = await client.batchGet(['fred', 'jane']);
// console.log('Batch user data:', data);
// };
// getMultipleUsers();