Skip to content

Commit b484d9e

Browse files
committed
Build a CODE stack for live activities with a dynamo table
1 parent 6af27cf commit b484d9e

4 files changed

Lines changed: 103 additions & 0 deletions

File tree

cdk/bin/cdk.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { App, Duration } from 'aws-cdk-lib';
33
import 'source-map-support/register';
44
import { FakeBreakingNewsLambda } from '../lib/fakebreakingnewslambda';
55
import { FootballNotificationsLambda } from '../lib/footballnotificationslambda';
6+
import { LiveActivities } from '../lib/liveactivities';
67
import type { NotificationProps } from '../lib/notification';
78
import { Notification } from '../lib/notification';
89
import type { RegistrationProps } from '../lib/registration';
@@ -186,3 +187,10 @@ new FootballNotificationsLambda(
186187
'FootballNotificationsLambda-PROD',
187188
footballNotificationsProdProps,
188189
);
190+
191+
export const liveActivitiesCodeProps: GuStackProps = {
192+
stack: 'mobile-notifications',
193+
stage: 'CODE',
194+
};
195+
196+
new LiveActivities(app, 'LiveActivities-CODE', liveActivitiesCodeProps);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`The LiveActivities stack matches the snapshot for CODE 1`] = `
4+
{
5+
"Metadata": {
6+
"gu:cdk:constructs": [],
7+
"gu:cdk:version": "TEST",
8+
},
9+
"Resources": {
10+
"liveactivitiesdynamotable87F336D2": {
11+
"DeletionPolicy": "Retain",
12+
"Properties": {
13+
"AttributeDefinitions": [
14+
{
15+
"AttributeName": "id",
16+
"AttributeType": "S",
17+
},
18+
],
19+
"BillingMode": "PAY_PER_REQUEST",
20+
"KeySchema": [
21+
{
22+
"AttributeName": "id",
23+
"KeyType": "HASH",
24+
},
25+
],
26+
"TableName": "mobile-notifications-liveactivities-CODE",
27+
"Tags": [
28+
{
29+
"Key": "devx-backup-enabled",
30+
"Value": "true",
31+
},
32+
{
33+
"Key": "gu:cdk:version",
34+
"Value": "TEST",
35+
},
36+
{
37+
"Key": "gu:repo",
38+
"Value": "guardian/mobile-n10n",
39+
},
40+
{
41+
"Key": "Stack",
42+
"Value": "mobile-notifications",
43+
},
44+
{
45+
"Key": "Stage",
46+
"Value": "CODE",
47+
},
48+
],
49+
},
50+
"Type": "AWS::DynamoDB::Table",
51+
"UpdateReplacePolicy": "Retain",
52+
},
53+
},
54+
}
55+
`;

cdk/lib/liveactivities.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { App } from 'aws-cdk-lib';
2+
import { Template } from 'aws-cdk-lib/assertions';
3+
import { liveActivitiesCodeProps } from '../bin/cdk';
4+
import { LiveActivities } from './liveactivities';
5+
6+
describe('The LiveActivities stack', () => {
7+
it('matches the snapshot for CODE', () => {
8+
const app = new App();
9+
const stack = new LiveActivities(
10+
app,
11+
'LiveActivities-CODE',
12+
liveActivitiesCodeProps,
13+
);
14+
const template = Template.fromStack(stack);
15+
expect(template.toJSON()).toMatchSnapshot();
16+
});
17+
});

cdk/lib/liveactivities.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { GuStackProps } from '@guardian/cdk/lib/constructs/core';
2+
import { GuStack } from '@guardian/cdk/lib/constructs/core';
3+
import type { App } from 'aws-cdk-lib';
4+
import { Tags } from 'aws-cdk-lib';
5+
import { AttributeType, BillingMode, Table } from 'aws-cdk-lib/aws-dynamodb';
6+
7+
export class LiveActivities extends GuStack {
8+
constructor(scope: App, id: string, props: GuStackProps) {
9+
super(scope, id, props);
10+
11+
const { stack, stage } = this;
12+
const app = 'liveactivities';
13+
14+
const dynamoTableName = `${stack}-liveactivities-${stage}`;
15+
16+
const dynamoTable = new Table(this, `${app}-dynamo-table`, {
17+
tableName: dynamoTableName,
18+
partitionKey: { name: 'id', type: AttributeType.STRING },
19+
billingMode: BillingMode.PAY_PER_REQUEST,
20+
});
21+
Tags.of(dynamoTable).add('devx-backup-enabled', 'true');
22+
}
23+
}

0 commit comments

Comments
 (0)