Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions apig-waf/src/api/dist/index.js

This file was deleted.

7 changes: 0 additions & 7 deletions apig-waf/src/api/dist/index.js.map

This file was deleted.

16 changes: 8 additions & 8 deletions apig-waf/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -55,4 +55,4 @@ export class ApiStack extends cdk.Stack {
description: 'This is the api url that needs to be invoked',
});
}
}
}
4 changes: 2 additions & 2 deletions apig-waf/src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
Expand Down
12 changes: 5 additions & 7 deletions apig-waf/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
22 changes: 10 additions & 12 deletions apig-waf/src/waf/index.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -70,7 +71,7 @@ export class WafStack extends cdk.Stack {
fieldToMatch: {
allQueryArguments: {}
},
textTransformations: [{
textTransformations: [{
priority: 1,
type: "URL_DECODE"
},
Expand Down Expand Up @@ -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"])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: It was previously fixed to the us-east-1 region, but I’ve updated it to support other regions. I tested it in ap-northeast-1.

});
}
}