Skip to content

Commit 15e18c8

Browse files
authored
chore(cdk-lib): fix most of the Rosetta example compilation failures (#25030)
Many a compilation error has slipped into our examples. Turn Rosetta strict mode back on for `aws-cdk-lib`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c174a49 commit 15e18c8

File tree

85 files changed

+656
-525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+656
-525
lines changed

packages/aws-cdk-lib/README.md

+48-40
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ According to the kind of project you are developing:
2727

2828
You can use a classic import to get access to each service namespaces:
2929

30-
```ts
30+
```ts nofixture
3131
import { Stack, App, aws_s3 as s3 } from 'aws-cdk-lib';
3232

3333
const app = new App();
@@ -40,7 +40,7 @@ new s3.Bucket(stack, 'TestBucket');
4040

4141
Alternatively, you can use "barrel" imports:
4242

43-
```ts
43+
```ts nofixture
4444
import { App, Stack } from 'aws-cdk-lib';
4545
import { Bucket } from 'aws-cdk-lib/aws-s3';
4646

@@ -684,13 +684,13 @@ exports.handler = async (e) => {
684684
`sum.ts`:
685685

686686
```ts nofixture
687+
import { Construct } from 'constructs';
687688
import {
688-
Construct,
689689
CustomResource,
690690
CustomResourceProvider,
691691
CustomResourceProviderRuntime,
692692
Token,
693-
} from '@aws-cdk/core';
693+
} from 'aws-cdk-lib';
694694

695695
export interface SumProps {
696696
readonly lhs: number;
@@ -911,7 +911,7 @@ a property of the creationPolicy on the resource options. Setting it to true wil
911911
resources that depend on the fleet resource.
912912

913913
```ts
914-
const fleet = new CfnFleet(stack, 'Fleet', {
914+
const fleet = new appstream.CfnFleet(this, 'Fleet', {
915915
instanceType: 'stream.standard.small',
916916
name: 'Fleet',
917917
computeCapacity: {
@@ -930,14 +930,18 @@ The properties passed to the level 2 constructs `AutoScalingGroup` and `Instance
930930

931931
The CfnWaitCondition resource from the `aws-cloudformation` module suppports the `resourceSignal`.
932932
The format of the timeout is `PT#H#M#S`. In the example below AWS Cloudformation will wait for
933-
3 success signals to occur within 15 minutes before the status of the resource will be set to
933+
3 success signals to occur within 15 minutes before the status of the resource will be set to
934934
`CREATE_COMPLETE`.
935935

936936
```ts
937-
resource.cfnOptions.resourceSignal = {
938-
count: 3,
939-
timeout: 'PR15M',
940-
}
937+
declare const resource: CfnResource;
938+
939+
resource.cfnOptions.creationPolicy = {
940+
resourceSignal: {
941+
count: 3,
942+
timeout: 'PR15M',
943+
}
944+
};
941945
```
942946

943947
[creation-policy]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-creationpolicy.html
@@ -1290,8 +1294,6 @@ to all roles within a specific construct scope. The most common use case would
12901294
be to apply a permissions boundary at the `Stage` level.
12911295

12921296
```ts
1293-
declare const app: App;
1294-
12951297
const prodStage = new Stage(app, 'ProdStage', {
12961298
permissionsBoundary: PermissionsBoundary.fromName('cdk-${Qualifier}-PermissionsBoundary'),
12971299
});
@@ -1323,19 +1325,21 @@ will be printed to the console or to a file (see below).
13231325
To use one or more validation plugins in your application, use the
13241326
`policyValidationBeta1` property of `Stage`:
13251327

1326-
```ts
1328+
```ts fixture=validation-plugin
13271329
// globally for the entire app (an app is a stage)
13281330
const app = new App({
13291331
policyValidationBeta1: [
1330-
// These hypothetical classes implement IValidationPlugin:
1331-
new ThirdPartyPluginX(),
1332+
// These hypothetical classes implement IPolicyValidationPluginBeta1:
1333+
new ThirdPartyPluginX(),
13321334
new ThirdPartyPluginY(),
13331335
],
13341336
});
13351337
13361338
// only apply to a particular stage
13371339
const prodStage = new Stage(app, 'ProdStage', {
1338-
policyValidationBeta1: [...],
1340+
policyValidationBeta1: [
1341+
new ThirdPartyPluginX(),
1342+
],
13391343
});
13401344
```
13411345

@@ -1351,12 +1355,12 @@ validation.
13511355
> secure to use.
13521356

13531357
By default, the report will be printed in a human readable format. If you want a
1354-
report in JSON format, enable it using the `@aws-cdk/core:validationReportJson`
1358+
report in JSON format, enable it using the `@aws-cdk/core:validationReportJson`
13551359
context passing it directly to the application:
13561360

13571361
```ts
1358-
const app = new App({
1359-
context: { '@aws-cdk/core:validationReportJson': true },
1362+
const app = new App({
1363+
context: { '@aws-cdk/core:validationReportJson': true },
13601364
});
13611365
```
13621366

@@ -1372,35 +1376,39 @@ the standard output.
13721376
### For plugin authors
13731377

13741378
The communication protocol between the CDK core module and your policy tool is
1375-
defined by the `IValidationPluginBeta1` interface. To create a new plugin you must
1379+
defined by the `IPolicyValidationPluginBeta1` interface. To create a new plugin you must
13761380
write a class that implements this interface. There are two things you need to
13771381
implement: the plugin name (by overriding the `name` property), and the
13781382
`validate()` method.
13791383

1380-
The framework will call `validate()`, passing an `IValidationContextBeta1` object.
1384+
The framework will call `validate()`, passing an `IPolicyValidationContextBeta1` object.
13811385
The location of the templates to be validated is given by `templatePaths`. The
1382-
plugin should return an instance of `ValidationPluginReportBeta1`. This object
1386+
plugin should return an instance of `PolicyValidationPluginReportBeta1`. This object
13831387
represents the report that the user wil receive at the end of the synthesis.
13841388

1385-
```ts
1386-
validate(context: ValidationContextBeta1): ValidationReportBeta1 {
1387-
// First read the templates using context.templatePaths...
1388-
1389-
// ...then perform the validation, and then compose and return the report.
1390-
// Using hard-coded values here for better clarity:
1391-
return {
1392-
success: false,
1393-
violations: [{
1394-
ruleName: 'CKV_AWS_117',
1395-
recommendation: 'Ensure that AWS Lambda function is configured inside a VPC',
1396-
fix: 'https://docs.bridgecrew.io/docs/ensure-that-aws-lambda-function-is-configured-inside-a-vpc-1',
1397-
violatingResources: [{
1398-
resourceName: 'MyFunction3BAA72D1',
1399-
templatePath: '/home/johndoe/myapp/cdk.out/MyService.template.json',
1400-
locations: 'Properties/VpcConfig',
1389+
```ts fixture=validation-plugin
1390+
class MyPlugin implements IPolicyValidationPluginBeta1 {
1391+
public readonly name = 'MyPlugin';
1392+
1393+
public validate(context: IPolicyValidationContextBeta1): PolicyValidationPluginReportBeta1 {
1394+
// First read the templates using context.templatePaths...
1395+
1396+
// ...then perform the validation, and then compose and return the report.
1397+
// Using hard-coded values here for better clarity:
1398+
return {
1399+
success: false,
1400+
violations: [{
1401+
ruleName: 'CKV_AWS_117',
1402+
description: 'Ensure that AWS Lambda function is configured inside a VPC',
1403+
fix: 'https://docs.bridgecrew.io/docs/ensure-that-aws-lambda-function-is-configured-inside-a-vpc-1',
1404+
violatingResources: [{
1405+
resourceLogicalId: 'MyFunction3BAA72D1',
1406+
templatePath: '/home/johndoe/myapp/cdk.out/MyService.template.json',
1407+
locations: ['Properties/VpcConfig'],
1408+
}],
14011409
}],
1402-
}],
1403-
};
1410+
};
1411+
}
14041412
}
14051413
```
14061414

packages/aws-cdk-lib/aws-apigateway/README.md

+41-37
Original file line numberDiff line numberDiff line change
@@ -730,50 +730,54 @@ books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), {
730730

731731
A full working example is shown below.
732732

733-
```ts
733+
```ts nofixture
734734
import * as path from 'path';
735735
import * as lambda from 'aws-cdk-lib/aws-lambda';
736+
import { Construct } from 'constructs';
736737
import { App, Stack } from 'aws-cdk-lib';
737-
import { MockIntegration, PassthroughBehavior, RestApi, TokenAuthorizer, Cors } from '../../lib';
738+
import { MockIntegration, PassthroughBehavior, RestApi, TokenAuthorizer, Cors } from 'aws-cdk-lib/aws-apigateway';
738739

739740
/// !show
740-
const app = new App();
741-
const stack = new Stack(app, 'TokenAuthorizerInteg');
742-
743-
const authorizerFn = new lambda.Function(stack, 'MyAuthorizerFunction', {
744-
runtime: lambda.Runtime.NODEJS_14_X,
745-
handler: 'index.handler',
746-
code: lambda.AssetCode.fromAsset(path.join(__dirname, 'integ.token-authorizer.handler')),
747-
});
748-
749-
const authorizer = new TokenAuthorizer(stack, 'MyAuthorizer', {
750-
handler: authorizerFn,
751-
});
752-
753-
const restapi = new RestApi(stack, 'MyRestApi', {
754-
cloudWatchRole: true,
755-
defaultMethodOptions: {
756-
authorizer,
757-
},
758-
defaultCorsPreflightOptions: {
759-
allowOrigins: Cors.ALL_ORIGINS,
760-
},
761-
});
741+
class MyStack extends Stack {
742+
constructor(scope: Construct, id: string) {
743+
super(scope, id);
744+
745+
const authorizerFn = new lambda.Function(this, 'MyAuthorizerFunction', {
746+
runtime: lambda.Runtime.NODEJS_14_X,
747+
handler: 'index.handler',
748+
code: lambda.AssetCode.fromAsset(path.join(__dirname, 'integ.token-authorizer.handler')),
749+
});
750+
751+
const authorizer = new TokenAuthorizer(this, 'MyAuthorizer', {
752+
handler: authorizerFn,
753+
});
754+
755+
const restapi = new RestApi(this, 'MyRestApi', {
756+
cloudWatchRole: true,
757+
defaultMethodOptions: {
758+
authorizer,
759+
},
760+
defaultCorsPreflightOptions: {
761+
allowOrigins: Cors.ALL_ORIGINS,
762+
},
763+
});
762764

763765

764-
restapi.root.addMethod('ANY', new MockIntegration({
765-
integrationResponses: [
766-
{ statusCode: '200' },
767-
],
768-
passthroughBehavior: PassthroughBehavior.NEVER,
769-
requestTemplates: {
770-
'application/json': '{ "statusCode": 200 }',
771-
},
772-
}), {
773-
methodResponses: [
774-
{ statusCode: '200' },
775-
],
776-
});
766+
restapi.root.addMethod('ANY', new MockIntegration({
767+
integrationResponses: [
768+
{ statusCode: '200' },
769+
],
770+
passthroughBehavior: PassthroughBehavior.NEVER,
771+
requestTemplates: {
772+
'application/json': '{ "statusCode": 200 }',
773+
},
774+
}), {
775+
methodResponses: [
776+
{ statusCode: '200' },
777+
],
778+
});
779+
}
780+
}
777781
```
778782

779783
By default, the `TokenAuthorizer` looks for the authorization token in the request header with the key 'Authorization'. This can,

0 commit comments

Comments
 (0)