Skip to content

Commit 07840a7

Browse files
authored
Merge pull request #12 from ZDF-OSS/feature/add_retention
fix: fix retention is not configurable
2 parents bee4929 + a2036c6 commit 07840a7

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

API.md

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,18 @@ Enabled logging sends all information to the CloudWatch LogGroup.
5858
Use our construct by installing the module and using our construct in your code:
5959

6060
```sh
61+
npm install -g aws-cdk
62+
npm install aws-cdk-lib
6163
npm install cdk-aws-wafv2-geofence-lib
6264
```
6365
**allowedCountiesToAccessService** expects an array of two-character country codes that you want to match against, for example, [ "US", "CN" ], from the alpha-2 country ISO codes of the ISO 3166 international standard.
6466

6567
When you use a geo match statement just for the region and country labels that it adds to requests, you still have to supply a country code for the rule to evaluate. In this case, you configure the rule to only count matching requests, but it will still generate logging and count metrics for any matches. You can reduce the logging and metrics that the rule produces by specifying a country that's unlikely to be a source of traffic to your site. (https://docs.aws.amazon.com/waf/latest/APIReference/API_GeoMatchStatement.html)
6668

69+
```ts
70+
import { CdkWafGeoLib } from 'cdk-aws-wafv2-geofence-lib'
71+
```
72+
6773
```ts
6874
// AWS WAFv2 GeoBlocking CDK Component
6975
const allowedCountiesToAccessService = ["DE"]

src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface ICdkWafGeoLibProps {
2626
enableCloudWatchLogs?: boolean;
2727
/** Name of the CloudWatch LogGroup where requests are stored. */
2828
cloudWatchLogGroupName?: string;
29-
/** Retention period to keep logs. */
29+
/** Retention period to keep logs. ONE_MONTH is default. */
3030
retentionDays?: RetentionDays;
3131

3232
/** Switch to control if the rule should block or count incomming requests. */
@@ -61,6 +61,8 @@ export class CdkWafGeoLib extends Construct {
6161
public readonly customResourceResult?: string;
6262
constructor(scope: Construct, id: string, props: ICdkWafGeoLibProps) {
6363
super(scope, id);
64+
const logRetention = props.retentionDays ?? RetentionDays.ONE_MONTH;
65+
const logGroupName = `aws-waf-logs-geo-${props.cloudWatchLogGroupName ?? 'default'}`;
6466

6567
const wafGeoBlocking = new WafRulesGeoBlock( {
6668
block: ( props.block || props.enableGeoBlocking),
@@ -119,9 +121,9 @@ export class CdkWafGeoLib extends Construct {
119121
});
120122

121123
const log_group = new cdk.aws_logs.LogGroup(this, 'waf-log-group', {
122-
retention: cdk.aws_logs.RetentionDays.ONE_WEEK,
124+
retention: logRetention,
123125
removalPolicy: cdk.RemovalPolicy.DESTROY,
124-
logGroupName: `aws-waf-logs-geo-${props.cloudWatchLogGroupName ?? 'default'}`,
126+
logGroupName,
125127
});
126128

127129
customResourceRole.addToPolicy(new PolicyStatement({

0 commit comments

Comments
 (0)