Skip to content

Commit

Permalink
fix: Node16 runtime (#52)
Browse files Browse the repository at this point in the history
* remove compatible runtimes for layer - node 18 not supported much yet

* Use NODE_16_X runtime everywhere

* lint

* aws-cdk-lib 2.50.0
  • Loading branch information
revmischa authored Dec 15, 2022
1 parent 4819d91 commit 7293b41
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { awscdk } = require('projen');
const project = new awscdk.AwsCdkConstructLibrary({
author: 'JetBridge',
authorAddress: '[email protected]',
cdkVersion: '2.53.0',
cdkVersion: '2.50.0',
defaultReleaseBranch: 'main',
name: 'cdk-nextjs-standalone',
repositoryUrl: 'https://github.com/jetbridge/cdk-nextjs.git',
Expand Down
4 changes: 2 additions & 2 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/ImageOptimizationLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as fs from 'fs';
import * as path from 'path';
import { Duration } from 'aws-cdk-lib';
import { Policy, PolicyStatement } from 'aws-cdk-lib/aws-iam';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { FunctionOptions } from 'aws-cdk-lib/aws-lambda';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import { IBucket } from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
import { LAMBDA_RUNTIME } from './constants';
import { NextjsBaseProps } from './NextjsBase';
import type { NextjsBuild } from './NextjsBuild';
import { NextjsLayer } from './NextjsLayer';
Expand Down Expand Up @@ -40,8 +40,6 @@ export interface ImageOptimizationProps extends NextjsBaseProps {
readonly nextBuild: NextjsBuild;
}

const RUNTIME = lambda.Runtime.NODEJS_18_X;

/**
* This lambda handles image optimization.
*/
Expand Down Expand Up @@ -69,7 +67,7 @@ export class ImageOptimizationLambda extends NodejsFunction {

super(scope, id, {
entry: imageOptHandlerPath,
runtime: RUNTIME,
runtime: LAMBDA_RUNTIME,
bundling: {
commandHooks: {
beforeBundling(_: string, outputDir: string): string[] {
Expand Down
4 changes: 2 additions & 2 deletions src/NextjsDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as s3 from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
import * as fs from 'fs-extra';
import { bundleFunction } from './BundleFunction';
import { DEFAULT_STATIC_MAX_AGE } from './constants';
import { DEFAULT_STATIC_MAX_AGE, LAMBDA_RUNTIME } from './constants';
import { BaseSiteDomainProps, buildErrorResponsesForRedirectToIndex, NextjsBaseProps } from './NextjsBase';
import { NextjsBuild } from './NextjsBuild';

Expand Down Expand Up @@ -520,7 +520,7 @@ export class NextjsDistribution extends Construct {
});

const fn = new cloudfront.experimental.EdgeFunction(this, 'DefaultOriginRequestEdgeFn', {
runtime: lambda.Runtime.NODEJS_16_X,
runtime: LAMBDA_RUNTIME,
// role,
handler: 'LambdaOriginRequest.handler',
code: lambda.Code.fromAsset(dirname(outputPath)),
Expand Down
5 changes: 2 additions & 3 deletions src/NextjsLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { StringParameter } from 'aws-cdk-lib/aws-ssm';
import { Construct } from 'constructs';
import * as fs from 'fs-extra';
import { bundleFunction } from './BundleFunction';
import { LAMBDA_RUNTIME } from './constants';
import { CONFIG_ENV_JSON_PATH } from './Nextjs';
import { NextjsBaseProps } from './NextjsBase';
import { createArchive, NextjsBuild } from './NextjsBuild';
Expand Down Expand Up @@ -39,8 +40,6 @@ export interface NextjsLambdaProps extends NextjsBaseProps {
readonly lambda?: FunctionOptions;
}

const RUNTIME = lambda.Runtime.NODEJS_16_X;

/**
* Build a lambda function from a NextJS application to handle server-side rendering, API routes, and image optimization.
*/
Expand Down Expand Up @@ -105,7 +104,7 @@ export class NextJsLambda extends Construct {
const fn = new Function(scope, 'ServerHandler', {
memorySize: functionOptions?.memorySize || 1024,
timeout: functionOptions?.timeout ?? Duration.seconds(10),
runtime: RUNTIME,
runtime: LAMBDA_RUNTIME,
handler: path.join(props.nextjsPath, 'server.handler'),
code,
environment,
Expand Down
1 change: 0 additions & 1 deletion src/NextjsLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class NextjsLayer extends LayerVersion {
const layerDir = path.resolve(__dirname, '../assets');
super(scope, id, {
code: new lambda.AssetCode(path.join(layerDir, 'sharp-0.30.0.zip')),
compatibleRuntimes: [lambda.Runtime.NODEJS_16_X, lambda.Runtime.NODEJS_18_X],
description: 'Sharp for Lambdas',
...props,
});
Expand Down
3 changes: 2 additions & 1 deletion src/NextjsS3EnvRewriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Bucket, IBucket } from 'aws-cdk-lib/aws-s3';
import * as cr from 'aws-cdk-lib/custom-resources';
import { Construct } from 'constructs';
import { bundleFunction } from './BundleFunction';
import { LAMBDA_RUNTIME } from './constants';
import { NextjsBaseProps } from './NextjsBase';
import { makeTokenPlaceholder, NextjsBuild } from './NextjsBuild';

Expand Down Expand Up @@ -65,7 +66,7 @@ export class NextjsS3EnvRewriter extends Construct {

// rewriter lambda function
const rewriteFn = new lambda.Function(this, 'RewriteOnEventHandler', {
runtime: lambda.Runtime.NODEJS_16_X,
runtime: LAMBDA_RUNTIME,
memorySize: 1024,
timeout: Duration.minutes(5),
handler: 'S3EnvRewriter.handler',
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Duration } from 'aws-cdk-lib';
import { Runtime } from 'aws-cdk-lib/aws-lambda';

export const DEFAULT_STATIC_MAX_AGE = Duration.days(30).toSeconds();
export const DEFAULT_STATIC_STALE_WHILE_REVALIDATE = Duration.days(1).toSeconds();

export const LAMBDA_RUNTIME = Runtime.NODEJS_16_X;
26 changes: 4 additions & 22 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7293b41

Please sign in to comment.