-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdk): aspect framework and tag implementation (#1451)
A generalized aspect framework is added. Aspects can be used to affect the construct tree without modifying the class hierarchy. This framework is designed to be generic for future use cases. Tagging is the first implementation. Tagging has been reimplemented to leverage the aspect framework and simplify the original tag design. Tag Manager still exists, but is no longer intended for use by L2 construct authors. There are two new classes `cdk.Tag` and `cdk.RemoveTag`. As new resources are added tag support will be automatic as long as they implement one of the existing tag specifications. All L2 constructs have removed the TagManager. Code generation has been modified to add tag support to any CloudFormation Resource with a matching specification, by creating a Tag Manager for that resource as a `tags` attribute. The schema code now includes the ability to detect 3 forms of tags which include the current CloudFormation Resources. BREAKING CHANGE: if you are using TagManager the API for this object has completely changed. You should no longer use TagManager directly, but instead replace this with Tag Aspects. `cdk.Tag` has been renamed to `cdk.CfnTag` to enable `cdk.Tag` to be the Tag Aspect. Fixes #1136 Fixes #1497 Related #360
- Loading branch information
Showing
36 changed files
with
1,711 additions
and
1,473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "node index" | ||
} |
53 changes: 53 additions & 0 deletions
53
examples/cdk-examples-typescript/hello-cdk-ecs-tags/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import ec2 = require('@aws-cdk/aws-ec2'); | ||
import ecs = require('@aws-cdk/aws-ecs'); | ||
import cdk = require('@aws-cdk/cdk'); | ||
|
||
const COST_CENTER_KEY = 'CostCenter'; | ||
|
||
class MarketingDepartmentStack extends cdk.Stack { | ||
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
// Create VPC and Fargate Cluster | ||
// NOTE: Limit AZs to avoid reaching resource quotas | ||
const vpc = new ec2.VpcNetwork(this, 'MyVpc', { maxAZs: 3 }); | ||
|
||
// override cost center to platform | ||
vpc.apply(new cdk.Tag(COST_CENTER_KEY, 'Platform')); | ||
|
||
const cluster = new ecs.Cluster(this, 'Cluster', { vpc }); | ||
|
||
// Create a load-balanced Fargate service and make it public | ||
const b2b = new ecs.LoadBalancedFargateService(this, 'B2BService', { | ||
cluster, // Required | ||
cpu: '512', // Default is 256 | ||
desiredCount: 6, // Default is 1 | ||
image: ecs.ContainerImage.fromDockerHub('amazon/amazon-ecs-sample'), // Required | ||
memoryMiB: '2048', // Default is 512 | ||
publicLoadBalancer: true // Default is false | ||
}); | ||
|
||
// Create a load-balanced Fargate service and make it public | ||
const b2c = new ecs.LoadBalancedFargateService(this, 'B2CService', { | ||
cluster, // Required | ||
cpu: '512', // Default is 256 | ||
desiredCount: 6, // Default is 1 | ||
image: ecs.ContainerImage.fromDockerHub('amazon/amazon-ecs-sample'), // Required | ||
memoryMiB: '2048', // Default is 512 | ||
publicLoadBalancer: true // Default is false | ||
}); | ||
|
||
// Output the DNS where you can access your service | ||
new cdk.Output(this, 'B2BLoadBalancerDNS', { value: b2b.loadBalancer.dnsName }); | ||
new cdk.Output(this, 'B2CLoadBalancerDNS', { value: b2c.loadBalancer.dnsName }); | ||
} | ||
} | ||
|
||
const app = new cdk.App(); | ||
|
||
// by default bill everything to marketing overrides are in the stack | ||
app.apply(new cdk.Tag(COST_CENTER_KEY, 'Marketing')); | ||
|
||
new MarketingDepartmentStack(app, 'Bonjour'); | ||
|
||
app.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.