Skip to content

Commit a70a2e6

Browse files
authored
chore: make examples compile (#18020)
Done for a bunch of modules: - custom-resources - backup - s3-assets - s3-notifications - s3-deployment - config - cloudtrail ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 23cfa3a commit a70a2e6

File tree

23 files changed

+328
-184
lines changed

23 files changed

+328
-184
lines changed

packages/@aws-cdk/aws-backup/README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const plan = backup.BackupPlan.dailyWeeklyMonthly5YearRetention(this, 'Plan');
3232

3333
Assigning resources to a plan can be done with `addSelection()`:
3434

35-
```ts fixture=with-plan
35+
```ts
36+
declare const plan: backup.BackupPlan;
3637
const myTable = dynamodb.Table.fromTableName(this, 'Table', 'myTableName');
3738
const myCoolConstruct = new Construct(this, 'MyCoolConstruct');
3839

@@ -50,16 +51,17 @@ created for the selection. The `BackupSelection` implements `IGrantable`.
5051

5152
To add rules to a plan, use `addRule()`:
5253

53-
```ts fixture=with-plan
54+
```ts
55+
declare const plan: backup.BackupPlan;
5456
plan.addRule(new backup.BackupPlanRule({
5557
completionWindow: Duration.hours(2),
5658
startWindow: Duration.hours(1),
5759
scheduleExpression: events.Schedule.cron({ // Only cron expressions are supported
5860
day: '15',
5961
hour: '3',
60-
minute: '30'
62+
minute: '30',
6163
}),
62-
moveToColdStorageAfter: Duration.days(30)
64+
moveToColdStorageAfter: Duration.days(30),
6365
}));
6466
```
6567

@@ -69,7 +71,8 @@ If no value is specified, the retention period is set to 35 days which is the ma
6971
Property `moveToColdStorageAfter` must not be specified because PITR does not support this option.
7072
This example defines an AWS Backup rule with PITR and a retention period set to 14 days:
7173

72-
```ts fixture=with-plan
74+
```ts
75+
declare const plan: backup.BackupPlan;
7376
plan.addRule(new backup.BackupPlanRule({
7477
enableContinuousBackup: true,
7578
deleteAfter: Duration.days(14),
@@ -78,7 +81,8 @@ plan.addRule(new backup.BackupPlanRule({
7881

7982
Ready-made rules are also available:
8083

81-
```ts fixture=with-plan
84+
```ts
85+
declare const plan: backup.BackupPlan;
8286
plan.addRule(backup.BackupPlanRule.daily());
8387
plan.addRule(backup.BackupPlanRule.weekly());
8488
```
@@ -152,7 +156,7 @@ const vault = new backup.BackupVault(this, 'Vault', {
152156
},
153157
}),
154158
],
155-
});
159+
}),
156160
})
157161
```
158162

@@ -166,8 +170,8 @@ new backup.BackupVault(this, 'Vault', {
166170
blockRecoveryPointDeletion: true,
167171
});
168172

169-
const plan = backup.BackupPlan.dailyMonthly1YearRetention(this, 'Plan');
170-
plan.backupVault.blockRecoveryPointDeletion();
173+
declare const backupVault: backup.BackupVault;
174+
backupVault.blockRecoveryPointDeletion();
171175
```
172176

173177
By default access is not restricted.

packages/@aws-cdk/aws-backup/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
]
2929
}
3030
},
31-
"projectReferences": true
31+
"projectReferences": true,
32+
"metadata": {
33+
"jsii": {
34+
"rosetta": {
35+
"strict": true
36+
}
37+
}
38+
}
3239
},
3340
"repository": {
3441
"type": "git",

packages/@aws-cdk/aws-backup/rosetta/default.ts-fixture

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Duration, RemovalPolicy, Stack } from '@aws-cdk/core';
33
import { Construct } from 'constructs';
44
import * as backup from '@aws-cdk/aws-backup';
55
import * as iam from '@aws-cdk/aws-iam';
6+
import * as dynamodb from '@aws-cdk/aws-dynamodb';
7+
import * as events from '@aws-cdk/aws-events';
68
import * as kms from '@aws-cdk/aws-kms';
79
import * as sns from '@aws-cdk/aws-sns';
810

