From c3557ab3f6f080831b9148ec986d46a22138009d Mon Sep 17 00:00:00 2001 From: kakakakakku Date: Sun, 19 Oct 2025 21:10:07 +0900 Subject: [PATCH 1/5] apig-waf: Delete dist/ files --- apig-waf/src/api/dist/index.js | 43 ------------------------------ apig-waf/src/api/dist/index.js.map | 7 ----- 2 files changed, 50 deletions(-) delete mode 100644 apig-waf/src/api/dist/index.js delete mode 100644 apig-waf/src/api/dist/index.js.map diff --git a/apig-waf/src/api/dist/index.js b/apig-waf/src/api/dist/index.js deleted file mode 100644 index b1d197ea9..000000000 --- a/apig-waf/src/api/dist/index.js +++ /dev/null @@ -1,43 +0,0 @@ -var __defProp = Object.defineProperty; -var __markAsModule = (target) => __defProp(target, "__esModule", {value: true}); -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, {get: all[name], enumerable: true}); -}; - -// api/lambda/index.ts -__markAsModule(exports); -__export(exports, { - ProxyLambda: () => handler -}); - -// api/config.json -var prefix = "WAFAPIGateway"; -var description = "A VPC Lambda to get request from API Gateway protected by WAF"; -var api = { - handler: "ProxyLambda" -}; -var headers = { - "Content-Type": "text/plain;charset=utf-8" -}; -var tags = [ - {key: "Key", value: "Value"}, - {key: "Project", value: "APIGatewayWAF"} -]; -var config_default = { - prefix, - description, - api, - headers, - tags -}; - -// api/lambda/api-handler.ts -var handler = async (event) => { - return { - body: `Success path: "${event.path}"`, - headers: config_default.headers, - statusCode: 200 - }; -}; -//# sourceMappingURL=index.js.map diff --git a/apig-waf/src/api/dist/index.js.map b/apig-waf/src/api/dist/index.js.map deleted file mode 100644 index 31bcc2b73..000000000 --- a/apig-waf/src/api/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lambda/index.ts", "../lambda/api-handler.ts"], - "sourcesContent": ["export { handler as ProxyLambda } from \"./api-handler\";", "\nimport { Handler } from \"aws-lambda\";\nimport config from \"../config.json\";\n\nexport const handler: Handler = async (event) => {\n return {\n body: `Success path: \"${event.path}\"`,\n headers: config.headers,\n statusCode: 200,\n };\n};"], - "mappings": ";;;;;;;;AAAA;AAAA;AAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;ACIO,IAAM,UAAmB,OAAO,UAAU;AAC/C,SAAO;AAAA,IACL,MAAM,kBAAkB,MAAM;AAAA,IAC9B,SAAS,eAAO;AAAA,IAChB,YAAY;AAAA;AAAA;", - "names": [] -} From 840e5e9967f8fea3b3b172979c50f44952d80c56 Mon Sep 17 00:00:00 2001 From: kakakakakku Date: Sun, 19 Oct 2025 21:12:20 +0900 Subject: [PATCH 2/5] apig-waf: Update CDK v2 --- apig-waf/src/api/index.ts | 14 +++++++------- apig-waf/src/index.ts | 2 +- apig-waf/src/package.json | 10 ++++------ apig-waf/src/waf/index.ts | 7 ++++--- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/apig-waf/src/api/index.ts b/apig-waf/src/api/index.ts index 95ffe9960..f20dcf7f9 100644 --- a/apig-waf/src/api/index.ts +++ b/apig-waf/src/api/index.ts @@ -1,13 +1,13 @@ - -import { LambdaRestApi } from "@aws-cdk/aws-apigateway"; -import * as lambda from "@aws-cdk/aws-lambda"; -import * as cdk from "@aws-cdk/core"; +import * as cdk from "aws-cdk-lib"; +import { LambdaRestApi } from "aws-cdk-lib/aws-apigateway"; +import * as lambda from "aws-cdk-lib/aws-lambda"; +import { Construct } from 'constructs'; import path from "path"; import config from "./config.json"; -import {PolicyStatement, ServicePrincipal, Effect, PolicyDocument, AnyPrincipal } from '@aws-cdk/aws-iam'; +import {PolicyStatement, ServicePrincipal, Effect, PolicyDocument, AnyPrincipal } from 'aws-cdk-lib/aws-iam'; export class ApiStack extends cdk.Stack { - constructor(scope: cdk.App, id: string) { + constructor(scope: Construct, id: string) { super(scope, id); const handler = new lambda.Function(this, "handler", { @@ -55,4 +55,4 @@ export class ApiStack extends cdk.Stack { description: 'This is the api url that needs to be invoked', }); } -} \ No newline at end of file +} diff --git a/apig-waf/src/index.ts b/apig-waf/src/index.ts index 300de9afd..6320150eb 100644 --- a/apig-waf/src/index.ts +++ b/apig-waf/src/index.ts @@ -1,4 +1,4 @@ -import * as cdk from "@aws-cdk/core"; +import * as cdk from "aws-cdk-lib"; import { ApiStack } from "./api/index"; import { buildSync } from "esbuild"; import path from "path"; diff --git a/apig-waf/src/package.json b/apig-waf/src/package.json index 4be5a79e9..6f81571b5 100644 --- a/apig-waf/src/package.json +++ b/apig-waf/src/package.json @@ -4,18 +4,16 @@ "build": "ts-node ." }, "dependencies": { - "@aws-cdk/aws-apigateway": "^1.89.0", - "@aws-cdk/aws-lambda": "^1.89.0", - "@aws-cdk/core": "^1.89.0", - "@aws-cdk/aws-wafv2": "1.126.0", - "aws-cdk": "2.80.0" + "aws-cdk-lib": "^2.220.0", + "constructs": "^10.0.0" }, "devDependencies": { "@types/aws-lambda": "^8.10.72", "@types/node": "^14.14.25", "aws-sdk": "^2.866.0", + "aws-cdk": "^2.1030.0", "esbuild": "^0.25.1", "ts-node": "^9.1.1", "typescript": "^4.1.5" } -} \ No newline at end of file +} diff --git a/apig-waf/src/waf/index.ts b/apig-waf/src/waf/index.ts index 4d1e365d6..a38f73447 100644 --- a/apig-waf/src/waf/index.ts +++ b/apig-waf/src/waf/index.ts @@ -1,8 +1,9 @@ -import { CfnWebACL, CfnWebACLAssociation } from '@aws-cdk/aws-wafv2'; -import * as cdk from "@aws-cdk/core"; +import * as cdk from "aws-cdk-lib"; +import { CfnWebACL, CfnWebACLAssociation } from 'aws-cdk-lib/aws-wafv2'; +import { Construct } from 'constructs'; export class WafStack extends cdk.Stack { - constructor(scope: cdk.Construct, id: string) { + constructor(scope: Construct, id: string) { super(scope, id); // const CustomHeader = new cdk.CfnParameter(this, "CustomHeader", { From d3cfe3e56c1de0fb2fd3ee168b977410f7a45571 Mon Sep 17 00:00:00 2001 From: kakakakakku Date: Sun, 19 Oct 2025 21:21:10 +0900 Subject: [PATCH 3/5] apig-waf: Update runtime to NODEJS_22_X --- apig-waf/src/api/index.ts | 2 +- apig-waf/src/index.ts | 2 +- apig-waf/src/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apig-waf/src/api/index.ts b/apig-waf/src/api/index.ts index f20dcf7f9..06c68e0d1 100644 --- a/apig-waf/src/api/index.ts +++ b/apig-waf/src/api/index.ts @@ -13,7 +13,7 @@ export class ApiStack extends cdk.Stack { const handler = new lambda.Function(this, "handler", { code: new lambda.AssetCode(path.resolve(__dirname, "dist")), handler: `index.${config.api.handler}`, - runtime: lambda.Runtime.NODEJS_14_X, + runtime: lambda.Runtime.NODEJS_22_X, }); //Grant api gateway invoke permission on lambda diff --git a/apig-waf/src/index.ts b/apig-waf/src/index.ts index 6320150eb..32eaf91f4 100644 --- a/apig-waf/src/index.ts +++ b/apig-waf/src/index.ts @@ -13,7 +13,7 @@ buildSync({ outfile: path.join(__dirname, "api", "dist", "index.js"), platform: "node", sourcemap: true, - target: "node14.2", + target: "node22", }); const app = new cdk.App(); diff --git a/apig-waf/src/package.json b/apig-waf/src/package.json index 6f81571b5..26f549cc1 100644 --- a/apig-waf/src/package.json +++ b/apig-waf/src/package.json @@ -9,7 +9,7 @@ }, "devDependencies": { "@types/aws-lambda": "^8.10.72", - "@types/node": "^14.14.25", + "@types/node": "^22.0.0", "aws-sdk": "^2.866.0", "aws-cdk": "^2.1030.0", "esbuild": "^0.25.1", From f8c83887673524ff2d219569902cb495be52dcb6 Mon Sep 17 00:00:00 2001 From: kakakakakku Date: Sun, 19 Oct 2025 21:29:54 +0900 Subject: [PATCH 4/5] apig-waf: Update region code for CfnWebACLAssociation --- apig-waf/src/waf/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apig-waf/src/waf/index.ts b/apig-waf/src/waf/index.ts index a38f73447..451aa8777 100644 --- a/apig-waf/src/waf/index.ts +++ b/apig-waf/src/waf/index.ts @@ -164,7 +164,7 @@ export class WafStack extends cdk.Stack { // const APIGatewayWebACLAssociation = new CfnWebACLAssociation(this, "APIGatewayWebACLAssociation", { webAclArn: APIGatewayWebACL.attrArn, - resourceArn: cdk.Fn.join("", ["arn:aws:apigateway:us-east-1::/restapis/", cdk.Fn.importValue("demorestapiid"), "/stages/prod", ]) + resourceArn: cdk.Fn.join("", ["arn:aws:apigateway:", this.region, "::/restapis/", cdk.Fn.importValue("demorestapiid"), "/stages/prod"]) }); } } From a4f1df08c8d41b6767402416a9dc3de9ef774498 Mon Sep 17 00:00:00 2001 From: kakakakakku Date: Sun, 19 Oct 2025 21:39:37 +0900 Subject: [PATCH 5/5] apig-waf: Format code --- apig-waf/src/waf/index.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/apig-waf/src/waf/index.ts b/apig-waf/src/waf/index.ts index 451aa8777..668a8ddc3 100644 --- a/apig-waf/src/waf/index.ts +++ b/apig-waf/src/waf/index.ts @@ -1,16 +1,16 @@ import * as cdk from "aws-cdk-lib"; import { CfnWebACL, CfnWebACLAssociation } from 'aws-cdk-lib/aws-wafv2'; import { Construct } from 'constructs'; - + export class WafStack extends cdk.Stack { constructor(scope: Construct, id: string) { super(scope, id); - + // const CustomHeader = new cdk.CfnParameter(this, "CustomHeader", { // type: "String", // default: "x-key" // }); - + //Web ACL const APIGatewayWebACL = new CfnWebACL(this, "APIGatewayWebACL", { name: "demo-api-gateway-webacl", @@ -71,7 +71,7 @@ export class WafStack extends cdk.Stack { fieldToMatch: { allQueryArguments: {} }, - textTransformations: [{ + textTransformations: [{ priority: 1, type: "URL_DECODE" }, @@ -152,20 +152,17 @@ export class WafStack extends cdk.Stack { }] } }, - ] } } } ] }); - + // Web ACL Association - // const APIGatewayWebACLAssociation = new CfnWebACLAssociation(this, "APIGatewayWebACLAssociation", { webAclArn: APIGatewayWebACL.attrArn, resourceArn: cdk.Fn.join("", ["arn:aws:apigateway:", this.region, "::/restapis/", cdk.Fn.importValue("demorestapiid"), "/stages/prod"]) }); } } - \ No newline at end of file