Skip to content

Commit 49be4fa

Browse files
Define dynamo table in cdk
Co-authored-by: Jorge <Jorge.Azevedo@guardian.co.uk>
1 parent abb5157 commit 49be4fa

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

cdk/lib/footballnotificationslambda.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { GuAlarm } from '@guardian/cdk/lib/constructs/cloudwatch';
44
import type { GuStackProps } from '@guardian/cdk/lib/constructs/core';
55
import { GuStack } from '@guardian/cdk/lib/constructs/core';
66
import type { App } from 'aws-cdk-lib';
7+
import { RemovalPolicy, Tags } from 'aws-cdk-lib';
78
import { Duration } from 'aws-cdk-lib';
89
import {
910
ComparisonOperator,
1011
Metric,
1112
TreatMissingData,
1213
Unit,
1314
} from 'aws-cdk-lib/aws-cloudwatch';
15+
import { AttributeType, BillingMode, Table } from 'aws-cdk-lib/aws-dynamodb';
1416
import { Schedule } from 'aws-cdk-lib/aws-events';
1517
import { Effect, PolicyStatement } from 'aws-cdk-lib/aws-iam';
1618
import { LoggingFormat, Runtime } from 'aws-cdk-lib/aws-lambda';
@@ -24,11 +26,6 @@ export class FootballNotificationsLambda extends GuStack {
2426
const { stack, stage, region, account } = this;
2527
const app = 'football';
2628

27-
const yamlTemplateFilePath = join(__dirname, '../../football/cfn.yaml');
28-
new CfnInclude(this, 'YamlTemplate', {
29-
templateFile: yamlTemplateFilePath,
30-
});
31-
3229
const footballnotificationslambda = new GuScheduledLambda(
3330
this,
3431
`${app}-Lambda`,
@@ -68,9 +65,29 @@ export class FootballNotificationsLambda extends GuStack {
6865
}),
6966
);
7067

71-
// Keep dynoma table defition in the yaml for now
7268
const dynamoTableName = `${stack}-football-notifications-${stage}`;
7369

70+
const dynamoTable = new Table(this, 'DynamoTable', {
71+
tableName: dynamoTableName,
72+
partitionKey: { name: 'notificationId', type: AttributeType.STRING },
73+
billingMode: BillingMode.PROVISIONED,
74+
readCapacity: 3,
75+
writeCapacity: 3,
76+
timeToLiveAttribute: 'ttl',
77+
removalPolicy: RemovalPolicy.RETAIN,
78+
});
79+
Tags.of(dynamoTable).add('devx-backup-enabled', 'true');
80+
81+
footballnotificationslambda.addToRolePolicy(
82+
new PolicyStatement({
83+
actions: ['dynamodb:PutItem', 'dynamodb:UpdateItem', 'dynamodb:Query'],
84+
effect: Effect.ALLOW,
85+
resources: [
86+
`arn:aws:dynamodb:${region}:${account}:table/${dynamoTableName}`,
87+
],
88+
}),
89+
);
90+
7491
footballnotificationslambda.addToRolePolicy(
7592
new PolicyStatement({
7693
actions: ['dynamodb:PutItem', 'dynamodb:UpdateItem', 'dynamodb:Query'],

0 commit comments

Comments
 (0)