packages/@aws-cdk/aws-backup/rosetta/with-plan.ts-fixture

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/@aws-cdk/aws-cloudtrail/README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ default retention setting. The following code enables sending CloudWatch logs bu
6868
period for the created Log Group.
6969

7070
```ts
71+
import * as logs from '@aws-cdk/aws-logs';
72+
7173
const trail = new cloudtrail.Trail(this, 'CloudTrail', {
7274
sendToCloudWatchLogs: true,
7375
cloudWatchLogsRetention: logs.RetentionDays.FOUR_MONTHS,
@@ -88,18 +90,18 @@ The following code filters events for S3 from a specific AWS account and trigger
8890

8991
```ts
9092
const myFunctionHandler = new lambda.Function(this, 'MyFunction', {
91-
code: lambda.Code.fromAsset('resource/myfunction');
93+
code: lambda.Code.fromAsset('resource/myfunction'),
9294
runtime: lambda.Runtime.NODEJS_12_X,
9395
handler: 'index.handler',
9496
});
9597

96-
const eventRule = Trail.onEvent(this, 'MyCloudWatchEvent', {
97-
target: new eventTargets.LambdaFunction(myFunctionHandler),
98+
const eventRule = cloudtrail.Trail.onEvent(this, 'MyCloudWatchEvent', {
99+
target: new targets.LambdaFunction(myFunctionHandler),
98100
});
99101

100102
eventRule.addEventPattern({
101-
account: '123456789012',
102-
source: 'aws.s3',
103+
account: ['123456789012'],
104+
source: ['aws.s3'],
103105
});
104106
```
105107

@@ -141,7 +143,7 @@ The following code configures the `Trail` to only track management events that a
141143
```ts
142144
const trail = new cloudtrail.Trail(this, 'CloudTrail', {
143145
// ...
144-
managementEvents: ReadWriteType.READ_ONLY,
146+
managementEvents: cloudtrail.ReadWriteType.READ_ONLY,
145147
});
146148
```
147149

@@ -157,13 +159,14 @@ be used to configure logging of S3 data events for specific buckets and specific
157159
configures logging of S3 data events for `fooBucket` and with object prefix `bar/`.
158160

159161
```ts
160-
import * as cloudtrail from '@aws-cdk/aws-cloudtrail';
162+
import * as s3 from '@aws-cdk/aws-s3';
161163

162164
const trail = new cloudtrail.Trail(this, 'MyAmazingCloudTrail');
165+
declare const bucket: s3.Bucket;
163166

164167
// Adds an event selector to the bucket foo
165168
trail.addS3EventSelector([{
166-
bucket: fooBucket, // 'fooBucket' is of type s3.IBucket
169+
bucket,
167170
objectPrefix: 'bar/',
168171
}]);
169172
```
@@ -174,12 +177,12 @@ configures logging of Lambda data events for a specific Function.
174177

175178
```ts
176179
const trail = new cloudtrail.Trail(this, 'MyAmazingCloudTrail');
177-
const amazingFunction = new lambda.Function(stack, 'AnAmazingFunction', {
180+
const amazingFunction = new lambda.Function(this, 'AnAmazingFunction', {
178181
runtime: lambda.Runtime.NODEJS_12_X,
179182
handler: "hello.handler",
180183
code: lambda.Code.fromAsset("lambda"),
181184
});
182185

183186
// Add an event selector to log data events for the provided Lambda functions.
184-
trail.addLambdaEventSelector([ lambdaFunction ]);
187+
trail.addLambdaEventSelector([ amazingFunction ]);
185188
```

packages/@aws-cdk/aws-cloudtrail/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
]
2929
}
3030
},
31-
"projectReferences": true
31+
"projectReferences": true,
32+
"metadata": {
33+
"jsii": {
34+
"rosetta": {
35+
"strict": true
36+
}
37+
}
38+
}
3239
},
3340
"repository": {
3441
"type": "git",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Fixture with packages imported, but nothing else
2+
import { Stack } from '@aws-cdk/core';
3+
import { Construct } from 'constructs';
4+
import * as cloudtrail from '@aws-cdk/aws-cloudtrail';
5+
import * as sns from '@aws-cdk/aws-sns';
6+
import * as lambda from '@aws-cdk/aws-lambda';
7+
import * as targets from '@aws-cdk/aws-events-targets';
8+
9+
class Fixture extends Stack {
10+
constructor(scope: Construct, id: string) {
11+
super(scope, id);
12+
/// here
13+
}
14+
}

packages/@aws-cdk/aws-config/README.md

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,15 @@ For example, you could create a managed rule that checks whether active access k
5959
within the number of days specified.
6060

6161
```ts
62-
import * as config from '@aws-cdk/aws-config';
63-
import * as cdk from '@aws-cdk/core';
64-
6562
// https://docs.aws.amazon.com/config/latest/developerguide/access-keys-rotated.html
6663
new config.ManagedRule(this, 'AccessKeysRotated', {
6764
identifier: config.ManagedRuleIdentifiers.ACCESS_KEYS_ROTATED,
6865
inputParameters: {
69-
maxAccessKeyAge: 60 // default is 90 days
66+
maxAccessKeyAge: 60, // default is 90 days
7067
},
71-
maximumExecutionFrequency: config.MaximumExecutionFrequency.TWELVE_HOURS // default is 24 hours
68+
69+
// default is 24 hours
70+
maximumExecutionFrequency: config.MaximumExecutionFrequency.TWELVE_HOURS,
7271
});
7372
```
7473

@@ -82,9 +81,6 @@ The following higher level constructs for AWS managed rules are available.
8281
Checks whether your active access keys are rotated within the number of days specified.
8382

8483
```ts
85-
import * as config from '@aws-cdk/aws-config';
86-
import * as cdk from '@aws-cdk/aws-cdk';
87-
8884
// compliant if access keys have been rotated within the last 90 days
8985
new config.AccessKeysRotated(this, 'AccessKeyRotated');
9086
```
@@ -95,12 +91,9 @@ Checks whether your CloudFormation stack's actual configuration differs, or has
9591
from it's expected configuration.
9692

9793
```ts
98-
import * as config from '@aws-cdk/aws-config';
99-
import * as cdk from '@aws-cdk/aws-cdk';
100-
10194
// compliant if stack's status is 'IN_SYNC'
10295
// non-compliant if the stack's drift status is 'DRIFTED'
103-
new config.CloudFormationStackDriftDetectionCheck(stack, 'Drift', {
96+
new config.CloudFormationStackDriftDetectionCheck(this, 'Drift', {
10497
ownStackOnly: true, // checks only the stack containing the rule
10598
});
10699
```
@@ -110,17 +103,14 @@ new config.CloudFormationStackDriftDetectionCheck(stack, 'Drift', {
110103
Checks whether your CloudFormation stacks are sending event notifications to a SNS topic.
111104

112105
```ts
113-
import * as config from '@aws-cdk/aws-config';
114-
import * as cdk from '@aws-cdk/aws-cdk';
115-
116106
// topics to which CloudFormation stacks may send event notifications
117-
const topic1 = new sns.Topic(stack, 'AllowedTopic1');
118-
const topic2 = new sns.Topic(stack, 'AllowedTopic2');
107+
const topic1 = new sns.Topic(this, 'AllowedTopic1');
108+
const topic2 = new sns.Topic(this, 'AllowedTopic2');
119109

120110
// non-compliant if CloudFormation stack does not send notifications to 'topic1' or 'topic2'
121111
new config.CloudFormationStackNotificationCheck(this, 'NotificationCheck', {
122112
topics: [topic1, topic2],
123-
})
113+
});
124114
```
125115

126116
### Custom rules
@@ -140,13 +130,15 @@ To create a custom rule, define a `CustomRule` and specify the Lambda Function
140130
to run and the trigger types.
141131

142132
```ts
143-
import * as config from '@aws-cdk/aws-config';
133+
declare const evalComplianceFn: lambda.Function;
144134

145135
new config.CustomRule(this, 'CustomRule', {
146136
lambdaFunction: evalComplianceFn,
147137
configurationChanges: true,
148138
periodic: true,
149-
maximumExecutionFrequency: config.MaximumExecutionFrequency.SIX_HOURS, // default is 24 hours
139+
140+
// default is 24 hours
141+
maximumExecutionFrequency: config.MaximumExecutionFrequency.SIX_HOURS,
150142
});
151143
```
152144

@@ -165,22 +157,21 @@ Use the `RuleScope` APIs (`fromResource()`, `fromResources()` or `fromTag()`) to
165157
the scope of both managed and custom rules:
166158

167159
```ts
168-
import * as config from '@aws-cdk/aws-config';
169-
170160
const sshRule = new config.ManagedRule(this, 'SSH', {
171161
identifier: config.ManagedRuleIdentifiers.EC2_SECURITY_GROUPS_INCOMING_SSH_DISABLED,
172162
ruleScope: config.RuleScope.fromResource(config.ResourceType.EC2_SECURITY_GROUP, 'sg-1234567890abcdefgh'), // restrict to specific security group
173163
});
174164

165+
declare const evalComplianceFn: lambda.Function;
175166
const customRule = new config.CustomRule(this, 'Lambda', {
176167
lambdaFunction: evalComplianceFn,
177-
configurationChanges: true
168+
configurationChanges: true,
178169
ruleScope: config.RuleScope.fromResources([config.ResourceType.CLOUDFORMATION_STACK, config.ResourceType.S3_BUCKET]), // restrict to all CloudFormation stacks and S3 buckets
179170
});
180171

181172
const tagRule = new config.CustomRule(this, 'CostCenterTagRule', {
182173
lambdaFunction: evalComplianceFn,
183-
configurationChanges: true
174+
configurationChanges: true,
184175
ruleScope: config.RuleScope.fromTag('Cost Center', 'MyApp'), // restrict to a specific tag
185176
});
186177
```
@@ -194,10 +185,6 @@ Use the `onComplianceChange()` APIs to trigger an EventBridge event when a compl
194185
of your AWS Config Rule fails:
195186

196187
```ts
197-
import * as config from '@aws-cdk/aws-config';
198-
import * as sns from '@aws-cdk/aws-sns';
199-
import * as targets from '@aws-cdk/aws-events-targets';
200-
201188
// Topic to which compliance notification events will be published
202189
const complianceTopic = new sns.Topic(this, 'ComplianceTopic');
203190

@@ -211,15 +198,13 @@ Use the `onReEvaluationStatus()` status to trigger an EventBridge event when an
211198
rule is re-evaluated.
212199

213200
```ts
214-
import * as config from '@aws-cdk/aws-config';
215-
import * as sns from '@aws-cdk/aws-sns';
216-
import * as targets from '@aws-cdk/aws-events-targets';
217-
218201
// Topic to which re-evaluation notification events will be published
219202
const reEvaluationTopic = new sns.Topic(this, 'ComplianceTopic');
203+
204+
const rule = new config.CloudFormationStackDriftDetectionCheck(this, 'Drift');
220205
rule.onReEvaluationStatus('ReEvaluationEvent', {
221206
target: new targets.SnsTopic(reEvaluationTopic),
222-
})
207+
});
223208
```
224209

225210
### Example
@@ -228,11 +213,6 @@ The following example creates a custom rule that evaluates whether EC2 instances
228213
Compliance events are published to an SNS topic.
229214

230215
```ts
231-
import * as config from '@aws-cdk/aws-config';
232-
import * as lambda from '@aws-cdk/aws-lambda';
233-
import * as sns from '@aws-cdk/aws-sns';
234-
import * as targets from '@aws-cdk/aws-events-targets';
235-
236216
// Lambda function containing logic that evaluates compliance with the rule.
237217
const evalComplianceFn = new lambda.Function(this, 'CustomFunction', {
238218
code: lambda.AssetCode.fromInline('exports.handler = (event) => console.log(event);'),
@@ -244,7 +224,7 @@ const evalComplianceFn = new lambda.Function(this, 'CustomFunction', {
244224
const customRule = new config.CustomRule(this, 'Custom', {
245225
configurationChanges: true,
246226
lambdaFunction: evalComplianceFn,
247-
ruleScope: config.RuleScope.fromResource([config.ResourceType.EC2_INSTANCE]),
227+
ruleScope: config.RuleScope.fromResource(config.ResourceType.EC2_INSTANCE),
248228
});
249229

250230
// A rule to detect stack drifts

packages/@aws-cdk/aws-config/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
]
2929
}
3030
},
31-
"projectReferences": true
31+
"projectReferences": true,
32+
"metadata": {
33+
"jsii": {
34+
"rosetta": {
35+
"strict": true
36+
}
37+
}
38+
}
3239
},
3340
"repository": {
3441
"type": "git",

0 commit comments

Comments
 (0)