Skip to content

Instantly share code, notes, and snippets.

@kenoir
Last active August 3, 2022 09:07
Show Gist options
  • Save kenoir/40c89e0fb0e13ae141cdc0db607e67f5 to your computer and use it in GitHub Desktop.
Save kenoir/40c89e0fb0e13ae141cdc0db607e67f5 to your computer and use it in GitHub Desktop.
type LambdaConfig = Record<string, string>;
type ConfigurableHandler = (config: LambdaConfig) => Promise<void>;
const buildLambdaHandler = (handler: ConfigurableHandler, prefix: string) => {
Log.info(`Finding config for: ${prefix}`);
// Include configuration logic to pull from env or wherever
const config: LambdaConfig = { 'foo/bar': 'baz' };
return () => handler(config);
};
// When you want to build a lambda:
export const myLambdaHandler = async (
config: LambdaConfig,
): Promise<void> => {
Log.info(config);
await Promise.resolve();
};
export const main = buildLambdaHandler(myLambdaHandler, 'myLambda');
if (require.main === module) {
void (async () => await main())();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment