a useful utility for serverless systems in AWS.
gamma is designed to be a reusable library which encapsulates much of the common boilerplate needed by lambda functions in a serverless system:
- caching ssm configuration accross function invocations
- logging to cloudwatch and configurable log levels
- a informative Error base class
const gamma = require('node-gamma');
gamma.log.setLogLevel('debug');
gamma.log.error(new gamma.error.InternalError({ some: 'thing' }));
gamma.log.debug('some debug');
gamma.log.info('some info');
gamma.log.setLogLevel('info');
gamma.log.error(new gamma.error.InternalError({ some: 'thing' }));
gamma.log.debug('wont log');
gamma.log.info('some info');
gamma.log.setLogLevel('info');
gamma.log.error(new Error('this is an error'));
gamma.setInstanceProps({
sourceRequestId: '1234',
instanceRequestId: '9876',
event: { ok: 'ok' }
});
console.log(gamma.getInstanceProps());
gamma.log.info('some info');
gamma.clearInstanceProps();
const delay = (t) => {
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, t);
});
};
const multifetch = async () => {
const f1 = await gamma.config.get('/secret');
await delay(5000);
const f2 = await gamma.config.get('/secret');
await delay(5000);
const f3 = await gamma.config.get('/secret');
}
Promise.resolve()
.then(() => {
gamma.config.init({ prefix: '/some', maxAge: 7000 });
// fetch, cached, refetch
return multifetch();
})
.then(() => {
gamma.config.init({ prefix: '/some' });
// fetch, cached, cached
return multifetch();
});