Last active
August 3, 2022 09:07
-
-
Save kenoir/40c89e0fb0e13ae141cdc0db607e67f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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