Skip to content

Commit 23cfa3a

Browse files
authored
chore: make more examples compile (#18318)
- `docdb` - `certificatemanager` - `msk` - `servicecatalogappregistry` - `cloudfront-origins` - `ses` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 64ae9f3 commit 23cfa3a

File tree

19 files changed

+283
-150
lines changed

19 files changed

+283
-150
lines changed

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ If Amazon Route 53 is your DNS provider for the requested domain, the DNS record
4040
created automatically:
4141

4242
```ts
43-
import * as acm from '@aws-cdk/aws-certificatemanager';
44-
import * as route53 from '@aws-cdk/aws-route53';
45-
4643
const myHostedZone = new route53.HostedZone(this, 'HostedZone', {
4744
zoneName: 'example.com',
4845
});
@@ -106,6 +103,7 @@ The `DnsValidatedCertificate` construct exists to facilitate creating these cert
106103
Route53-based DNS validation.
107104

108105
```ts
106+
declare const myHostedZone: route53.HostedZone;
109107
new acm.DnsValidatedCertificate(this, 'CrossRegionCertificate', {
110108
domainName: 'hello.example.com',
111109
hostedZone: myHostedZone,
@@ -120,10 +118,10 @@ AWS Certificate Manager can create [private certificates](https://docs.aws.amazo
120118
```ts
121119
import * as acmpca from '@aws-cdk/aws-acmpca';
122120

123-
new acm.PrivateCertificate(stack, 'PrivateCertificate', {
121+
new acm.PrivateCertificate(this, 'PrivateCertificate', {
124122
domainName: 'test.example.com',
125123
subjectAlternativeNames: ['cool.example.com', 'test.example.net'], // optional
126-
certificateAuthority: acmpca.CertificateAuthority.fromCertificateAuthorityArn(stack, 'CA',
124+
certificateAuthority: acmpca.CertificateAuthority.fromCertificateAuthorityArn(this, 'CA',
127125
'arn:aws:acm-pca:us-east-1:123456789012:certificate-authority/023077d8-2bfa-4eb0-8f22-05c96deade77'),
128126
});
129127
```
@@ -134,7 +132,7 @@ If you want to import an existing certificate, you can do so from its ARN:
134132

135133
```ts
136134
const arn = 'arn:aws:...';
137-
const certificate = Certificate.fromCertificateArn(this, 'Certificate', arn);
135+
const certificate = acm.Certificate.fromCertificateArn(this, 'Certificate', arn);
138136
```
139137

140138
## Sharing between Stacks
@@ -152,8 +150,14 @@ An alarm can be created to determine whether a certificate is soon due for
152150
renewal ussing the following code:
153151

154152
```ts
155-
const certificate = new Certificate(this, 'Certificate', { /* ... */ });
156-
certificate.metricDaysToExpiry().createAlarm({
153+
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
154+
155+
declare const myHostedZone: route53.HostedZone;
156+
const certificate = new acm.Certificate(this, 'Certificate', {
157+
domainName: 'hello.example.com',
158+
validation: acm.CertificateValidation.fromDns(myHostedZone),
159+
});
160+
certificate.metricDaysToExpiry().createAlarm(this, 'Alarm', {
157161
comparisonOperator: cloudwatch.ComparisonOperator.LESS_THAN_THRESHOLD,
158162
evaluationPeriods: 1,
159163
threshold: 45, // Automatic rotation happens between 60 and 45 days before expiry

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

+8-1
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",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Fixture with packages imported, but nothing else
2+
import { Stack } from '@aws-cdk/core';
3+
import { Construct } from 'constructs';
4+
import * as acm from '@aws-cdk/aws-certificatemanager';
5+
import * as route53 from '@aws-cdk/aws-route53';
6+
7+
class Fixture extends Stack {
8+
constructor(scope: Construct, id: string) {
9+
super(scope, id);
10+
/// here
11+
}
12+
}

packages/@aws-cdk/aws-cloudfront-origins/README.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ An S3 bucket can be added as an origin. If the bucket is configured as a website
1818
documents.
1919

2020
```ts
21-
import * as cloudfront from '@aws-cdk/aws-cloudfront';
22-
import * as origins from '@aws-cdk/aws-cloudfront-origins';
23-
2421
const myBucket = new s3.Bucket(this, 'myBucket');
2522
new cloudfront.Distribution(this, 'myDist', {
2623
defaultBehavior: { origin: new origins.S3Origin(myBucket) },
@@ -38,9 +35,6 @@ URLs and not S3 URLs directly. Alternatively, a custom origin access identity ca
3835
You can configure CloudFront to add custom headers to the requests that it sends to your origin. These custom headers enable you to send and gather information from your origin that you don’t get with typical viewer requests. These headers can even be customized for each origin. CloudFront supports custom headers for both for custom and Amazon S3 origins.
3936

4037
```ts
41-
import * as cloudfront from '@aws-cdk/aws-cloudfront';
42-
import * as origins from '@aws-cdk/aws-cloudfront-origins';
43-
4438
const myBucket = new s3.Bucket(this, 'myBucket');
4539
new cloudfront.Distribution(this, 'myDist', {
4640
defaultBehavior: { origin: new origins.S3Origin(myBucket, {
@@ -60,12 +54,12 @@ accessible (`internetFacing` is true). Both Application and Network load balance
6054
import * as ec2 from '@aws-cdk/aws-ec2';
6155
import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2';
6256

63-
const vpc = new ec2.Vpc(...);
57+
declare const vpc: ec2.Vpc;
6458
// Create an application load balancer in a VPC. 'internetFacing' must be 'true'
6559
// for CloudFront to access the load balancer and use it as an origin.
6660
const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
6761
vpc,
68-
internetFacing: true
62+
internetFacing: true,
6963
});
7064
new cloudfront.Distribution(this, 'myDist', {
7165
defaultBehavior: { origin: new origins.LoadBalancerV2Origin(lb) },
@@ -75,6 +69,9 @@ new cloudfront.Distribution(this, 'myDist', {
7569
The origin can also be customized to respond on different ports, have different connection properties, etc.
7670

7771
```ts
72+
import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2';
73+
74+
declare const loadBalancer: elbv2.ApplicationLoadBalancer;
7875
const origin = new origins.LoadBalancerV2Origin(loadBalancer, {
7976
connectionAttempts: 3,
8077
connectionTimeout: Duration.seconds(5),
@@ -103,6 +100,7 @@ CloudFront automatically switches to the secondary origin.
103100
You achieve that behavior in the CDK using the `OriginGroup` class:
104101

105102
```ts
103+
const myBucket = new s3.Bucket(this, 'myBucket');
106104
new cloudfront.Distribution(this, 'myDist', {
107105
defaultBehavior: {
108106
origin: new origins.OriginGroup({

packages/@aws-cdk/aws-cloudfront-origins/package.json

+8-1
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",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Fixture with packages imported, but nothing else
2+
import { Duration, Stack } from '@aws-cdk/core';
3+
import { Construct } from 'constructs';
4+
import * as cloudfront from '@aws-cdk/aws-cloudfront';
5+
import * as origins from '@aws-cdk/aws-cloudfront-origins';
6+
import * as s3 from '@aws-cdk/aws-s3';
7+
8+
class Fixture extends Stack {
9+
constructor(scope: Construct, id: string) {
10+
super(scope, id);
11+
12+
/// here
13+
14+
}
15+
}

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

+54-27
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ always launch a database in a VPC. Use the `vpcSubnets` attribute to control whe
1818
your instances will be launched privately or publicly:
1919

2020
```ts
21-
const cluster = new DatabaseCluster(this, 'Database', {
22-
masterUser: {
23-
username: 'myuser' // NOTE: 'admin' is reserved by DocumentDB
24-
excludeCharacters: '\"@/:', // optional, defaults to the set "\"@/" and is also used for eventually created rotations
25-
secretName: '/myapp/mydocdb/masteruser', // optional, if you prefer to specify the secret name
26-
},
27-
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R5, ec2.InstanceSize.LARGE),
28-
vpcSubnets: {
29-
subnetType: ec2.SubnetType.PUBLIC,
30-
},
31-
vpc
21+
declare const vpc: ec2.Vpc;
22+
const cluster = new docdb.DatabaseCluster(this, 'Database', {
23+
masterUser: {
24+
username: 'myuser', // NOTE: 'admin' is reserved by DocumentDB
25+
excludeCharacters: '\"@/:', // optional, defaults to the set "\"@/" and is also used for eventually created rotations
26+
secretName: '/myapp/mydocdb/masteruser', // optional, if you prefer to specify the secret name
27+
},
28+
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R5, ec2.InstanceSize.LARGE),
29+
vpcSubnets: {
30+
subnetType: ec2.SubnetType.PUBLIC,
31+
},
32+
vpc,
3233
});
3334
```
3435

@@ -42,21 +43,26 @@ To control who can access the cluster, use the `.connections` attribute. Documen
4243
you don't need to specify the port:
4344

4445
```ts
46+
declare const cluster: docdb.DatabaseCluster;
4547
cluster.connections.allowDefaultPortFromAnyIpv4('Open to the world');
4648
```
4749

4850
The endpoints to access your database cluster will be available as the `.clusterEndpoint` and `.clusterReadEndpoint`
4951
attributes:
5052

5153
```ts
54+
declare const cluster: docdb.DatabaseCluster;
5255
const writeAddress = cluster.clusterEndpoint.socketAddress; // "HOSTNAME:PORT"
5356
```
5457

5558
If you have existing security groups you would like to add to the cluster, use the `addSecurityGroups` method. Security
5659
groups added in this way will not be managed by the `Connections` object of the cluster.
5760

5861
```ts
59-
const securityGroup = new ec2.SecurityGroup(stack, 'SecurityGroup', {
62+
declare const vpc: ec2.Vpc;
63+
declare const cluster: docdb.DatabaseCluster;
64+
65+
const securityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', {
6066
vpc,
6167
});
6268
cluster.addSecurityGroups(securityGroup);
@@ -67,16 +73,17 @@ cluster.addSecurityGroups(securityGroup);
6773
Deletion protection can be enabled on an Amazon DocumentDB cluster to prevent accidental deletion of the cluster:
6874

6975
```ts
70-
const cluster = new DatabaseCluster(this, 'Database', {
71-
masterUser: {
72-
username: 'myuser'
73-
},
74-
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R5, ec2.InstanceSize.LARGE),
75-
vpcSubnets: {
76-
subnetType: ec2.SubnetType.PUBLIC,
77-
},
78-
vpc,
79-
deletionProtection: true // Enable deletion protection.
76+
declare const vpc: ec2.Vpc;
77+
const cluster = new docdb.DatabaseCluster(this, 'Database', {
78+
masterUser: {
79+
username: 'myuser',
80+
},
81+
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R5, ec2.InstanceSize.LARGE),
82+
vpcSubnets: {
83+
subnetType: ec2.SubnetType.PUBLIC,
84+
},
85+
vpc,
86+
deletionProtection: true, // Enable deletion protection.
8087
});
8188
```
8289

@@ -85,6 +92,7 @@ const cluster = new DatabaseCluster(this, 'Database', {
8592
When the master password is generated and stored in AWS Secrets Manager, it can be rotated automatically:
8693

8794
```ts
95+
declare const cluster: docdb.DatabaseCluster;
8896
cluster.addRotationSingleUser(); // Will rotate automatically after 30 days
8997
```
9098

@@ -93,22 +101,28 @@ cluster.addRotationSingleUser(); // Will rotate automatically after 30 days
93101
The multi user rotation scheme is also available:
94102

95103
```ts
104+
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
105+
106+
declare const myImportedSecret: secretsmanager.Secret;
107+
declare const cluster: docdb.DatabaseCluster;
108+
96109
cluster.addRotationMultiUser('MyUser', {
97-
secret: myImportedSecret // This secret must have the `masterarn` key
110+
secret: myImportedSecret, // This secret must have the `masterarn` key
98111
});
99112
```
100113

101114
It's also possible to create user credentials together with the cluster and add rotation:
102115

103116
```ts
117+
declare const cluster: docdb.DatabaseCluster;
104118
const myUserSecret = new docdb.DatabaseSecret(this, 'MyUserSecret', {
105119
username: 'myuser',
106-
masterSecret: cluster.secret
120+
masterSecret: cluster.secret,
107121
});
108122
const myUserSecretAttached = myUserSecret.attach(cluster); // Adds DB connections information in the secret
109123

110124
cluster.addRotationMultiUser('MyUser', { // Add rotation using the multi user scheme
111-
secret: myUserSecretAttached // This secret must have the `masterarn` key
125+
secret: myUserSecretAttached, // This secret must have the `masterarn` key
112126
});
113127
```
114128

@@ -126,8 +140,21 @@ Sending audit or profiler needs to be configured in two places:
126140
2. Enable the corresponding option(s) when creating the `DatabaseCluster`:
127141

128142
```ts
129-
const cluster = new DatabaseCluster(this, 'Database', {
130-
...,
143+
import * as iam from '@aws-cdk/aws-iam';
144+
import * as logs from'@aws-cdk/aws-logs';
145+
146+
declare const myLogsPublishingRole: iam.Role;
147+
declare const vpc: ec2.Vpc;
148+
149+
const cluster = new docdb.DatabaseCluster(this, 'Database', {
150+
masterUser: {
151+
username: 'myuser',
152+
},
153+
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R5, ec2.InstanceSize.LARGE),
154+
vpcSubnets: {
155+
subnetType: ec2.SubnetType.PUBLIC,
156+
},
157+
vpc,
131158
exportProfilerLogsToCloudWatch: true, // Enable sending profiler logs
132159
exportAuditLogsToCloudWatch: true, // Enable sending audit logs
133160
cloudWatchLogsRetention: logs.RetentionDays.THREE_MONTHS, // Optional - default is to never expire logs

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

+8-1
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",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Fixture with packages imported, but nothing else
2+
import { Stack } from '@aws-cdk/core';
3+
import { Construct } from 'constructs';
4+
import * as docdb from '@aws-cdk/aws-docdb';
5+
import * as ec2 from '@aws-cdk/aws-ec2';
6+
7+
class Fixture extends Stack {
8+
constructor(scope: Construct, id: string) {
9+
super(scope, id);
10+
/// here
11+
}
12+
}

0 commit comments

Comments
 (0)