Skip to content

Commit

Permalink
fix: Skip image fn bundling if placeholder (#57)
Browse files Browse the repository at this point in the history
* Skip image fn bundling if placeholder

* placeholder fn

* node16 target
  • Loading branch information
revmischa authored Dec 17, 2022
1 parent 7293b41 commit bb8ec5f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
6 changes: 6 additions & 0 deletions assets/lambda/ImageOptimization/placeholder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { APIGatewayProxyHandlerV2 } from 'aws-lambda';

export const handler: APIGatewayProxyHandlerV2 = async (event) => ({
statusCode: 200,
body: 'Placeholder function is deployed',
});
42 changes: 23 additions & 19 deletions src/ImageOptimizationLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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
Expand Down

0 comments on commit bb8ec5f

Please sign in to comment.