Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@genie-solutions/lambda-toolbelt
Advanced tools
Set of reusable tools to make writing new Lambda functions a breeze.
import { applyMiddleware, httpHandler, withJSONBody, HTTPEvent, HTTPContext } from 'genie-lambda-toolbelt';
const myHelloWorldFunction = async (event: HTTPEvent, context: HTTPContext): Promise<object> => {
const { genie: { body } } = context;
return {
message: `Hello, ${body.name}`,
};
};
export default applyMiddleware(httpHandler, withJSONBody)(myHelloWorldFunction);
Automatically verifies and parses the payload of a JWT token being provided via a HTTP header.
Example:
import { createParameterStore, applyMiddleware, httpHandler, withJWTPayload } from 'genie-lambda-toolbelt';
const mySuperSecretFunction = async (event: HTTPEvent, context: HTTPContext): Promise<object> => {
const { userId, tenantId, roleId } = context.genie.jwt.role;
return Promise.resolve('Oll Korrect (yep, that is what OK stands for)');
};
const parameterStore = createParameterStore();
const getPublicKey = () => parameterStore('JWT_PUBLIC_KEY');
export default applyMiddleware(
httpHandler,
withJWTPayload({
getPublicKey,
algorithm: 'RS256',
headerName: 'X-GENIE-ROLES',
payloadKey: 'role',
}),
)(mySuperSecretFunction);
Automatically add parameters into genie context and validate any required params.
Example:
import {
applyMiddleware,
httpHandler,
withJSONBody,
withParameters,
HTTPEvent,
HTTPContext
} from 'genie-lambda-toolbelt';
// These interfaces should be in type.ts, here is just quick example
interface MyPathParamsContext {
pathParameters: {
pathParam1: string;
}
}
interface MyQueryStringParamsContext {
queryStringParameters: {
qsParam1: string;
qsParam2: string;
}
}
interface MyBodyContext {
body: {
bodyParam1: string;
bodyParam2: number;
}
}
type MyCustomContext = HTTPContext<MyBodyContext & MyPathParamsContext & MyQueryStringParamsContext>;
const mySuperSweetFunction = async (event: HTTPEvent, context: MyCustomContext): Promise<object> => {
const genie = context.genie;
const { pathParam1 } = genie.pathParameters;
const { qsParam1, qsParam2 } = genie.queryStringParameters;
const { bodyParam1, bodyParam2 } = genie.body;
return {};
};
export default applyMiddleware(
httpHandler,
withJSONBody,
withParameters({
// These fields should be defined when actually required
requiredPathParams: ['pathParam1'],
requiredJsonBodyParams: ['bodyParam1', 'bodyParam2'],
requiredQueryStringParams: ['qsParam1', 'qsParam2'],
}),
)(mySuperSweetFunction);
Automatically validate required clientId and assign to genie
Example:
import { applyMiddleware, httpHandler, withClientId, withJSONBody, HTTPContext, ClientIdContext } from 'genie-lambda-toolbelt';
// These interfaces should be in type.ts, here is just quick example
type MyCustomContext = HTTPContext<ClientIdContext>;
const mySuperSweetFunction = async (event: HTTPEvent, context: MyCustomContext): Promise<object> => {
const { genie: { clientId } } = event;
return {};
};
export default applyMiddleware(
httpHandler,
withJSONBody,
withClientId,
)(mySuperSweetFunction);
Many times you will want to custom your own HTTPContext and extends it with many other available Context such as ClientIdContext, JwtContext To do this, you can leverage HTTPContext<T1 & T2 & ... & TN> to mix n-contexts into One Final Interface
Example:
import {
applyMiddleware,
httpHandler,
withClientId,
withJSONBody,
HTTPEvent,
HTTPContext,
JwtContext,
ClientIdContext
} from 'genie-lambda-toolbelt';
interface MyBodyContext {
body: {
bodyParam1: string;
bodyParam2: number;
}
}
type MyCustomContext = HTTPContext<MyBodyContext & ClientIdContext & JwtContext>;
const mySuperSweetFunction = async (event: HTTPEvent, context: MyCustomContext): Promise<object> => {
// Then you can use your Customized Context with the combined structure
const genie = context.genie;
const { bodyParam1, bodyParam2 } = genie.body;
const { roles } = genie.jwt;
const { clientId } = genie;
return {};
};
export default applyMiddleware(
httpHandler,
withJSONBody,
withClientId,
)(mySuperSweetFunction);
FAQs
Toolbelt for creating Lambda functions
The npm package @genie-solutions/lambda-toolbelt receives a total of 0 weekly downloads. As such, @genie-solutions/lambda-toolbelt popularity was classified as not popular.
We found that @genie-solutions/lambda-toolbelt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.