Skip to content

Commit

Permalink
Merge pull request #1258 from aligent/hotfix/Fix-Imports
Browse files Browse the repository at this point in the history
Fix imports of experimental cloudfront lambda@edge functions
  • Loading branch information
AdamJHall authored Dec 4, 2023
2 parents 8ee4a1c + 49c807b commit f15b234
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 138 deletions.
44 changes: 24 additions & 20 deletions packages/basic-auth/lib/basic-auth-construct.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Construct } from "constructs";
import { EdgeFunction } from "aws-cdk-lib/aws-cloudfront/lib/experimental";
import { experimental } from "aws-cdk-lib/aws-cloudfront";
import { Esbuild } from "@aligent/cdk-esbuild";
import { AssetHashType, DockerImage } from "aws-cdk-lib";
import { Code, IVersion, Runtime, Version } from "aws-cdk-lib/aws-lambda";
Expand All @@ -11,7 +11,7 @@ export interface BasicAuthFunctionOptions {
}

export class BasicAuthFunction extends Construct {
readonly edgeFunction: EdgeFunction;
readonly edgeFunction: experimental.EdgeFunction;

constructor(scope: Construct, id: string, options: BasicAuthFunctionOptions) {
super(scope, id);
Expand All @@ -22,24 +22,28 @@ export class BasicAuthFunction extends Construct {
'echo "Docker build not supported. Please install esbuild."',
];

this.edgeFunction = new EdgeFunction(this, `${id}-basic-auth-fn`, {
code: Code.fromAsset(join(__dirname, "handlers"), {
assetHashType: AssetHashType.OUTPUT,
bundling: {
command,
image: DockerImage.fromRegistry("busybox"),
local: new Esbuild({
entryPoints: [join(__dirname, "handlers/basic-auth.ts")],
define: {
"process.env.AUTH_USERNAME": options.username,
"process.env.AUTH_PASSWORD": options.password,
},
}),
},
}),
runtime: Runtime.NODEJS_18_X,
handler: "basic-auth.handler",
});
this.edgeFunction = new experimental.EdgeFunction(
this,
`${id}-basic-auth-fn`,
{
code: Code.fromAsset(join(__dirname, "handlers"), {
assetHashType: AssetHashType.OUTPUT,
bundling: {
command,
image: DockerImage.fromRegistry("busybox"),
local: new Esbuild({
entryPoints: [join(__dirname, "handlers/basic-auth.ts")],
define: {
"process.env.AUTH_USERNAME": options.username,
"process.env.AUTH_PASSWORD": options.password,
},
}),
},
}),
runtime: Runtime.NODEJS_18_X,
handler: "basic-auth.handler",
}
);
}

public getFunctionVersion(): IVersion {
Expand Down
38 changes: 21 additions & 17 deletions packages/cloudfront-security-headers/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AssetHashType, DockerImage } from "aws-cdk-lib";
import { EdgeFunction } from "aws-cdk-lib/aws-cloudfront/lib/experimental";
import { experimental } from "aws-cdk-lib/aws-cloudfront";
import { Code, IVersion, Runtime, Version } from "aws-cdk-lib/aws-lambda";
import { Construct } from "constructs";
import { join } from "path";
Expand All @@ -10,7 +10,7 @@ export interface SecurityHeaderFunctionProps {
}

export class SecurityHeaderFunction extends Construct {
readonly edgeFunction: EdgeFunction;
readonly edgeFunction: experimental.EdgeFunction;

constructor(
scope: Construct,
Expand All @@ -35,21 +35,25 @@ export class SecurityHeaderFunction extends Construct {
'echo "Docker build not supported. Please install esbuild."',
];

this.edgeFunction = new EdgeFunction(this, `${id}-security-header-fn`, {
code: Code.fromAsset(join(__dirname, "handlers"), {
assetHashType: AssetHashType.OUTPUT,
bundling: {
command,
image: DockerImage.fromRegistry("busybox"),
local: new Esbuild({
entryPoints: [join(__dirname, "handlers/security-header.ts")],
define: defineOptions,
}),
},
}),
runtime: Runtime.NODEJS_18_X,
handler: "security-header.handler",
});
this.edgeFunction = new experimental.EdgeFunction(
this,
`${id}-security-header-fn`,
{
code: Code.fromAsset(join(__dirname, "handlers"), {
assetHashType: AssetHashType.OUTPUT,
bundling: {
command,
image: DockerImage.fromRegistry("busybox"),
local: new Esbuild({
entryPoints: [join(__dirname, "handlers/security-header.ts")],
define: defineOptions,
}),
},
}),
runtime: Runtime.NODEJS_18_X,
handler: "security-header.handler",
}
);
}

public getFunctionVersion(): IVersion {
Expand Down
48 changes: 26 additions & 22 deletions packages/geoip-redirect/lib/redirect-construct.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AssetHashType, DockerImage } from "aws-cdk-lib";
import { EdgeFunction } from "aws-cdk-lib/aws-cloudfront/lib/experimental";
import { experimental } from "aws-cdk-lib/aws-cloudfront";
import { Code, IVersion, Runtime, Version } from "aws-cdk-lib/aws-lambda";
import { Construct } from "constructs";
import { join } from "path";
Expand All @@ -14,7 +14,7 @@ export interface RedirectFunctionOptions {
}

export class RedirectFunction extends Construct {
readonly edgeFunction: EdgeFunction;
readonly edgeFunction: experimental.EdgeFunction;

constructor(scope: Construct, id: string, options: RedirectFunctionOptions) {
super(scope, id);
Expand All @@ -25,26 +25,30 @@ export class RedirectFunction extends Construct {
'echo "Docker build not supported. Please install esbuild."',
];

this.edgeFunction = new EdgeFunction(this, `${id}-redirect-fn`, {
code: Code.fromAsset(join(__dirname, "handlers"), {
assetHashType: AssetHashType.OUTPUT,
bundling: {
command,
image: DockerImage.fromRegistry("busybox"),
local: new Esbuild({
entryPoints: [join(__dirname, "handlers/redirect.ts")],
define: {
"process.env.REDIRECT_HOST": options.redirectHost,
"process.env.SUPPORTED_REGIONS":
options.supportedRegionsExpression,
"process.env.DEFAULT_REGION": options.defaultRegion,
},
}),
},
}),
runtime: Runtime.NODEJS_18_X,
handler: "redirect.handler",
});
this.edgeFunction = new experimental.EdgeFunction(
this,
`${id}-redirect-fn`,
{
code: Code.fromAsset(join(__dirname, "handlers"), {
assetHashType: AssetHashType.OUTPUT,
bundling: {
command,
image: DockerImage.fromRegistry("busybox"),
local: new Esbuild({
entryPoints: [join(__dirname, "handlers/redirect.ts")],
define: {
"process.env.REDIRECT_HOST": options.redirectHost,
"process.env.SUPPORTED_REGIONS":
options.supportedRegionsExpression,
"process.env.DEFAULT_REGION": options.defaultRegion,
},
}),
},
}),
runtime: Runtime.NODEJS_18_X,
handler: "redirect.handler",
}
);
}

public getFunctionVersion(): IVersion {
Expand Down
42 changes: 23 additions & 19 deletions packages/prerender-proxy/lib/error-response-construct.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AssetHashType, DockerImage } from "aws-cdk-lib";
import { EdgeFunction } from "aws-cdk-lib/aws-cloudfront/lib/experimental";
import { experimental } from "aws-cdk-lib/aws-cloudfront";
import { Code, IVersion, Runtime, Version } from "aws-cdk-lib/aws-lambda";
import { Construct } from "constructs";
import { join } from "path";
Expand All @@ -10,7 +10,7 @@ export interface ErrorResponseFunctionOptions {
}

export class ErrorResponseFunction extends Construct {
readonly edgeFunction: EdgeFunction;
readonly edgeFunction: experimental.EdgeFunction;

constructor(
scope: Construct,
Expand All @@ -25,23 +25,27 @@ export class ErrorResponseFunction extends Construct {
'echo "Docker build not supported. Please install esbuild."',
];

this.edgeFunction = new EdgeFunction(this, `${id}-error-response-fn`, {
code: Code.fromAsset(join(__dirname, "handlers"), {
assetHashType: AssetHashType.OUTPUT,
bundling: {
command,
image: DockerImage.fromRegistry("busybox"),
local: new Esbuild({
entryPoints: [join(__dirname, "handlers/error-response.ts")],
define: {
"process.env.PATH_PREFIX": options.pathPrefix ?? "",
},
}),
},
}),
runtime: Runtime.NODEJS_18_X,
handler: "error-response.handler",
});
this.edgeFunction = new experimental.EdgeFunction(
this,
`${id}-error-response-fn`,
{
code: Code.fromAsset(join(__dirname, "handlers"), {
assetHashType: AssetHashType.OUTPUT,
bundling: {
command,
image: DockerImage.fromRegistry("busybox"),
local: new Esbuild({
entryPoints: [join(__dirname, "handlers/error-response.ts")],
define: {
"process.env.PATH_PREFIX": options.pathPrefix ?? "",
},
}),
},
}),
runtime: Runtime.NODEJS_18_X,
handler: "error-response.handler",
}
);
}

public getFunctionVersion(): IVersion {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AssetHashType, DockerImage } from "aws-cdk-lib";
import { EdgeFunction } from "aws-cdk-lib/aws-cloudfront/lib/experimental";
import { experimental } from "aws-cdk-lib/aws-cloudfront";
import { Code, IVersion, Runtime, Version } from "aws-cdk-lib/aws-lambda";
import { Construct } from "constructs";
import { join } from "path";
Expand All @@ -11,7 +11,7 @@ export interface CloudFrontCacheControlOptions {
}

export class CloudFrontCacheControl extends Construct {
readonly edgeFunction: EdgeFunction;
readonly edgeFunction: experimental.EdgeFunction;

constructor(
scope: Construct,
Expand All @@ -26,26 +26,30 @@ export class CloudFrontCacheControl extends Construct {
'echo "Docker build not supported. Please install esbuild."',
];

this.edgeFunction = new EdgeFunction(this, `${id}-cache-control-fn`, {
code: Code.fromAsset(join(__dirname, "handlers"), {
assetHashType: AssetHashType.OUTPUT,
bundling: {
command,
image: DockerImage.fromRegistry("busybox"),
local: new Esbuild({
entryPoints: [join(__dirname, "handlers/cache-control.ts")],
define: {
"process.env.PRERENDER_CACHE_KEY":
options?.cacheKey ?? "x-prerender-requestid",
"process.env.PRERENDER_CACHE_MAX_AGE":
String(options?.maxAge) ?? "0",
},
}),
},
}),
runtime: Runtime.NODEJS_18_X,
handler: "cache-control.handler",
});
this.edgeFunction = new experimental.EdgeFunction(
this,
`${id}-cache-control-fn`,
{
code: Code.fromAsset(join(__dirname, "handlers"), {
assetHashType: AssetHashType.OUTPUT,
bundling: {
command,
image: DockerImage.fromRegistry("busybox"),
local: new Esbuild({
entryPoints: [join(__dirname, "handlers/cache-control.ts")],
define: {
"process.env.PRERENDER_CACHE_KEY":
options?.cacheKey ?? "x-prerender-requestid",
"process.env.PRERENDER_CACHE_MAX_AGE":
String(options?.maxAge) ?? "0",
},
}),
},
}),
runtime: Runtime.NODEJS_18_X,
handler: "cache-control.handler",
}
);
}

public getFunctionVersion(): IVersion {
Expand Down
36 changes: 20 additions & 16 deletions packages/prerender-proxy/lib/prerender-check-construct.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AssetHashType, DockerImage } from "aws-cdk-lib";
import { EdgeFunction } from "aws-cdk-lib/aws-cloudfront/lib/experimental";
import { experimental } from "aws-cdk-lib/aws-cloudfront";
import { Code, IVersion, Runtime, Version } from "aws-cdk-lib/aws-lambda";
import { Construct } from "constructs";
import { join } from "path";
import { Esbuild } from "@aligent/cdk-esbuild";

export class PrerenderCheckFunction extends Construct {
readonly edgeFunction: EdgeFunction;
readonly edgeFunction: experimental.EdgeFunction;

constructor(scope: Construct, id: string) {
super(scope, id);
Expand All @@ -17,20 +17,24 @@ export class PrerenderCheckFunction extends Construct {
'echo "Docker build not supported. Please install esbuild."',
];

this.edgeFunction = new EdgeFunction(this, `${id}-prerender-check-fn`, {
code: Code.fromAsset(join(__dirname, "handlers"), {
assetHashType: AssetHashType.OUTPUT,
bundling: {
command,
image: DockerImage.fromRegistry("busybox"),
local: new Esbuild({
entryPoints: [join(__dirname, "handlers/prerender-check.ts")],
}),
},
}),
runtime: Runtime.NODEJS_18_X,
handler: "prerender-check.handler",
});
this.edgeFunction = new experimental.EdgeFunction(
this,
`${id}-prerender-check-fn`,
{
code: Code.fromAsset(join(__dirname, "handlers"), {
assetHashType: AssetHashType.OUTPUT,
bundling: {
command,
image: DockerImage.fromRegistry("busybox"),
local: new Esbuild({
entryPoints: [join(__dirname, "handlers/prerender-check.ts")],
}),
},
}),
runtime: Runtime.NODEJS_18_X,
handler: "prerender-check.handler",
}
);
}

public getFunctionVersion(): IVersion {
Expand Down
Loading

0 comments on commit f15b234

Please sign in to comment.