Skip to content

Instantly share code, notes, and snippets.

@tsh-code
Created May 6, 2024 09:43
Show Gist options
  • Save tsh-code/46ccf5cd1b0dbded6e3bcaeaf7a2ccd8 to your computer and use it in GitHub Desktop.
Save tsh-code/46ccf5cd1b0dbded6e3bcaeaf7a2ccd8 to your computer and use it in GitHub Desktop.
multiple preloaded lambdas stack
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