Skip to content

Commit 52ae047

Browse files
feat: updated naming for edge functions
1 parent 1721ce6 commit 52ae047

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

src/cdk/constructs/RoutingLambdaEdge.ts renamed to src/cdk/constructs/OriginRequestLambdaEdge.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import path from 'node:path'
88
import { buildLambda } from '../../build/edge'
99
import { CacheConfig } from '../../types'
1010

11-
interface RoutingLambdaEdgeProps extends cdk.StackProps {
11+
interface OriginRequestLambdaEdgeProps extends cdk.StackProps {
1212
bucketName: string
1313
renderServerDomain: string
1414
buildOutputPath: string
@@ -22,15 +22,15 @@ const NodeJSEnvironmentMapping: Record<string, lambda.Runtime> = {
2222
'20': lambda.Runtime.NODEJS_20_X
2323
}
2424

25-
export class RoutingLambdaEdge extends Construct {
25+
export class OriginRequestLambdaEdge extends Construct {
2626
public readonly lambdaEdge: cloudfront.experimental.EdgeFunction
2727

28-
constructor(scope: Construct, id: string, props: RoutingLambdaEdgeProps) {
28+
constructor(scope: Construct, id: string, props: OriginRequestLambdaEdgeProps) {
2929
const { bucketName, bucketRegion, renderServerDomain, nodejs, buildOutputPath, cacheConfig } = props
3030
super(scope, id)
3131

3232
const nodeJSEnvironment = NodeJSEnvironmentMapping[nodejs ?? ''] ?? NodeJSEnvironmentMapping['20']
33-
const name = 'edgeRouting'
33+
const name = 'originRequest'
3434

3535
buildLambda(name, buildOutputPath, {
3636
define: {
@@ -41,13 +41,13 @@ export class RoutingLambdaEdge extends Construct {
4141
}
4242
})
4343

44-
const logGroup = new logs.LogGroup(this, 'RoutingLambdaEdgeLogGroup', {
45-
logGroupName: `/aws/lambda/${id}-edgeRouting`,
44+
const logGroup = new logs.LogGroup(this, 'OriginRequestLambdaEdgeLogGroup', {
45+
logGroupName: `/aws/lambda/${id}-originRequest`,
4646
removalPolicy: cdk.RemovalPolicy.DESTROY,
4747
retention: logs.RetentionDays.ONE_DAY
4848
})
4949

50-
this.lambdaEdge = new cloudfront.experimental.EdgeFunction(this, 'RoutingLambdaEdge', {
50+
this.lambdaEdge = new cloudfront.experimental.EdgeFunction(this, 'OriginRequestLambdaEdge', {
5151
runtime: nodeJSEnvironment,
5252
code: lambda.Code.fromAsset(path.join(buildOutputPath, 'server-functions', name)),
5353
handler: 'index.handler',

src/cdk/constructs/CheckExpirationLambdaEdge.ts renamed to src/cdk/constructs/OriginResponseLambdaEdge.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import path from 'node:path'
88
import { buildLambda } from '../../build/edge'
99
import { CacheConfig } from '../../types'
1010

11-
interface CheckExpirationLambdaEdgeProps extends cdk.StackProps {
11+
interface OriginResponseLambdaEdgeProps extends cdk.StackProps {
1212
renderWorkerQueueUrl: string
1313
renderWorkerQueueArn: string
1414
buildOutputPath: string
@@ -22,15 +22,15 @@ const NodeJSEnvironmentMapping: Record<string, lambda.Runtime> = {
2222
'20': lambda.Runtime.NODEJS_20_X
2323
}
2424

25-
export class CheckExpirationLambdaEdge extends Construct {
25+
export class OriginResponseLambdaEdge extends Construct {
2626
public readonly lambdaEdge: cloudfront.experimental.EdgeFunction
2727

28-
constructor(scope: Construct, id: string, props: CheckExpirationLambdaEdgeProps) {
28+
constructor(scope: Construct, id: string, props: OriginResponseLambdaEdgeProps) {
2929
const { nodejs, buildOutputPath, cacheConfig, renderWorkerQueueUrl, renderWorkerQueueArn, region } = props
3030
super(scope, id)
3131

3232
const nodeJSEnvironment = NodeJSEnvironmentMapping[nodejs ?? ''] ?? NodeJSEnvironmentMapping['20']
33-
const name = 'checkExpiration'
33+
const name = 'originResponse'
3434

3535
buildLambda(name, buildOutputPath, {
3636
define: {
@@ -40,13 +40,13 @@ export class CheckExpirationLambdaEdge extends Construct {
4040
}
4141
})
4242

43-
const logGroup = new logs.LogGroup(this, 'CheckExpirationLambdaEdgeLogGroup', {
44-
logGroupName: `/aws/lambda/${id}-checkExpiration`,
43+
const logGroup = new logs.LogGroup(this, 'OriginResponseLambdaEdgeLogGroup', {
44+
logGroupName: `/aws/lambda/${id}-originResponse`,
4545
removalPolicy: cdk.RemovalPolicy.DESTROY,
4646
retention: logs.RetentionDays.ONE_DAY
4747
})
4848

49-
this.lambdaEdge = new cloudfront.experimental.EdgeFunction(this, 'CheckExpirationLambdaEdge', {
49+
this.lambdaEdge = new cloudfront.experimental.EdgeFunction(this, 'OriginResponseLambdaEdge', {
5050
runtime: nodeJSEnvironment,
5151
code: lambda.Code.fromAsset(path.join(buildOutputPath, 'server-functions', name)),
5252
handler: 'index.handler',

src/cdk/stacks/NextCloudfrontStack.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Stack, type StackProps } from 'aws-cdk-lib'
22
import { Construct } from 'constructs'
33
import * as s3 from 'aws-cdk-lib/aws-s3'
4-
import { RoutingLambdaEdge } from '../constructs/RoutingLambdaEdge'
4+
import { OriginRequestLambdaEdge } from '../constructs/OriginRequestLambdaEdge'
55
import { CloudFrontDistribution } from '../constructs/CloudFrontDistribution'
66
import { CacheConfig } from '../../types'
7-
import { CheckExpirationLambdaEdge } from '../constructs/CheckExpirationLambdaEdge'
7+
import { OriginResponseLambdaEdge } from '../constructs/OriginResponseLambdaEdge'
88
import { ViewerResponseLambdaEdge } from '../constructs/ViewerResponseLambdaEdge'
99

1010
export interface NextCloudfrontStackProps extends StackProps {
@@ -20,8 +20,8 @@ export interface NextCloudfrontStackProps extends StackProps {
2020
}
2121

2222
export class NextCloudfrontStack extends Stack {
23-
public readonly routingLambdaEdge: RoutingLambdaEdge
24-
public readonly checkExpLambdaEdge: CheckExpirationLambdaEdge
23+
public readonly originRequestLambdaEdge: OriginRequestLambdaEdge
24+
public readonly originResponseLambdaEdge: OriginResponseLambdaEdge
2525
public readonly viewerResponseLambdaEdge: ViewerResponseLambdaEdge
2626
public readonly cloudfront: CloudFrontDistribution
2727

@@ -39,7 +39,7 @@ export class NextCloudfrontStack extends Stack {
3939
imageTTL
4040
} = props
4141

42-
this.routingLambdaEdge = new RoutingLambdaEdge(this, `${id}-RoutingLambdaEdge`, {
42+
this.originRequestLambdaEdge = new OriginRequestLambdaEdge(this, `${id}-OriginRequestLambdaEdge`, {
4343
nodejs,
4444
bucketName: staticBucketName,
4545
renderServerDomain,
@@ -48,7 +48,7 @@ export class NextCloudfrontStack extends Stack {
4848
bucketRegion: region
4949
})
5050

51-
this.checkExpLambdaEdge = new CheckExpirationLambdaEdge(this, `${id}-CheckExpirationLambdaEdge`, {
51+
this.originResponseLambdaEdge = new OriginResponseLambdaEdge(this, `${id}-OriginResponseLambdaEdge`, {
5252
nodejs,
5353
renderWorkerQueueUrl,
5454
buildOutputPath,
@@ -70,14 +70,14 @@ export class NextCloudfrontStack extends Stack {
7070
this.cloudfront = new CloudFrontDistribution(this, `${id}-NextCloudFront`, {
7171
staticBucket,
7272
renderServerDomain,
73-
requestEdgeFunction: this.routingLambdaEdge.lambdaEdge,
74-
responseEdgeFunction: this.checkExpLambdaEdge.lambdaEdge,
73+
requestEdgeFunction: this.originRequestLambdaEdge.lambdaEdge,
74+
responseEdgeFunction: this.originResponseLambdaEdge.lambdaEdge,
7575
viewerResponseEdgeFunction: this.viewerResponseLambdaEdge.lambdaEdge,
7676
cacheConfig,
7777
imageTTL
7878
})
7979

80-
staticBucket.grantRead(this.routingLambdaEdge.lambdaEdge)
81-
staticBucket.grantRead(this.checkExpLambdaEdge.lambdaEdge)
80+
staticBucket.grantRead(this.originRequestLambdaEdge.lambdaEdge)
81+
staticBucket.grantRead(this.originResponseLambdaEdge.lambdaEdge)
8282
}
8383
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)