Created
May 6, 2024 09:43
-
-
Save tsh-code/46ccf5cd1b0dbded6e3bcaeaf7a2ccd8 to your computer and use it in GitHub Desktop.
multiple preloaded lambdas stack
This file contains 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
import { StackContext, Function, Stack } from "sst/constructs"; | |
const LANGUAGE_PAIRS = [ | |
["es", "en"], | |
["pl", "en"], | |
] as const; | |
interface UnidirectionalTranslation { | |
from: string; | |
to: string; | |
} | |
const getTranslatingFunction = (stack: Stack, { from, to }: UnidirectionalTranslation) => { | |
const key = `${from}-${to}`; | |
const fn = new Function(stack, `StaticTranslations-${key}`, { | |
runtime: "container", | |
handler: "packages/functions/src/preloaded-translation", | |
memorySize: 6000, | |
timeout: "10 minutes", | |
environment: { | |
FROM_LANGUAGE_CODE: from, | |
TO_LANGUAGE_CODE: to, | |
}, | |
container: { | |
buildArgs: { | |
LANGUAGE_CODE_PAIR: key, | |
}, | |
}, | |
}); | |
return { key, fn }; | |
}; | |
export function Translations({ stack }: StackContext) { | |
const translationFn = new Function(stack, "TranslationLambda", { | |
runtime: "container", | |
handler: "packages/functions/src/translation", | |
memorySize: 6000, | |
diskSize: 1024, | |
timeout: "10 minutes", | |
}); | |
const translationFns = LANGUAGE_PAIRS.map(([from, to]) => | |
getTranslatingFunction(stack, { from, to }) | |
); | |
return { translationFn, translationFns }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment