Skip to content

Commit d20938c

Browse files
author
Elad Ben-Israel
authored
feat: deprecate "cloudformation" namespace in favor of "CfnXxx" (#1311)
Rename generated CloudFormation resource constructs from `cloudformation.XxxResource` to `CfnXxx`. This fixes #878 and eliminates the use of namespaces in the CDK. This is done in a backwards compatible way, which means that we still generate the old resources under the `cloudformation` namespace so we can remove them in a subsequent release. Those resources also include a deprecation warning which is emitted upon `cdk synth`. Documentation updated to reflect changes. Related: aws/jsii#283 and aws/jsii#270
1 parent 19fefc6 commit d20938c

File tree

108 files changed

+459
-876
lines changed

Some content is hidden

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

108 files changed

+459
-876
lines changed

docs/src/aws-construct-lib.rst

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ the AWS Construct and patch the underlying resources.
122122

123123
AWS constructs, such as :py:class:`Topic <@aws-cdk/aws-sns.Topic>`, encapsulate
124124
one or more AWS CloudFormation resources behind their APIs. These resources are
125-
also represented as constructs under the ``cloudformation`` namespace in each
125+
also represented as ``CfnXxx`` constructs in each
126126
library. For example, the :py:class:`@aws-cdk/aws-s3.Bucket` construct
127-
encapsulates the :py:class:`@aws-cdk/aws-s3.cloudformation.BucketResource`. When
127+
encapsulates the :py:class:`@aws-cdk/aws-s3.CfnBucket`. When
128128
a stack that includes an AWS construct is synthesized, the CloudFormation
129129
definition of the underlying resources are included in the resulting template.
130130

@@ -167,11 +167,11 @@ given an :py:class:`s3.Bucket <@aws-cdk/s3.Bucket>` construct:
167167
const bucket = new s3.Bucket(this, 'MyBucket');
168168
169169
// we use our knowledge that the main construct is called "Resource" and
170-
// that it's actual type is s3.cloudformation.BucketResource; const
171-
const bucketResource = bucket.findChild('Resource') as s3.cloudformation.BucketResource;
170+
// that it's actual type is s3.CfnBucket; const
171+
const bucketResource = bucket.findChild('Resource') as s3.CfnBucket;
172172
173173
At this point, ``bucketResource`` represents the low-level CloudFormation resource of type
174-
:py:class:`s3.cloudformation.BucketResource <@aws-cdk/aws-s3.cloudformation.BucketResource>`
174+
:py:class:`s3.CfnBucket <@aws-cdk/aws-s3.CfnBucket>`
175175
encapsulated by our bucket.
176176

177177
:py:meth:`construct.findChild(id) <@aws-cdk/cdk.Construct.findChild>` will fail
@@ -186,7 +186,7 @@ type:
186186
187187
const bucketResource =
188188
bucket.children.find(c => (c as cdk.Resource).resourceType === 'AWS::S3::Bucket')
189-
as s3.cloudformation.BucketResource;
189+
as s3.CfnBucket;
190190
191191
From that point, users are interacting with CloudFormation resource classes
192192
(which extend :py:class:`cdk.Resource <@aws-cdk/cdk.Resource>`), so we will look
@@ -203,7 +203,7 @@ For example, this code:
203203

204204
.. code-block:: ts
205205
206-
const bucketResource = bucket.findChild('Resource') as s3.cloudformation.BucketResource;
206+
const bucketResource = bucket.findChild('Resource') as s3.CfnBucket;
207207
208208
bucketResource.options.metadata = { MetadataKey: 'MetadataValue' };
209209
bucketResource.options.updatePolicy = {
@@ -321,7 +321,7 @@ to delete values:
321321
encryption: s3.BucketEncryption.KmsManaged
322322
});
323323
324-
const bucketResource = bucket.findChild('Resource') as s3.cloudformation.BucketResource;
324+
const bucketResource = bucket.findChild('Resource') as s3.CfnBucket;
325325
bucketResource.addPropertyOverride('BucketEncryption.ServerSideEncryptionConfiguration.0.EncryptEverythingAndAlways', true);
326326
bucketResource.addPropertyDeletionOverride('BucketEncryption.ServerSideEncryptionConfiguration.0.ServerSideEncryptionByDefault');
327327
@@ -349,19 +349,18 @@ Directly Defining CloudFormation Resources
349349
-------------------------------------------
350350

