You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> **This is a stable example. It should successfully build out of the box**
10
+
>
11
+
> This example is built on Construct Libraries marked "Stable" and does not have any infrastructure prerequisites to build.
12
+
13
+
---
14
+
<!--END STABILITY BANNER-->
15
+
16
+
This sample shows how you can override the behavior for allocating logical names to CloudFormation resources in the CDK.
17
+
18
+
It implements a feature that allows users to specify a prefix for all logical names using the `prefix` context key.
19
+
20
+
## Usage
21
+
22
+
1. Extend your stacks from [`BaseStack`](src/main/java/com/myorg/BaseStack.java) instead of `Stack`.
23
+
2. Specify the context when calling the CLI through `--context prefix=PREFIX`.
24
+
25
+
## Implementation
26
+
27
+
The [`BaseStack`](src/main/java/com/myorg/BaseStack.java) class implements this custom behavior. Using a base stack is a
28
+
common and recommended pattern for reusing policy within an organization.
29
+
30
+
Then, any stack that derives from [`BaseStack`](src/main/java/com/myorg/BaseStack.java) will automatically have this
31
+
behavior.
32
+
33
+
## Build
34
+
35
+
To build this example, you need to be in this example's root directory. Then run the following:
36
+
37
+
```bash
38
+
npm install -g aws-cdk
39
+
npm install
40
+
cdk synth
41
+
```
42
+
43
+
This will install the necessary CDK, then this example's dependencies, and then build the CloudFormation template. The resulting CloudFormation template will be in the `cdk.out` directory.
44
+
45
+
## Deploy
46
+
47
+
Run `cdk deploy --context prefix=PREFIX`. This will deploy / redeploy your Stack to your AWS Account.
48
+
49
+
## Example
50
+
51
+
Without prefix:
52
+
53
+
```shell
54
+
$ cdk synth -j
55
+
{
56
+
"Resources": {
57
+
"MyTopic86869434": {
58
+
"Type": "AWS::SNS::Topic"
59
+
},
60
+
"MyBucketF68F3FF0": {
61
+
"Type": "AWS::S3::Bucket"
62
+
}
63
+
}
64
+
}
65
+
```
66
+
67
+
With prefix:
68
+
69
+
```shell
70
+
$ cdk synth -j -c prefix="MyTeam"
71
+
{
72
+
"Resources": {
73
+
"MyTeamMyTopic86869434": {
74
+
"Type": "AWS::SNS::Topic"
75
+
},
76
+
"MyTeamMyBucketF68F3FF0": {
77
+
"Type": "AWS::S3::Bucket"
78
+
}
79
+
}
80
+
}
81
+
```
82
+
83
+
## Useful commands
84
+
85
+
```
86
+
* `mvn clean package` compile and run tests
87
+
* `cdk ls` list all stacks in the app
88
+
* `cdk synth` emits the synthesized CloudFormation template
89
+
* `cdk deploy` deploy this stack to your default AWS account/region
90
+
* `cdk diff` compare deployed stack with current state
0 commit comments