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
Copy file name to clipboardExpand all lines: posts/2023-10-07-the-stack-part-2.md
+23-20Lines changed: 23 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,11 +103,12 @@ Instead of setting this up from scratch, start from the template for this step i
103
103
104
104
Our overall aim is to structure our CDK into three main groupings:
105
105
106
-
-`Cloud`: Hosted Zones, VPC, Certificates, infrequently changing things
106
+
-`Global`: "Global" (often `us-east-1`) specific things such as ACM Certificates for CloudFront, and we'll also put Hosted Zones here
107
+
-`Cloud`: Region specific infrequently changing things such as VPC, Region-specific Certificates, etc
107
108
-`Platform`: DynamoDB, Cache, SQS
108
109
-`Services`: Lambdas, API Gateway, etc
109
110
110
-
This split is based on the frequency something changes, and allows us to deploy freqeuently changing stacks without having to also look at things that very rarely change. In this part of the series we will set up the `Cloud` stack.
111
+
This split is based on the frequency something changes, and allows us to deploy freqeuently changing stacks without having to also look at things that very rarely change. In this part of the series we will set up the `Global` stack.
111
112
112
113
As you can see in the [GitHub repository](https://github.com/codetalkio/the-stack/tree/part-2-automatic-deployments), we structure our CDK stack as follows:
113
114
@@ -116,45 +117,47 @@ As you can see in the [GitHub repository](https://github.com/codetalkio/the-stac
116
117
-`deployment.ts`: Our "executable" that CDK run run (defined in `cdk.json`)
117
118
-`helpers.ts`: Helper functions to make our CDK code more readable and safe to run
118
119
-`lib/`: The actual logic of our CDK stacks
119
-
-`cloud/`: Our 'Cloud' layer containing all the resources that are shared across all stacks
120
-
-`stack.ts`: Gathers all of our 'Cloud' stacks into one stack
120
+
-`global/`: Our 'Global' layer containing all the resources that are shared across all stacks
121
+
-`stack.ts`: Gathers all of our 'Global' stacks into one stack
121
122
-`domain.ts`: Sets up our Hosted Zone and ACM certificates
122
123
123
124
This might seem like overkill right now, but will benefit us quite quickly as we start adding more stacks to our project.
124
125
125
-
In `deployment.ts` you'll see the root of our CDK stack. This is where we will define the three layers we mentioned earlier, `Cloud`, `Platform`, and `Services`. In CDK terminilogy these are called `Stack`s.
126
+
In `deployment.ts` you'll see the root of our CDK stack. This is where we will define the three layers we mentioned earlier, `Global`, `Cloud`, `Platform`, and `Services`. In CDK terminilogy these are called `Stack`s.
126
127
127
-
For now, we will only define the `Cloud` layer:
128
+
For now, we will only define the `Global` layer:
128
129
129
130
```typescript
130
131
// ...imports
131
132
const app =newcdk.App();
132
133
133
134
/**
134
-
* Define our 'Cloud' stack that provisions the infrastructure for our application, such
135
-
* as domain names, certificates, and other resources that are shared across all.
135
+
* Define our 'Global' stack that provisions the infrastructure for our application, such
136
+
* as domain names, certificates, and other resources that are shared across all regions.
136
137
*
137
138
* ```bash
138
-
* bun run cdk deploy --concurrency 4 'Cloud' 'Cloud/**'
139
+
* bun run cdk deploy --concurrency 6 'Global/**'
139
140
* ```
140
141
*/
141
-
const cloudStackName ="Cloud";
142
-
if (matchesStack(app, cloudStackName)) {
143
-
newCloudStack(app, cloudStackName, {
142
+
const globalStackName ="Global";
143
+
if (matchesStack(app, globalStackName)) {
144
+
// Some of our global resources need to live in us-east-1 (e.g. CloudFront certificates),
145
+
// so we set that as the region for all global resources.
We've set up some conveniences to easily run a single stack, via `matchesStack`, and to validate our environment variables, via `validateEnv`.
154
157
155
-
Our `CloudStack` is then defined in `lib/cloud/stack.ts`, and more or less just pieces together the types and the sub-stacks in the `cloud/` directory.
158
+
Our `GlobalStack` is then defined in `lib/global/stack.ts`, and more or less just pieces together the types and the sub-stacks in the `global/` directory.
156
159
157
-
The interesting bit here is the call to `new domain.Stack` which is what actually kicks off the provisioning of resources, which are defined inside the `lib/cloud/domain.ts` file on layer deeper:
160
+
The interesting bit here is the call to `new domain.Stack` which is what actually kicks off the provisioning of resources, which are defined inside the `lib/global/domain.ts` file on layer deeper:
158
161
159
162
```typescript
160
163
// ...imports
@@ -170,7 +173,7 @@ export class Stack extends cdk.Stack {
170
173
}
171
174
```
172
175
173
-
And finally we get to the interesting part of it all in `lib/cloud/domain.ts`. This is the first place we are actually defining resources that will be deployed to AWS, by calling the CDK `Construct`s that are available to us. `Construct` is the CDK terminology for the actual resources we create, i.e. our building blocks.
176
+
And finally we get to the interesting part of it all in `lib/global/domain.ts`. This is the first place we are actually defining resources that will be deployed to AWS, by calling the CDK `Construct`s that are available to us. `Construct` is the CDK terminology for the actual resources we create, i.e. our building blocks.
174
177
175
178
We create our Hosted Zone via `new route53.HostedZone` and our ACM certificate via `new acm.Certificate`. You can find out more about each of these in the CDK docs:
176
179
@@ -646,7 +649,7 @@ _setup-deployment:
646
649
cd deployment
647
650
bun install
648
651
649
-
# Deploy the specified <stack>, e.g. `just deploy Cloud`, defaulting to --all.
652
+
# Deploy the specified <stack>, e.g. `just deploy 'Global/**'`, defaulting to --all.
0 commit comments