Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@noths/cloud-utils
Advanced tools
A collection of helpful Node.JS utility functions which are used across Lambda (and other) serverless functions.
Wraps function execution with encrypted secrets from AWS SSM Parameter Store using a specific key, provided that the executing IAM Role has sufficient privileges to do so.
import { withParameters } from '@noths/cloud-utils';
const SECRET_KEY = '/path/to/ssm/encrypted/secret';
const ALIAS = 'SUPER_SECRET_KEY';
const myFn = async ({ [ALIAS]: key }, a, b) => {
return thirdPartyApi(key).someOperation(a, b);
};
export default withParameters({ [ALIAS]: SECRET_KEY })(myFn);
Elsewhere in the application, this function can be consumed as:
import myFn from './some-file';
const handler = async (a, b, ...other) => {
const { result } = await myFn(a, b);
return result;
};
Wraps modules & functions, providing AWS XRay tracing for trace execution. You may also provide a recognizable name for the module to be traced, in addition to custom metadata, annotations and captured functions as subsegments.
Note, functions wrapped with captureFunc
or captureFuncSync
should have a withTracing
higher in their call stack; otherwise XRay will throw an error, as no namespace, segment or context has been configured.
import { captureFunc } from '@aerofer/utils/tools/tracing';
import someRemoteOperation from 'some-other-module';
const OPERATION = 'Some Remote Operation';
const metadata = {
version: '0.0.1',
};
// capture arguments and add as annotations
const capture = (a, b) => ({ a, b });
const handler = async (a, b) => {
const { body } = await someRemoteOperation(a, b);
return body;
}
export default captureFunc(OPERATION, { metadata, capture })(handler);
import { captureFuncSync } from '@aerofer/utils/tools/tracing';
import captureSync from 'some-other-module';
const CAPTURE = 'Capture';
const handler = (customerId, amount) => {
const annotations = { customerId };
const capture = captureFuncSync(CAPTURE, { annotations })(captureSync);
return capture(customerId, amount);
};
export default handler;
Provides a helpful utility for optionally wrapping low-level, native error objects from libraries with application errors which can be:
import { withProperties } from '@noths/cloud-utils/tools/errors';
export const FOOBAR_ERROR = 'FoobarError';
const errors = {
...(withProperties(FOOBAR_ERROR, { statusCode: 400, message: 'A foobar error occurred' })),
};
export default errors;
When you need to throw an error of this type inside your application, you can instantiate it like so:
import Errors, { FOOBAR_ERROR } from './errors';
const { [FOOBAR_ERROR]: LogicalError } = Errors;
const fn = (cb) => {
someOperation((err, data) => {
if (err) {
throw new LogicalError('overrides default message', err);
} else {
cb(data);
}
})
};
Simple logger for serializing objects and application errors into JSON lines for inspection and JSONPath filtering.
import Logger from '@noths/cloud-utils/tools/logger';
const TIME_TAKEN = 'ExecutionTimeTaken';
const reporter = (time) => ({ time, type: TIME_TAKEN });
const handler = async () => {
const start = +new Date();
const data = await processor();
const end = +new Date();
Logger.info(reporter(end - start));
return data;
};
There are two environment variables you can set, in-order to control the logger:
LOG_LEVEL
- The level of logging to produce output for.HTTP Responders wrap response objects from Lambda Proxy functions (or any other mechanism), enabling the easy serialization of Javascript objects whether it is a success or failure.
import { success, failure } from '@noths/cloud-utils/tools/responders';
// Object containing security HTTP headers & CORS
import headers from './headers';
export const handler = async (event, context, cb) => {
try {
const result = await processor(event);
const response = success({ code: 201, headers, body: result });
cb(null, response);
} catch (err) {
if (err.statusCode) {
// application error
cb(null, failure(event, err));
} else {
// native error
cb(err);
}
}
};
FAQs
Functional cloud utilities for NOTHS Serverless Cloud Applications
The npm package @noths/cloud-utils receives a total of 0 weekly downloads. As such, @noths/cloud-utils popularity was classified as not popular.
We found that @noths/cloud-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.