Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: aws resource api linting (breaking changes) #1434

Merged
merged 29 commits into from
Dec 28, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
71b60e4
Convert FnXxx to Fn.xxx()
Dec 25, 2018
69da340
Pseudo parameters from new Aws.Xxx() to Aws.xxx
Dec 25, 2018
f2827d0
Finalize change
Dec 25, 2018
0424e80
Move FnCondition to condition.ts
Dec 25, 2018
13b7d91
feat: normalize import/export APIs of all AWS resources
Dec 26, 2018
7ad4d40
A few more lints
Dec 26, 2018
cf839e0
CR fixes
Dec 27, 2018
603a460
Revert "Pseudo parameters from new Aws.Xxx() to Aws.xxx"
Dec 27, 2018
0130c76
Do not use FnBase as an external base class
Dec 27, 2018
b9fb939
Merge branch 'master' into benisrae/intrinsics-and-pseudo-refactor
Dec 27, 2018
dbd80d9
Remove merge error
Dec 27, 2018
e967937
Rename condition methods
Dec 27, 2018
7e2c49d
Merge branch 'master' into benisrae/api-linting
Dec 27, 2018
757d793
Add missing imported classes
Dec 27, 2018
d4a30a5
Retain immutability of IHostedZone attributes
Dec 27, 2018
584b8bc
Fix event sources
Dec 27, 2018
6cc21b8
Merge remote-tracking branch 'origin/master' into benisrae/api-linting
Dec 27, 2018
d341522
fix linting error
Dec 27, 2018
eb6c206
Rename XxxAttributes to XxxImportProps
Dec 27, 2018
be2fcd0
Renames in comments
Dec 27, 2018
546df1d
Fix linting error
Dec 27, 2018
8f5fe1e
yet another tslint error
Dec 27, 2018
4ccd6f1
a few more linting
Dec 27, 2018
41888be
Add coverge to rule import/export
Dec 27, 2018
980a1da
Extend converage
Dec 27, 2018
6687081
Preserve logical id
Dec 27, 2018
b81a1fd
Fix another hosted zone logical id
Dec 27, 2018
dcde666
fix .net issue
Dec 27, 2018
ae2e27e
remove another inherited override
Dec 27, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ Fn.if_(Fn.equals(param.ref, 'True'), 'Encrypted', Pseudo.NO_VALUE)
After:

```javascript
new FnIf(new FnEquals(param.ref, 'True'), 'Encrypted', new AwsNoValue())
new FnIf(Fn.equals(param.ref, 'True'), 'Encrypted', new AwsNoValue())
```

- CloudFormation template options (`templateFormatVersion`, `description` and `transform`) are now grouped under `Stack.templateOptions` instead of directly under `Stack`.
Expand Down
15 changes: 9 additions & 6 deletions docs/src/aws-construct-lib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function.

Furthermore, most AWS Constructs expose ``grant*`` methods which allow
intent-based permission definitions. For example, the AWS S3 :py:class:`Bucket <@aws-cdk/aws-s3.Bucket>`
construct has a :py:meth:`grantRead(principal) <@aws-cdk/aws-s3.BucketRef.grantRead>`
construct has a :py:meth:`grantRead(principal) <@aws-cdk/aws-s3.IBucket.grantRead>`
method which accepts an AWS IAM :py:class:`Principal <@aws-cdk/aws-iam.IPrincipal>`
such as a :py:class:`User <@aws-cdk/aws-iam.User>` or a :py:class:`Role <@aws-cdk/aws-iam.Role>`,
and will modify their policy to allow the principal to read objects from the bucket.
Expand All @@ -52,7 +52,7 @@ Event-Driven APIs
Many of the AWS constructs include ``on*`` methods which can be used to react
to events emitted by the construct. For example, the AWS CodeCommit
:py:mod:`Repository <@aws-cdk/aws-codecommit.Repository>` construct has an
:py:meth:`onCommit <@aws-cdk/aws-codecommit.RepositoryRef.onCommit>` method.
:py:meth:`onCommit <@aws-cdk/aws-codecommit.IRepository.onCommit>` method.

AWS Constructs that can be used as targets for various event providers implement
interfaces such as :py:mod:`IEventRuleTarget <@aws-cdk/aws-events.IEventRuleTarget>`
Expand Down Expand Up @@ -84,7 +84,7 @@ Many AWS resources emit AWS CloudWatch metrics as part of their normal operation
be used to setup :py:mod:`Alarms <@aws-cdk/aws-cloudwatch.Alarm>` or included in :py:mod:`Dashboards <@aws-cdk/aws-cloudwatch.Dashboard>`.

:py:mod:`Metric <@aws-cdk/aws-cloudwatch.Metric>` objects for AWS Constructs can be obtained
via ``metricXxx()`` methods. For example, the :py:meth:`metricDuration() <@aws-cdk/aws-lambda.FunctionRef.metricDuration>`
via ``metricXxx()`` methods. For example, the :py:meth:`metricDuration() <@aws-cdk/aws-lambda.IFunction.metricDuration>`
method reports the execution time of an AWS Lambda function.

For more information see the :doc:`refs/_aws-cdk_aws-cloudwatch` documentation.
Expand All @@ -95,12 +95,15 @@ Imports
=======

If you need to reference a resource which is defined outside of your CDK app (e.g. a bucket, a VPC, etc),
you can use the ``Xxxx.import(...)`` static methods which are available on AWS Constructs. For example,
the :py:meth:`Bucket.import() <@aws-cdk/aws-s3.BucketRef.import>` method can be used to obtain
a :py:mod:`BucketRef <@aws-cdk/aws-s3.BucketRef>` object which can be used in most places where
you can use the ``Xxxx.import(...)`` static methods which are available on AWS Constructs.

For example, the :py:meth:`Bucket.import() <@aws-cdk/aws-s3.Bucket.import>` method can be used to obtain
an :py:mod:`IBucket <@aws-cdk/aws-s3.IBucket>` object which can be used in most places where
a bucket is required. This patterns allows treating resources defined outside your app as if they
were part of your app.



.. _cloudformation_layer:

Access the AWS CloudFormation Layer
Expand Down
8 changes: 4 additions & 4 deletions docs/src/cloudformation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ Intrinsic Functions

.. code-block:: js

import cdk = require('@aws-cdk/cdk');
new cdk.FnJoin(",", [...])
import { Fn } from'@aws-cdk/cdk';
Fn.join(",", [...])

.. _pseudo_parameters:

Expand All @@ -183,8 +183,8 @@ Pseudo Parameters

.. code-block:: js

import cdk = require('@aws-cdk/cdk');
new cdk.AwsRegion()
import { Aws } from '@aws-cdk/cdk';
Aws.region

.. Add a new topic in "Advanced Topics" about integrating
cdk synch > mytemplate
Expand Down
2 changes: 1 addition & 1 deletion docs/src/constructs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Construct IDs may be any string with the following caveats:
* Path separators (``/``s) will be replaced by double-dashes ``--``. This means
that if you are trying to look up a child construct that may have a path separator,
you will need to manually replace it with ``--``.
* Construct IDs may not include unresolved tokens (such as `new AwsRegion()`). This is
* Construct IDs may not include unresolved tokens (such as `Aws.region`). This is
because those tokens are only resolved during deployment, and therefore cannot be used
to render a stable logical ID for any resources in this tree.

Expand Down
12 changes: 6 additions & 6 deletions docs/src/passing-in-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ in the stack property.

class HelloCdkStack extends cdk.Stack {
// Property that defines the stack you are exporting from
public readonly myBucketRefProps: s3.BucketRefProps;
public readonly myBucketAttributes: s3.BucketAttributes;

constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);

const mybucket = new s3.Bucket(this, "MyFirstBucket");

// Save bucket's *BucketRefProps*
this.myBucketRefProps = mybucket.export();
// Save bucket's *BucketAttributes*
this.myBucketAttributes = mybucket.export();
}
}

Expand All @@ -193,7 +193,7 @@ We use this interface to pass the bucket properties between the two stacks.

// Interface we'll use to pass the bucket's properties to another stack
interface MyCdkStackProps {
theBucketRefProps: s3.BucketRefProps;
theBucketAttributes: s3.BucketAttributes;
}

Create the second stack that gets a reference to the other bucket
Expand All @@ -206,7 +206,7 @@ from the properties passed in through the constructor.
constructor(parent: cdk.App, name: string, props: MyCdkStackProps) {
super(parent, name);

const myOtherBucket = s3.Bucket.import(this, "MyOtherBucket", props.theBucketRefProps);
const myOtherBucket = s3.Bucket.import(this, "MyOtherBucket", props.theBucketAttributes);

// Do something with myOtherBucket
}
Expand All @@ -221,7 +221,7 @@ Finally, connect the dots in your app.
const myStack = new HelloCdkStack(app, "HelloCdkStack");

new MyCdkStack(app, "MyCdkStack", {
theBucketRefProps: myStack.myBucketRefProps
theBucketAttributes: myStack.myBucketAttributes
});

app.run();
Expand Down
30 changes: 15 additions & 15 deletions examples/cdk-examples-typescript/advanced-usage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class CloudFormationExample extends cdk.Stack {
// outputs are constructs the synthesize into the template's "Outputs" section
new cdk.Output(this, 'Output', {
description: 'This is an output of the template',
value: new cdk.FnConcat(new cdk.AwsAccountId(), '/', param.ref)
value: `${cdk.Aws.accountId}/${param.ref}`
});

// stack.templateOptions can be used to specify template-level options
Expand All @@ -166,23 +166,23 @@ class CloudFormationExample extends cdk.Stack {

// all CloudFormation's pseudo-parameters are supported via the `cdk.AwsXxx` classes
eladb marked this conversation as resolved.
Show resolved Hide resolved
PseudoParameters: [
new cdk.AwsAccountId(),
new cdk.AwsDomainSuffix(),
new cdk.AwsNotificationARNs(),
new cdk.AwsNoValue(),
new cdk.AwsPartition(),
new cdk.AwsRegion(),
new cdk.AwsStackId(),
new cdk.AwsStackName(),
cdk.Aws.accountId,
cdk.Aws.domainSuffix,
cdk.Aws.notificationARNs,
cdk.Aws.noValue,
cdk.Aws.partition,
cdk.Aws.region,
cdk.Aws.stackId,
cdk.Aws.stackName,
],

// all CloudFormation's intrinsic functions are supported via the `cdk.FnXxx` classes
// all CloudFormation's intrinsic functions are supported via the `cdk.Fn.xxx` static methods.
IntrinsicFunctions: [
new cdk.FnAnd(
new cdk.FnFindInMap('MyMap', 'K1', 'K2'),
new cdk.FnSub('hello ${world}', {
world: new cdk.FnBase64(param.ref) // resolves to { Ref: <param-id> }
}))
cdk.Fn.join('', [
cdk.Fn.findInMap('MyMap', 'K1', 'K2'),
cdk.Fn.sub('hello ${world}', {
world: cdk.Fn.base64(param.ref) // resolves to { Ref: <param-id> }
}) ])
],
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import cdk = require('@aws-cdk/cdk');
// `Bucket.import`.

class Producer extends cdk.Stack {
public readonly myBucketRef: s3.BucketRefProps;
public readonly myBucketRef: s3.BucketAttributes;

constructor(parent: cdk.App, name: string) {
super(parent, name);
Expand Down Expand Up @@ -35,7 +35,7 @@ class ConsumerConstruct extends cdk.Construct {
// this bucket and contents.

interface ConsumerProps {
userBucketRef: s3.BucketRefProps;
userBucketRef: s3.BucketAttributes;
}

class Consumer extends cdk.Stack {
Expand Down
2 changes: 1 addition & 1 deletion examples/cdk-examples-typescript/chat-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MyStack extends cdk.Stack {

new CognitoChatRoomPool(this, 'UserPool');

const bucket = s3.BucketRef.import(this, 'DougsBucket', {
const bucket = s3.Bucket.import(this, 'DougsBucket', {
bucketName: 'dougs-chat-app'
});

Expand Down
2 changes: 1 addition & 1 deletion examples/cdk-examples-typescript/ec2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MyApp extends cdk.Stack {
}

class CommonInfrastructure extends cdk.Stack {
public vpc: ec2.VpcNetworkRefProps;
public vpc: ec2.VpcNetworkAttributes;

constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const exportedVpc = new ec2.VpcNetwork(vpcStack, 'VPC', {

const appStack = new cdk.Stack(app, 'AppStack');

const importedVpc = ec2.VpcNetworkRef.import(appStack, 'VPC', exportedVpc.export());
const importedVpc = ec2.VpcNetwork.import(appStack, 'VPC', exportedVpc.export());

const asg = new autoscaling.AutoScalingGroup(appStack, 'ASG', {
vpc: importedVpc,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"pkglint": "tools/pkglint/bin/pkglint -f ."
},
"devDependencies": {
"@types/node": "^8.10.38",
"@types/node": "8.10.38",
eladb marked this conversation as resolved.
Show resolved Hide resolved
"@types/nodeunit": "^0.0.30",
"conventional-changelog-cli": "^2.0.5",
"lerna": "^3.3.0",
Expand Down
9 changes: 8 additions & 1 deletion packages/@aws-cdk/assets-docker/lib/adopted-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class AdoptedRepository extends ecr.RepositoryBase {

private readonly policyDocument = new iam.PolicyDocument();

constructor(parent: cdk.Construct, id: string, props: AdoptedRepositoryProps) {
constructor(parent: cdk.Construct, id: string, private readonly props: AdoptedRepositoryProps) {
super(parent, id);

const fn = new lambda.SingletonFunction(this, 'Function', {
Expand Down Expand Up @@ -70,6 +70,13 @@ export class AdoptedRepository extends ecr.RepositoryBase {
this.repositoryArn = ecr.Repository.arnForLocalRepository(this.repositoryName);
}

/**
* Export this repository from the stack
*/
public export() {
return this.props;
}

/**
* Adds a statement to the repository resource policy.
*
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/assets-docker/lib/image-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export class DockerImageAsset extends cdk.Construct {
this.addMetadata(cxapi.ASSET_METADATA, asset);

// parse repository name and tag from the parameter (<REPO_NAME>:<TAG>)
const components = new cdk.FnSplit(':', imageNameParameter.value);
const repositoryName = new cdk.FnSelect(0, components).toString();
const imageTag = new cdk.FnSelect(1, components).toString();
const components = cdk.Fn.split(':', imageNameParameter.valueAsString);
const repositoryName = cdk.Fn.select(0, components).toString();
const imageTag = cdk.Fn.select(1, components).toString();

// Require that repository adoption happens first, so we route the
// input ARN into the Custom Resource and then get the URI which we use to
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/assets/lib/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class Asset extends cdk.Construct {
/**
* The S3 bucket in which this asset resides.
*/
public readonly bucket: s3.BucketRef;
public readonly bucket: s3.IBucket;

/**
* Indicates if this asset is a zip archive. Allows constructs to ensure that the
Expand Down Expand Up @@ -110,11 +110,11 @@ export class Asset extends cdk.Construct {
});

this.s3BucketName = bucketParam.value.toString();
this.s3Prefix = new cdk.FnSelect(0, new cdk.FnSplit(cxapi.ASSET_PREFIX_SEPARATOR, keyParam.value)).toString();
const s3Filename = new cdk.FnSelect(1, new cdk.FnSplit(cxapi.ASSET_PREFIX_SEPARATOR, keyParam.value)).toString();
this.s3Prefix = cdk.Fn.select(0, cdk.Fn.split(cxapi.ASSET_PREFIX_SEPARATOR, keyParam.valueAsString)).toString();
const s3Filename = cdk.Fn.select(1, cdk.Fn.split(cxapi.ASSET_PREFIX_SEPARATOR, keyParam.valueAsString)).toString();
this.s3ObjectKey = `${this.s3Prefix}${s3Filename}`;

this.bucket = s3.BucketRef.import(this, 'AssetBucket', {
this.bucket = s3.Bucket.import(this, 'AssetBucket', {
bucketName: this.s3BucketName
});

Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-apigateway/lib/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import cdk = require('@aws-cdk/cdk');
import crypto = require('crypto');
import { CfnDeployment, CfnDeploymentProps } from './apigateway.generated';
import { RestApiRef } from './restapi-ref';
import { IRestApi } from './restapi';

export interface DeploymentProps {
/**
* The Rest API to deploy.
*/
api: RestApiRef;
api: IRestApi;

/**
* A description of the purpose of the API Gateway deployment.
Expand Down Expand Up @@ -56,7 +56,7 @@ export interface DeploymentProps {
*/
export class Deployment extends cdk.Construct implements cdk.IDependable {
public readonly deploymentId: string;
public readonly api: RestApiRef;
public readonly api: IRestApi;

/**
* Allows taking a dependency on this construct.
Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/aws-apigateway/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './restapi';
export * from './restapi-ref';
export * from './resource';
export * from './method';
export * from './integration';
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/integrations/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export interface LambdaIntegrationOptions extends IntegrationOptions {
*
*/
export class LambdaIntegration extends AwsIntegration {
private readonly handler: lambda.FunctionRef;
private readonly handler: lambda.IFunction;
private readonly enableTest: boolean;

constructor(handler: lambda.FunctionRef, options: LambdaIntegrationOptions = { }) {
constructor(handler: lambda.IFunction, options: LambdaIntegrationOptions = { }) {
const proxy = options.proxy === undefined ? true : options.proxy;

super({
Expand Down
46 changes: 0 additions & 46 deletions packages/@aws-cdk/aws-apigateway/lib/restapi-ref.ts
Original file line number Diff line number Diff line change
@@ -1,46 +0,0 @@
import cdk = require('@aws-cdk/cdk');

export interface RestApiRefProps {
/**
* The REST API ID of an existing REST API resource.
*/
restApiId: string;
}

export abstract class RestApiRef extends cdk.Construct {

/**
* Imports an existing REST API resource.
* @param parent Parent construct
* @param id Construct ID
* @param props Imported rest API properties
*/
public static import(parent: cdk.Construct, id: string, props: RestApiRefProps): RestApiRef {
return new ImportedRestApi(parent, id, props);
}

/**
* The ID of this API Gateway RestApi.
*/
public readonly abstract restApiId: string;

/**
* Exports a REST API resource from this stack.
* @returns REST API props that can be imported to another stack.
*/
public export(): RestApiRefProps {
return {
restApiId: new cdk.Output(this, 'RestApiId', { value: this.restApiId }).makeImportValue().toString()
};
}
}

class ImportedRestApi extends RestApiRef {
public restApiId: string;

constructor(parent: cdk.Construct, id: string, props: RestApiRefProps) {
super(parent, id);

this.restApiId = props.restApiId;
}
}
Loading