From bb8ec5fa3519ff74580e5ddaba25675ef33ddc78 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sat, 17 Dec 2022 04:50:03 +0200 Subject: [PATCH] fix: Skip image fn bundling if placeholder (#57) * Skip image fn bundling if placeholder * placeholder fn * node16 target --- .../lambda/ImageOptimization/placeholder.ts | 6 +++ src/ImageOptimizationLambda.ts | 42 ++++++++++--------- 2 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 assets/lambda/ImageOptimization/placeholder.ts diff --git a/assets/lambda/ImageOptimization/placeholder.ts b/assets/lambda/ImageOptimization/placeholder.ts new file mode 100644 index 00000000..0c94c861 --- /dev/null +++ b/assets/lambda/ImageOptimization/placeholder.ts @@ -0,0 +1,6 @@ +import { APIGatewayProxyHandlerV2 } from 'aws-lambda'; + +export const handler: APIGatewayProxyHandlerV2 = async (event) => ({ + statusCode: 200, + body: 'Placeholder function is deployed', +}); diff --git a/src/ImageOptimizationLambda.ts b/src/ImageOptimizationLambda.ts index 5eb00047..e033c630 100644 --- a/src/ImageOptimizationLambda.ts +++ b/src/ImageOptimizationLambda.ts @@ -47,7 +47,7 @@ export class ImageOptimizationLambda extends NodejsFunction { bucket: IBucket; constructor(scope: Construct, id: string, props: ImageOptimizationProps) { - const { lambdaOptions, bucket } = props; + const { lambdaOptions, bucket, isPlaceholder } = props; const lambdaPath = path.resolve(__dirname, '../assets/lambda/ImageOptimization'); const imageOptHandlerPath = path.resolve(lambdaPath, 'index.ts'); @@ -66,26 +66,30 @@ export class ImageOptimizationLambda extends NodejsFunction { if (!fs.existsSync(target)) fs.symlinkSync(source, target, 'dir'); super(scope, id, { - entry: imageOptHandlerPath, + entry: isPlaceholder + ? path.join(__dirname, '../assets/lambda/ImageOptimization/placeholder.ts') + : imageOptHandlerPath, runtime: LAMBDA_RUNTIME, - bundling: { - commandHooks: { - beforeBundling(_: string, outputDir: string): string[] { - // Saves the required-server-files.json to the .next folder - const filePath = path.join(props.nextBuild.nextStandaloneBuildDir, 'required-server-files.json'); - return [`mkdir -p "${outputDir}/.next"`, `cp "${filePath}" "${outputDir}/.next"`]; + bundling: isPlaceholder + ? undefined + : { + commandHooks: { + beforeBundling(_: string, outputDir: string): string[] { + // Saves the required-server-files.json to the .next folder + const filePath = path.join(props.nextBuild.nextStandaloneBuildDir, 'required-server-files.json'); + return [`mkdir -p "${outputDir}/.next"`, `cp "${filePath}" "${outputDir}/.next"`]; + }, + afterBundling() { + return []; + }, + beforeInstall() { + return []; + }, + }, + minify: true, + target: 'node16', + externalModules: ['@aws-sdk/client-s3'], }, - afterBundling() { - return []; - }, - beforeInstall() { - return []; - }, - }, - minify: true, - target: 'node18', - externalModules: ['@aws-sdk/client-s3'], - }, layers: [props.nextLayer], ...lambdaOptions, // defaults