351351
It is also possible to explicitly define CloudFormation resources in your stack.
352-
To that end, instantiate one of the constructs under the ``cloudformation``
353-
namespace of the dedicated library.
352+
To that end, instantiate one of the ``CfnXxx`` constructs of the dedicated library.
354353

355354
.. code-block:: ts
356355
357-
new s3.cloudformation.BucketResource(this, 'MyBucket', {
356+
new s3.CfnBucket(this, 'MyBucket', {
358357
analyticsConfigurations: [
359358
// ...
360359
]
361360
});
362361
363362
In the rare case where you want to define a resource that doesn't have a
364-
corresponding ``cloudformation`` class (such as a new resource that was not yet
363+
corresponding ``CfnXxx`` class (such as a new resource that was not yet
365364
published in the CloudFormation resource specification), you can instantiate the
366365
:py:class:`cdk.Resource <@aws-cdk/cdk.Resource>` object:
367366

docs/src/cloudformation.rst

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ the :py:class:`@aws-cdk/aws-sns.Topic` construct can be used to define SNS
2121
Topics, etc.
2222

2323
Under the hood, these constructs are implemented using CloudFormation resources,
24-
which are available under the **cloudformation** namespace of each library. For
24+
which are available under the **CfnXxx** classes in each library. For
2525
example, the :py:class:`@aws-cdk/aws-s3.Bucket` construct uses the
26-
:py:class:`@aws-cdk/aws-s3.cloudformation.BucketResource` resource (as well as
26+
:py:class:`@aws-cdk/aws-s3.CfnBucket` resource (as well as
2727
other resources, depending on what bucket APIs are used).
2828

2929
.. important::
@@ -39,7 +39,7 @@ Resources
3939
CloudFormation resource classes are automatically generated from the `AWS
4040
CloudFormation Resource Specification
4141
<https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-resource-specification.html>`_
42-
and available under the **cloudformation** namespace of each AWS library. Their
42+
and available under the **CfnXxx** classes of each AWS library. Their
4343
API matches 1:1 with how you would use these resources in CloudFormation.
4444

4545
When defining CloudFormation resource, the **props** argument of the class
@@ -51,11 +51,11 @@ resource encrypted with an AWS managed key you can directly specify the
5151
`KmsMasterKeyId <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html#aws-sqs-queue-kmsmasterkeyid>`_
5252
property.
5353

54-
.. code-block:: js
54+
.. code-block:: ts
5555
56-
import { cloudformation } from '@aws-cdk/aws-sqs';
56+
import sqs = require('@aws-cdk/aws-sqs');
5757
58-
new cloudformation.QueueResource(this, 'MyQueueResource', {
58+
new sqs.CfnQueue(this, 'MyQueueResource', {
5959
kmsMasterKeyId: 'alias/aws/sqs'
6060
});
6161
@@ -82,14 +82,14 @@ use one of the properties available on the resource object.
8282
The following example configures a |LAM| function's dead letter queue to use a
8383
the ARN of an |SQS| queue resource.
8484

85-
.. code-block:: js
85+
.. code-block:: ts
8686
87-
import { cloudformation as sqscfn } from '@aws-cdk/aws-sqs';
88-
import { cloudformation as lambdacfn } from '@aws-cdk/aws-lambda';
87+
import sqs = require('@aws-cdk/aws-sqs');
88+
import lambda = require('@aws-cdk/aws-lambda');
8989
90-
const dlq = new sqscfn.QueueResource(this, { name: 'DLQ' });
90+
const dlq = new sqs.CfnQueue(this, { name: 'DLQ' });
9191
92-
new lambdacfn.FunctionResource(this, {
92+
new lambda.CfnFunction(this, {
9393
deadLetterConfig: {
9494
targetArn: dlq.queueArn
9595
}
@@ -118,13 +118,13 @@ Parameters
118118

119119
.. NEEDS SOME INTRO TEXT
120120
121-
.. code-block:: js
121+
.. code-block:: ts
122122
123-
import { cloudformation } from '@aws-cdk/aws-sns';
123+
import sns = require('@aws-cdk/aws-sns');
124124
import cdk = require('@aws-cdk/cdk');
125125
126126
const p = new cdk.Parameter(this, 'MyParam', { type: 'String' });
127-
new cloudformation.TopicResource(this, 'MyTopic', { displayName: p.ref });
127+
new sns.CfnTopic(this, 'MyTopic', { displayName: p.ref });
128128
129129
.. _outputs:
130130

@@ -135,10 +135,10 @@ Outputs
135135
136136
.. code-block:: js
137137
138-
import { cloudformation } from '@aws-cdk/aws-sqs';
138+
import sqs = require('@aws-cdk/aws-sqs');
139139
import cdk = require('@aws-cdk/cdk');
140140
141-
const queue = new cloudformation.QueueResource(this, 'MyQueue');
141+
const queue = new sqs.CfnQueue(this, 'MyQueue');
142142
const out = new cdk.Output(this, 'MyQueueArn', { value: queue.queueArn });
143143
144144
const import = out.makeImportValue();
@@ -153,13 +153,13 @@ Conditions
153153
154154
.. code-block:: js
155155
156-
import { cloudformation } from '@aws-cdk/aws-sqs';
156+
import sqs = require('@aws-cdk/aws-sqs');
157157
import cdk = require('@aws-cdk/cdk');
158158
const cond = new cdk.Condition(this, 'MyCondition', {
159159
expression: new cdk.FnIf(...)
160160
});
161161
162-
const queue = new cloudformation.QueueResource(this, 'MyQueue');
162+
const queue = new sqs.CfnQueue(this, 'MyQueue');
163163
queue.options.condition = cond;
164164
165165
.. _intrinsic_functions:

examples/cdk-examples-typescript/advanced-usage/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cloudformation } from '@aws-cdk/aws-cloudformation';
1+
import { CfnStack } from '@aws-cdk/aws-cloudformation';
22
import ec2 = require('@aws-cdk/aws-ec2');
33
import iam = require('@aws-cdk/aws-iam');
44
import s3 = require('@aws-cdk/aws-s3');
@@ -55,7 +55,7 @@ class EnvContextExample extends cdk.Stack {
5555
// render construct name based on it's availablity zone
5656
const constructName = `InstanceFor${az.replace(/-/g, '').toUpperCase()}`;
5757

58-
new ec2.cloudformation.InstanceResource(this, constructName, {
58+
new ec2.CfnInstance(this, constructName, {
5959
imageId: ami.imageId,
6060
availabilityZone: az,
6161
});
@@ -90,7 +90,7 @@ class IncludeExample extends cdk.Stack {
9090

9191
// add constructs (and resources) programmatically
9292
new EnvContextExample(parent, 'Example');
93-
new sqs.cloudformation.QueueResource(this, 'CDKQueue', {});
93+
new sqs.CfnQueue(this, 'CDKQueue', {});
9494
}
9595
}
9696

@@ -104,7 +104,7 @@ class NestedStackExample extends cdk.Stack {
104104
// add an "AWS::CloudFormation::Stack" resource which uses the MongoDB quickstart
105105
// https://aws.amazon.com/quickstart/architecture/mongodb/
106106
// only non-default values are provided here.
107-
new cloudformation.StackResource(this, 'NestedStack', {
107+
new CfnStack(this, 'NestedStack', {
108108
templateUrl: 'https://s3.amazonaws.com/quickstart-reference/mongodb/latest/templates/mongodb-master.template',
109109
parameters: {
110110
KeyPairName: 'my-key-pair',
@@ -125,10 +125,10 @@ class ResourceReferencesExample extends cdk.Stack {
125125
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
126126
super(parent, name, props);
127127

128-
const topic = new sns.cloudformation.TopicResource(this, 'Topic', {});
129-
const queue = new sqs.cloudformation.QueueResource(this, 'Queue', {});
128+
const topic = new sns.CfnTopic(this, 'Topic', {});
129+
const queue = new sqs.CfnQueue(this, 'Queue', {});
130130

131-
new sns.cloudformation.SubscriptionResource(this, 'Subscription', {
131+
new sns.CfnSubscription(this, 'Subscription', {
132132
topicArn: topic.ref, // resolves to { Ref: <topic-id> }
133133
protocol: 'sqs',
134134
endpoint: queue.queueArn // resolves to { "Fn::GetAtt": [ <queue-id>, "Arn" ] }

examples/cdk-examples-typescript/chat-app/cognito-chat-room-pool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class CognitoChatRoomPool extends cdk.Construct {
66
super(parent, name);
77

88
// Create chat room user pool
9-
const chatPool = new cognito.cloudformation.UserPoolResource(this, 'UserPool', {
9+
const chatPool = new cognito.CfnUserPool(this, 'UserPool', {
1010
adminCreateUserConfig: {
1111
allowAdminCreateUserOnly: false
1212
},
@@ -26,7 +26,7 @@ export class CognitoChatRoomPool extends cdk.Construct {
2626
});
2727

2828
// Now for the client
29-
new cognito.cloudformation.UserPoolClientResource(this, 'UserPoolClient', {
29+
new cognito.CfnUserPoolClient(this, 'UserPoolClient', {
3030
clientName: 'Chat-Room',
3131
explicitAuthFlows: [ 'ADMIN_NO_SRP_AUTH' ],
3232
refreshTokenValidity: 30,

examples/cdk-examples-typescript/cloudformation/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class CloudFormationExample extends cdk.Stack {
55
constructor(parent: cdk.App) {
66
super(parent);
77

8-
new sqs.cloudformation.QueueResource(this, 'MyQueue', {
8+
new sqs.CfnQueue(this, 'MyQueue', {
99
visibilityTimeout: 300
1010
});
1111
}

examples/cdk-examples-typescript/custom-resource/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CustomResource } from '@aws-cdk/aws-cloudformation';
22
import lambda = require('@aws-cdk/aws-lambda');
3-
import { cloudformation as s3 } from '@aws-cdk/aws-s3';
3+
import { CfnBucket } from '@aws-cdk/aws-s3';
44
import cdk = require('@aws-cdk/cdk');
55
import fs = require('fs');
66

@@ -86,7 +86,7 @@ class FailAfterCreatingStack extends cdk.Stack {
8686
});
8787

8888
// Bucket with an invalid name will fail the deployment and cause a rollback
89-
const bucket = new s3.BucketResource(this, 'FailingBucket', {
89+
const bucket = new CfnBucket(this, 'FailingBucket', {
9090
bucketName: 'hello!@#$^'
9191
});
9292

examples/cdk-examples-typescript/resource-overrides/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ResourceOverridesExample extends cdk.Stack {
1515
encryption: s3.BucketEncryption.KmsManaged
1616
});
1717

18-
const bucketResource2 = bucket.findChild('Resource') as s3.cloudformation.BucketResource;
18+
const bucketResource2 = bucket.findChild('Resource') as s3.CfnBucket;
1919
bucketResource2.addPropertyOverride('BucketEncryption.ServerSideEncryptionConfiguration.0.EncryptEverythingAndAlways', true);
2020
bucketResource2.addPropertyDeletionOverride('BucketEncryption.ServerSideEncryptionConfiguration.0.ServerSideEncryptionByDefault');
2121

@@ -25,8 +25,8 @@ class ResourceOverridesExample extends cdk.Stack {
2525
// Accessing the L1 bucket resource from an L2 bucket
2626
//
2727

28-
const bucketResource = bucket.findChild('Resource') as s3.cloudformation.BucketResource;
29-
const anotherWay = bucket.children.find(c => (c as cdk.Resource).resourceType === 'AWS::S3::Bucket') as s3.cloudformation.BucketResource;
28+
const bucketResource = bucket.findChild('Resource') as s3.CfnBucket;
29+
const anotherWay = bucket.children.find(c => (c as cdk.Resource).resourceType === 'AWS::S3::Bucket') as s3.CfnBucket;
3030
assert.equal(bucketResource, anotherWay);
3131

3232
//
@@ -108,7 +108,7 @@ class ResourceOverridesExample extends cdk.Stack {
108108
// need to consule the codebase or use the `.map.find` method above
109109
//
110110

111-
const lc = asg.findChild('LaunchConfig') as autoscaling.cloudformation.LaunchConfigurationResource;
111+
const lc = asg.findChild('LaunchConfig') as autoscaling.CfnLaunchConfiguration;
112112
lc.addPropertyOverride('Foo.Bar', 'Hello');
113113
}
114114
}

examples/cdk-examples-typescript/sns-sqs/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class CFN extends cdk.Stack {
2020
constructor(parent: cdk.App, name: string) {
2121
super(parent, name);
2222

23-
const topic = new sns.cloudformation.TopicResource(this, 'MyTopic');
24-
const queue = new sqs.cloudformation.QueueResource(this, 'MyQueue');
23+
const topic = new sns.CfnTopic(this, 'MyTopic');
24+
const queue = new sqs.CfnQueue(this, 'MyQueue');
2525

26-
new sns.cloudformation.SubscriptionResource(this, 'TopicToQueue', {
26+
new sns.CfnSubscription(this, 'TopicToQueue', {
2727
topicArn: topic.ref, // ref == arn for topics
2828
endpoint: queue.queueName,
2929
protocol: 'sqs'
@@ -36,7 +36,7 @@ class CFN extends cdk.Stack {
3636
.addServicePrincipal('sns.amazonaws.com')
3737
.setCondition('ArnEquals', { 'aws:SourceArn': topic.ref }));
3838

39-
new sqs.cloudformation.QueuePolicyResource(this, 'MyQueuePolicy', {
39+
new sqs.CfnQueuePolicy(this, 'MyQueuePolicy', {
4040
policyDocument,
4141
queues: [ queue.ref ]
4242
});

packages/@aws-cdk/aws-apigateway/lib/deployment.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cdk = require('@aws-cdk/cdk');
22
import crypto = require('crypto');
3-
import { cloudformation } from './apigateway.generated';
3+
import { CfnDeployment, CfnDeploymentProps } from './apigateway.generated';
44
import { RestApiRef } from './restapi-ref';
55

66
export interface DeploymentProps {
@@ -103,13 +103,13 @@ export class Deployment extends cdk.Construct implements cdk.IDependable {
103103
}
104104
}
105105

106-
class LatestDeploymentResource extends cloudformation.DeploymentResource {
106+
class LatestDeploymentResource extends CfnDeployment {
107107
private originalLogicalId?: string;
108108
private lazyLogicalIdRequired: boolean;
109109
private lazyLogicalId?: string;
110110
private hashComponents = new Array<any>();
111111

112-
constructor(parent: cdk.Construct, id: string, props: cloudformation.DeploymentResourceProps) {
112+
constructor(parent: cdk.Construct, id: string, props: CfnDeploymentProps) {
113113
super(parent, id, props);
114114

115115
// from this point, don't allow accessing logical ID before synthesis

packages/@aws-cdk/aws-apigateway/lib/method.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cdk = require('@aws-cdk/cdk');
2-
import { cloudformation } from './apigateway.generated';
2+
import { CfnMethod, CfnMethodProps } from './apigateway.generated';
33
import { Integration } from './integration';
44
import { MockIntegration } from './integrations/mock';
55
import { IRestApiResource } from './resource';
@@ -83,7 +83,7 @@ export class Method extends cdk.Construct {
8383

8484
const defaultMethodOptions = props.resource.defaultMethodOptions || {};
8585

86-
const methodProps: cloudformation.MethodResourceProps = {
86+
const methodProps: CfnMethodProps = {
8787
resourceId: props.resource.resourceId,
8888
restApiId: this.restApi.restApiId,
8989
httpMethod: props.httpMethod,
@@ -94,7 +94,7 @@ export class Method extends cdk.Construct {
9494
integration: this.renderIntegration(props.integration)
9595
};
9696

97-
const resource = new cloudformation.MethodResource(this, 'Resource', methodProps);
97+
const resource = new CfnMethod(this, 'Resource', methodProps);
9898

9999
this.methodId = resource.ref;
100100

@@ -134,7 +134,7 @@ export class Method extends cdk.Construct {
134134
return this.restApi.executeApiArn(this.httpMethod, this.resource.resourcePath, 'test-invoke-stage');
135135
}
136136

137-
private renderIntegration(integration?: Integration): cloudformation.MethodResource.IntegrationProperty {
137+
private renderIntegration(integration?: Integration): CfnMethod.IntegrationProperty {
138138
if (!integration) {
139139
// use defaultIntegration from API if defined
140140
if (this.resource.defaultIntegration) {

0 commit comments

Comments
 (0)