@praisegeek/serverless-utils
v1.0.6-0
Published
Helper utils and packages when working with serverless lambda
Downloads
9
Readme
Serverless Utils
A collection of helper utilities when working on AWS Serverless lambda.
Install
npm i @praisegeek/serverless-utils
Helpers
- Dynamodb
- API Validation Hooks
- Responses
Dynamodb
Dynamodb local listens on port 8000
Example usage
import { dynamodb as db } from '@praisegeek/serverless-utils';
// Async-Await
async () => {
const user = await db.get('user-table', 1);
console.log(user);
// { id: 1, name: Praise }
};
// Promise
db.get('user-table', 1)
.then((user) => {
console.log(user);
// { id: 1, name: Praise }
})
.catch((err) => {
console.log(err);
});
All Methods
- get
- put
- update
- delete
- query
- scan
- batchGet
- batchWrite
Pagination
Query and Scan returns a nextToken string which is used to get more or previous items
import { dynamodb as db } from '@praisegeek/serverless-utils';
async () => {
const admins = await db.query('user-table', {
IndexName: 'roles',
KeyConditionExpression: 'roles = :roles',
ExpressionAttributeValues: {
':roles': 'admins',
},
NextToken: 'a163c127-7440-4836-85a0-f3b6ef2b51b1',
});
console.log(admins);
// { count: 5, nextToken: 'f7e089d8-bc53-4b01-9e71-92fc9bc60fca', items: [ {id: 1, name: 'Praise' }, ... ] }
};
Milestone
- [x] DynamoDB Helpers
- [x] Request Validations
- [x] Response Headers
- [x] Typescript Support
- [ ] Cognito Authentication ( Email/Password, Social Auth, OpenID )
- [ ] Uploaders
- [ ] Stripe Helpers