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": [] -} diff --git a/apig-waf/src/api/index.ts b/apig-waf/src/api/index.ts index 95ffe9960..06c68e0d1 100644 --- a/apig-waf/src/api/index.ts +++ b/apig-waf/src/api/index.ts @@ -1,19 +1,19 @@ - -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", { 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 @@ -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..32eaf91f4 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"; @@ -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 4be5a79e9..26f549cc1 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", + "@types/node": "^22.0.0", "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..668a8ddc3 100644 --- a/apig-waf/src/waf/index.ts +++ b/apig-waf/src/waf/index.ts @@ -1,15 +1,16 @@ -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", { // type: "String", // default: "x-key" // }); - + //Web ACL const APIGatewayWebACL = new CfnWebACL(this, "APIGatewayWebACL", { name: "demo-api-gateway-webacl", @@ -70,7 +71,7 @@ export class WafStack extends cdk.Stack { fieldToMatch: { allQueryArguments: {} }, - textTransformations: [{ + textTransformations: [{ priority: 1, type: "URL_DECODE" }, @@ -151,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: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"]) }); } } - \ No newline at end of file