You can do this pretty easily with a local build script like this:
const websiteRedirectFunction = new lambda.Function(
this,
"RedirectFunction",
{
code: lambda.Code.fromAsset(path.resolve(__dirname, "../../redirect"), {
bundling: {
command: [
"bash",
"-c",
"npm install && npm run build && cp -rT /asset-input/dist/ /asset-output/",
],
image: lambda.Runtime.NODEJS_12_X.bundlingDockerImage,
user: "root",
},
}),
handler: "index.redirect",
tracing: lambda.Tracing.ACTIVE,
runtime: lambda.Runtime.NODEJS_12_X,
}
);
Assuming you have a folder that you want to build and upload the handler and node_modules for Lambda.
From the docs:
When using lambda.Code.fromAsset(path) it is possible to bundle the code by running a command in a Docker container. The asset path will be mounted at /asset-input. The Docker container is responsible for putting content at /asset-output. The content at /asset-output will be zipped and used as Lambda code.