Skip to content
This repository was archived by the owner on Jul 26, 2022. It is now read-only.

Commit d48e2ab

Browse files
authored
Merge pull request #36 from guardian/jw-upgrade-cdk
Upgrade to cdk version 0.26.0
2 parents 535269a + f51d230 commit d48e2ab

File tree

4 files changed

+686
-647
lines changed

4 files changed

+686
-647
lines changed

cdk/lib/__snapshots__/cdk-stack.test.ts.snap

+12-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Object {
77
"Description": "BucketName",
88
"Type": "String",
99
},
10+
"PrivateSubnets": Object {
11+
"Default": "/account/vpc/primary/subnets/private",
12+
"Description": "A list of private subnets",
13+
"Type": "AWS::SSM::Parameter::Value<List<AWS::EC2::Subnet::Id>>",
14+
},
1015
"Stack": Object {
1116
"Default": "deploy",
1217
"Description": "Name of this stack",
@@ -21,6 +26,11 @@ Object {
2126
"Description": "Stage name",
2227
"Type": "String",
2328
},
29+
"VpcId": Object {
30+
"Default": "/account/vpc/primary/id",
31+
"Description": "Virtual Private Cloud to run EC2 instances within",
32+
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::VPC::Id>",
33+
},
2434
"accountsAllowList": Object {
2535
"Description": "A comma separated list of account numbers to include",
2636
"Type": "String",
@@ -29,18 +39,10 @@ Object {
2939
"Description": "Base URL for Prism",
3040
"Type": "String",
3141
},
32-
"subnetIds": Object {
33-
"Description": "The subnet IDs for the lambda to live in (this allows it to talk to Prism)",
34-
"Type": "List<AWS::EC2::Subnet::Id>",
35-
},
3642
"topicArn": Object {
3743
"Description": "The ARN of the SNS topic to send messages to",
3844
"Type": "String",
3945
},
40-
"vpcId": Object {
41-
"Description": "The VPC ID for the lambda to live in (this allows it to talk to Prism)",
42-
"Type": "AWS::EC2::VPC::Id",
43-
},
4446
},
4547
"Resources": Object {
4648
"tagjanitorlambda3E6E11A1": Object {
@@ -135,7 +137,7 @@ Object {
135137
},
136138
],
137139
"SubnetIds": Object {
138-
"Ref": "subnetIds",
140+
"Ref": "PrivateSubnets",
139141
},
140142
},
141143
},
@@ -170,7 +172,7 @@ Object {
170172
},
171173
],
172174
"VpcId": Object {
173-
"Ref": "vpcId",
175+
"Ref": "VpcId",
174176
},
175177
},
176178
"Type": "AWS::EC2::SecurityGroup",
@@ -321,7 +323,6 @@ Object {
321323
},
322324
"tagjanitorlambdatagjanitorlambdarate7days0B5F68379": Object {
323325
"Properties": Object {
324-
"Description": "Run tag-janitor every 7 days",
325326
"ScheduleExpression": "rate(7 days)",
326327
"State": "ENABLED",
327328
"Targets": Array [

cdk/lib/cdk-stack.ts

+8-19
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { Runtime } from "@aws-cdk/aws-lambda";
44
import type { App } from "@aws-cdk/core";
55
import { Duration } from "@aws-cdk/core";
66
import type { GuStackProps } from "@guardian/cdk/lib/constructs/core";
7-
import { GuStack, GuStringParameter, GuSubnetListParameter, GuVpcParameter } from "@guardian/cdk/lib/constructs/core";
7+
import { GuStack, GuStringParameter } from "@guardian/cdk/lib/constructs/core";
88
import { GuVpc } from "@guardian/cdk/lib/constructs/ec2";
9-
import { GuLambdaFunction } from "@guardian/cdk/lib/constructs/lambda";
9+
import { GuScheduledLambda } from "@guardian/cdk/lib/patterns/scheduled-lambda";
1010

1111
export class CdkStack extends GuStack {
1212
constructor(scope: App, id: string, props: GuStackProps) {
@@ -19,12 +19,6 @@ export class CdkStack extends GuStack {
1919
topic: new GuStringParameter(this, "topicArn", {
2020
description: "The ARN of the SNS topic to send messages to",
2121
}),
22-
vpc: new GuVpcParameter(this, "vpcId", {
23-
description: "The VPC ID for the lambda to live in (this allows it to talk to Prism)",
24-
}), // TODO: Look this up in SSM https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html#aws-ssm-parameter-types
25-
subnets: new GuSubnetListParameter(this, "subnetIds", {
26-
description: "The subnet IDs for the lambda to live in (this allows it to talk to Prism)",
27-
}), // TODO: Look this up in SSM https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html#aws-ssm-parameter-types
2822
accountsAllowList: new GuStringParameter(this, "accountsAllowList", {
2923
description: "A comma separated list of account numbers to include",
3024
}),
@@ -35,7 +29,7 @@ export class CdkStack extends GuStack {
3529

3630
const lambdaFrequency = Duration.days(7);
3731

38-
const tagJanitorLambda = new GuLambdaFunction(this, `${this.app}-lambda`, {
32+
const tagJanitorLambda = new GuScheduledLambda(this, `${this.app}-lambda`, {
3933
handler: "dist/src/handler.handler",
4034
functionName: `${this.app}-${this.stage}`,
4135
runtime: Runtime.NODEJS_12_X,
@@ -50,18 +44,13 @@ export class CdkStack extends GuStack {
5044
PRISM_URL: parameters.prismUrl.valueAsString,
5145
},
5246
description: "Lambda to notify about instances with missing tags",
53-
timeout: Duration.seconds(30),
54-
memorySize: 512,
55-
vpc: GuVpc.fromId(this, "vpc", parameters.vpc.valueAsString),
47+
// This lambda needs access to the Deploy Tools VPC so that it can talk to Prism
48+
vpc: GuVpc.fromIdParameter(this, "vpc"),
5649
vpcSubnets: {
57-
subnets: GuVpc.subnets(this, parameters.subnets.valueAsList),
50+
subnets: GuVpc.subnetsfromParameter(this),
5851
},
59-
rules: [
60-
{
61-
schedule: Schedule.rate(lambdaFrequency),
62-
description: `Run tag-janitor every ${lambdaFrequency.toHumanString()}`,
63-
},
64-
],
52+
schedule: Schedule.rate(lambdaFrequency),
53+
monitoringConfiguration: { noMonitoring: true },
6554
});
6655

6756
tagJanitorLambda.addToRolePolicy(

cdk/package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
"lint": "eslint lib/** bin/** --ext .ts --no-error-on-unmatched-pattern"
1414
},
1515
"devDependencies": {
16-
"@aws-cdk/assert": "~1.74.0",
16+
"@aws-cdk/assert": "1.86.0",
1717
"@guardian/eslint-config-typescript": "^0.4.1",
1818
"@types/jest": "^26.0.20",
1919
"@types/node": "10.17.27",
2020
"@typescript-eslint/eslint-plugin": "^4.14.0",
2121
"@typescript-eslint/parser": "^4.14.0",
22-
"aws-cdk": "~1.74.0",
22+
"aws-cdk": "1.86.0",
2323
"eslint": "^7.18.0",
2424
"eslint-config-prettier": "^6.15.0",
2525
"eslint-plugin-eslint-comments": "^3.2.0",
@@ -32,14 +32,14 @@
3232
"typescript": "~4.1.3"
3333
},
3434
"dependencies": {
35-
"@aws-cdk/assert": "~1.74.0",
36-
"@aws-cdk/aws-ec2": "~1.74.0",
37-
"@aws-cdk/aws-events-targets": "~1.74.0",
38-
"@aws-cdk/aws-iam": "~1.74.0",
39-
"@aws-cdk/aws-lambda": "~1.74.0",
40-
"@aws-cdk/aws-s3": "~1.74.0",
41-
"@aws-cdk/core": "~1.74.0",
42-
"@guardian/cdk": "^0.11.0",
35+
"@aws-cdk/assert": "1.86.0",
36+
"@aws-cdk/aws-ec2": "1.86.0",
37+
"@aws-cdk/aws-events-targets": "1.86.0",
38+
"@aws-cdk/aws-iam": "1.86.0",
39+
"@aws-cdk/aws-lambda": "1.86.0",
40+
"@aws-cdk/aws-s3": "1.86.0",
41+
"@aws-cdk/core": "1.86.0",
42+
"@guardian/cdk": "0.26.0",
4343
"source-map-support": "^0.5.16"
4444
}
4545
}

0 commit comments

Comments
 (0)