@aws/nx-plugin-mcp 0.119.0 → 0.121.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/aws-nx-mcp.js +23 -35
- package/docs/guides/astro-docs.mdx +142 -0
- package/docs/guides/connection/py-agent-a2a.mdx +105 -0
- package/docs/guides/connection/py-agent-mcp.mdx +147 -0
- package/docs/guides/connection/react-agui.mdx +240 -0
- package/docs/guides/connection/react-fastapi.mdx +1476 -0
- package/docs/guides/connection/react-py-agent.mdx +198 -0
- package/docs/guides/connection/react-smithy.mdx +1355 -0
- package/docs/guides/connection/react-trpc.mdx +447 -0
- package/docs/guides/connection/react-ts-agent.mdx +198 -0
- package/docs/guides/connection/smithy-rdb.mdx +161 -0
- package/docs/guides/connection/trpc-rdb.mdx +127 -0
- package/docs/guides/connection/ts-agent-a2a.mdx +106 -0
- package/docs/guides/connection/ts-agent-mcp.mdx +144 -0
- package/docs/guides/connection/ts-agent-rdb.mdx +141 -0
- package/docs/guides/connection/ts-mcp-server-rdb.mdx +135 -0
- package/docs/guides/connection.mdx +126 -0
- package/docs/guides/docker-bundling.mdx +403 -0
- package/docs/guides/fastapi.mdx +509 -0
- package/docs/guides/license.mdx +293 -0
- package/docs/guides/nx-generator.mdx +588 -0
- package/docs/guides/py-agent.mdx +483 -0
- package/docs/guides/py-mcp-server.mdx +161 -0
- package/docs/guides/python-lambda-function.mdx +207 -0
- package/docs/guides/python-project.mdx +228 -0
- package/docs/guides/react-website-auth.mdx +216 -0
- package/docs/guides/react-website.mdx +421 -0
- package/docs/guides/runtime-config.mdx +312 -0
- package/docs/guides/terraform-project.mdx +317 -0
- package/docs/guides/trpc.mdx +816 -0
- package/docs/guides/ts-agent.mdx +436 -0
- package/docs/guides/ts-lambda-function.mdx +218 -0
- package/docs/guides/ts-mcp-server.mdx +169 -0
- package/docs/guides/ts-nx-plugin.mdx +159 -0
- package/docs/guides/ts-rdb.mdx +759 -0
- package/docs/guides/ts-smithy-api.mdx +661 -0
- package/docs/guides/typescript-infrastructure.mdx +408 -0
- package/docs/guides/typescript-project.mdx +312 -0
- package/docs/guides/workspace.mdx +181 -0
- package/docs/snippets/agent/architecture.mdx +72 -0
- package/docs/snippets/agent/bedrock-deployment.mdx +172 -0
- package/docs/snippets/agent/runtime-arn.mdx +64 -0
- package/docs/snippets/api/api-architecture.mdx +93 -0
- package/docs/snippets/api/api-choice-note.mdx +6 -0
- package/docs/snippets/api/cors-configuration-cdk-note.mdx +25 -0
- package/docs/snippets/api/cors-configuration-terraform-note.mdx +28 -0
- package/docs/snippets/api/shared-constructs.mdx +38 -0
- package/docs/snippets/api/type-safe-api-integrations.mdx +643 -0
- package/docs/snippets/api/waf-configuration.mdx +37 -0
- package/docs/snippets/connection/a2a-infrastructure.mdx +63 -0
- package/docs/snippets/connection/lambda-rdb-ssl-requirements.mdx +40 -0
- package/docs/snippets/connection/mcp-server-rdb-ssl-requirements.mdx +35 -0
- package/docs/snippets/connection/rdb-api-infrastructure.mdx +72 -0
- package/docs/snippets/connection/react-agent-infrastructure.mdx +61 -0
- package/docs/snippets/connection/strands-agent-rdb-ssl-requirements.mdx +35 -0
- package/docs/snippets/lambda-function/architecture.mdx +36 -0
- package/docs/snippets/lambda-function/deploying-your-function.mdx +118 -0
- package/docs/snippets/mcp/architecture.mdx +58 -0
- package/docs/snippets/mcp/assistant-docs.mdx +10 -0
- package/docs/snippets/mcp/bedrock-deployment.mdx +167 -0
- package/docs/snippets/mcp/config.mdx +13 -0
- package/docs/snippets/mcp/configuration-py.mdx +42 -0
- package/docs/snippets/mcp/configuration-ts.mdx +53 -0
- package/docs/snippets/mcp/observability.mdx +8 -0
- package/docs/snippets/mcp/shared-constructs.mdx +32 -0
- package/docs/snippets/pdk-migration/example/01-migrate-api.mdx +602 -0
- package/docs/snippets/pdk-migration/example/02-migrate-website.mdx +915 -0
- package/docs/snippets/pdk-migration/example/03-migrate-infra.mdx +161 -0
- package/docs/snippets/pdk-migration/example/04-deploy.mdx +229 -0
- package/docs/snippets/pdk-migration/faq/aws-arch.mdx +17 -0
- package/docs/snippets/pdk-migration/faq/cdk-graph.mdx +29 -0
- package/docs/snippets/pdk-migration/faq/infrastructure-python-java.mdx +19 -0
- package/docs/snippets/pdk-migration/faq/pdk-nag.mdx +15 -0
- package/docs/snippets/pdk-migration/faq/pipeline.mdx +15 -0
- package/docs/snippets/pdk-migration/faq/type-safe-api.mdx +310 -0
- package/docs/snippets/pdk-migration/faq/use-of-projen.mdx +15 -0
- package/docs/snippets/prerequisites.mdx +20 -0
- package/docs/snippets/required-prerequisites.mdx +12 -0
- package/docs/snippets/shared-constructs.mdx +40 -0
- package/docs/snippets/tools/acurl.mdx +73 -0
- package/docs/snippets/ts-bundle.mdx +14 -0
- package/package.json +1 -1
- package/src/py/agent/schema.json +1 -1
- package/src/py/fast-api/schema.json +2 -2
- package/src/py/mcp-server/schema.json +1 -1
- package/src/smithy/ts/api/schema.json +2 -2
- package/src/trpc/backend/schema.json +2 -2
- package/src/ts/agent/schema.json +1 -1
- package/src/ts/mcp-server/schema.json +1 -1
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: CDK Infrastructure
|
|
3
|
+
description: Reference documentation for CDK Infrastructure
|
|
4
|
+
generator: ts#infra
|
|
5
|
+
---
|
|
6
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
7
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
8
|
+
import Link from '@components/link.astro';
|
|
9
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
10
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
11
|
+
|
|
12
|
+
[AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/home.html) is a framework for defining cloud infrastructure in code and provisioning it through AWS CloudFormation.
|
|
13
|
+
|
|
14
|
+
The TypeScript infrastructure generator creates an AWS CDK infrastructure application written in TypeScript. The generated application includes security best practices through [Checkov](https://www.checkov.io/) security checks.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Generate an Infrastructure Project
|
|
19
|
+
|
|
20
|
+
You can generate a new infrastructure project in two ways:
|
|
21
|
+
|
|
22
|
+
<RunGenerator generator="ts#infra" />
|
|
23
|
+
|
|
24
|
+
### Options
|
|
25
|
+
|
|
26
|
+
<GeneratorParameters generator="ts#infra" />
|
|
27
|
+
|
|
28
|
+
## Generator Output
|
|
29
|
+
|
|
30
|
+
The generator will create the following project structure in the `<directory>/<name>` directory:
|
|
31
|
+
|
|
32
|
+
<FileTree>
|
|
33
|
+
|
|
34
|
+
- src
|
|
35
|
+
- main.ts Application entry point instantiating CDK stages to deploy
|
|
36
|
+
- stages CDK Stage definitions
|
|
37
|
+
- application-stage.ts Defines a collection of stacks to deploy in a stage
|
|
38
|
+
- stacks CDK Stack definitions
|
|
39
|
+
- application-stack.ts Main application stack
|
|
40
|
+
- cdk.json CDK configuration
|
|
41
|
+
- project.json Project configuration and build targets
|
|
42
|
+
- checkov.yml Checkov configuration file
|
|
43
|
+
|
|
44
|
+
</FileTree>
|
|
45
|
+
|
|
46
|
+
If you set the `enableStageConfig` option, the generator also creates two shared packages for centralized credential management (if they don't already exist):
|
|
47
|
+
|
|
48
|
+
<FileTree>
|
|
49
|
+
|
|
50
|
+
- packages/common
|
|
51
|
+
- infra-config Stage configuration types and credential mappings
|
|
52
|
+
- src
|
|
53
|
+
- stages.types.ts Type definitions for stage credentials and config
|
|
54
|
+
- stages.config.ts Your stage-to-credential mappings (edit this)
|
|
55
|
+
- index.ts Re-exports for importing from other packages
|
|
56
|
+
- scripts Centralized deploy/destroy scripts
|
|
57
|
+
- src
|
|
58
|
+
- infra-deploy.ts Deploy bin script
|
|
59
|
+
- infra-destroy.ts Destroy bin script
|
|
60
|
+
- stage-credentials/ Shared logic (credential lookup, CDK command building)
|
|
61
|
+
|
|
62
|
+
</FileTree>
|
|
63
|
+
|
|
64
|
+
:::tip[TypeScript Project Features]
|
|
65
|
+
Your infrastructure is a TypeScript project, so you can refer to the <Link path="guides/typescript-project">TypeScript project documentation</Link> for more details about their general usage.
|
|
66
|
+
:::
|
|
67
|
+
|
|
68
|
+
## Implementing your CDK Infrastructure
|
|
69
|
+
|
|
70
|
+
You can start writing your CDK infrastructure inside `src/stacks/application-stack.ts`, for example:
|
|
71
|
+
|
|
72
|
+
```ts title="src/stacks/application-stack.ts" {9-10}
|
|
73
|
+
import { Stack, StackProps } from 'aws-cdk-lib';
|
|
74
|
+
import { Bucket } from 'aws-cdk-lib/aws-s3'
|
|
75
|
+
import { Construct } from 'constructs';
|
|
76
|
+
|
|
77
|
+
export class ApplicationStack extends Stack {
|
|
78
|
+
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
79
|
+
super(scope, id, props);
|
|
80
|
+
|
|
81
|
+
// Declare your infrastructure here
|
|
82
|
+
new Bucket(this, 'MyBucket');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Stages and Stacks
|
|
88
|
+
|
|
89
|
+
CDK uses [Stages](https://docs.aws.amazon.com/cdk/v2/guide/stages.html) to group stacks that should be deployed together to a specific environment. The generated `src/main.ts` creates a sandbox stage for your own development and testing:
|
|
90
|
+
|
|
91
|
+
```ts title="src/main.ts"
|
|
92
|
+
new ApplicationStage(app, 'my-app-sandbox', {
|
|
93
|
+
env: {
|
|
94
|
+
account: process.env.CDK_DEFAULT_ACCOUNT,
|
|
95
|
+
region: process.env.CDK_DEFAULT_REGION,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The `env` property tells CDK which AWS account and region to deploy to. `CDK_DEFAULT_ACCOUNT` and `CDK_DEFAULT_REGION` are resolved automatically by the CDK CLI from your active AWS credentials. See the [CDK environments documentation](https://docs.aws.amazon.com/cdk/v2/guide/environments.html) for more details.
|
|
101
|
+
|
|
102
|
+
If you generated with `enableStageConfig`, the `main.ts` reads account and region from a centralized config file instead, falling back to environment variables when no config is set:
|
|
103
|
+
|
|
104
|
+
```ts title="src/main.ts (with enableStageConfig)"
|
|
105
|
+
import stagesConfig from ':my-scope/common-infra-config';
|
|
106
|
+
|
|
107
|
+
const projectStages = stagesConfig.projects?.['packages/infra']?.stages ?? {};
|
|
108
|
+
const sandboxConfig = projectStages['my-app-sandbox'];
|
|
109
|
+
|
|
110
|
+
new ApplicationStage(app, 'my-app-sandbox', {
|
|
111
|
+
env: {
|
|
112
|
+
account: sandboxConfig?.account ?? process.env.CDK_DEFAULT_ACCOUNT,
|
|
113
|
+
region: sandboxConfig?.region ?? process.env.CDK_DEFAULT_REGION,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
You can add more stages to deploy to different environments. For example, `beta` and `prod` stages targeting separate AWS accounts:
|
|
119
|
+
|
|
120
|
+
```ts title="src/main.ts"
|
|
121
|
+
new ApplicationStage(app, 'project-beta', {
|
|
122
|
+
env: {
|
|
123
|
+
account: '123456789012',
|
|
124
|
+
region: 'us-west-2',
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
new ApplicationStage(app, 'project-prod', {
|
|
128
|
+
env: {
|
|
129
|
+
account: '098765432109',
|
|
130
|
+
region: 'us-west-2',
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
A Stage groups one or more stacks. You can add as many stacks as you need inside a stage:
|
|
136
|
+
|
|
137
|
+
```ts title="src/stages/application-stage.ts"
|
|
138
|
+
import { Stage, StageProps } from 'aws-cdk-lib';
|
|
139
|
+
import { Construct } from 'constructs';
|
|
140
|
+
import { BackendStack } from '../stacks/backend-stack.js';
|
|
141
|
+
import { FrontendStack } from '../stacks/frontend-stack.js';
|
|
142
|
+
|
|
143
|
+
export class ApplicationStage extends Stage {
|
|
144
|
+
constructor(scope: Construct, id: string, props?: StageProps) {
|
|
145
|
+
super(scope, id, props);
|
|
146
|
+
|
|
147
|
+
new BackendStack(this, 'Backend', {
|
|
148
|
+
crossRegionReferences: true,
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
new FrontendStack(this, 'Frontend', {
|
|
152
|
+
crossRegionReferences: true,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Stage Credential Configuration
|
|
159
|
+
|
|
160
|
+
:::note[Staged Configuration]
|
|
161
|
+
This section applies when you generate with `enableStageConfig`. Without it, the generator produces a simpler setup where you manage AWS credentials yourself (e.g., by exporting `AWS_PROFILE` before deploying).
|
|
162
|
+
:::
|
|
163
|
+
|
|
164
|
+
When you have multiple stages targeting different AWS accounts, managing credentials manually can be error-prone, especially as the number of stages grows.
|
|
165
|
+
|
|
166
|
+
The `enableStageConfig` option solves this by generating two shared packages:
|
|
167
|
+
|
|
168
|
+
- **`packages/common/infra-config`** — A single config file where you map each stage to its AWS credentials, account, and region. This is importable from any package in your workspace, so your CDK `main.ts` can read account and region from the same source of truth.
|
|
169
|
+
- **`packages/common/scripts`** — `infra-deploy` and `infra-destroy` commands that wrap CDK with automatic credential resolution. When you run `deploy`, the script reads the config, sets the right AWS environment variables for the CDK child process, and runs `cdk deploy`. Your shell environment is never modified.
|
|
170
|
+
|
|
171
|
+
#### Configuring Credentials
|
|
172
|
+
|
|
173
|
+
Edit `packages/common/infra-config/src/stages.config.ts` to map your stages to AWS credentials:
|
|
174
|
+
|
|
175
|
+
```ts title="packages/common/infra-config/src/stages.config.ts"
|
|
176
|
+
import type { StagesConfig } from './stages.types.js';
|
|
177
|
+
|
|
178
|
+
const config: StagesConfig = {
|
|
179
|
+
projects: {
|
|
180
|
+
// The key is the project path relative to the workspace root.
|
|
181
|
+
// This matches the path in project.json and in deploy commands.
|
|
182
|
+
'packages/infra': {
|
|
183
|
+
stages: {
|
|
184
|
+
// Stage names must match the CDK stage identifiers in main.ts
|
|
185
|
+
// (the first argument to `new ApplicationStage(app, 'my-app-dev', ...)`).
|
|
186
|
+
'my-app-dev': {
|
|
187
|
+
credentials: { type: 'profile', profile: 'dev-account' },
|
|
188
|
+
region: 'us-east-1',
|
|
189
|
+
},
|
|
190
|
+
'my-app-prod': {
|
|
191
|
+
credentials: {
|
|
192
|
+
type: 'assumeRole',
|
|
193
|
+
assumeRole: 'arn:aws:iam::123456789012:role/DeployRole',
|
|
194
|
+
},
|
|
195
|
+
region: 'us-west-2',
|
|
196
|
+
account: '123456789012',
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
shared: {
|
|
202
|
+
// Shared stages are available to all infra projects.
|
|
203
|
+
// Project-specific entries take priority over shared ones.
|
|
204
|
+
stages: {
|
|
205
|
+
sandbox: {
|
|
206
|
+
credentials: { type: 'profile', profile: 'personal-sandbox' },
|
|
207
|
+
region: 'us-east-1',
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export default config;
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
When you deploy, for example:
|
|
217
|
+
|
|
218
|
+
<NxCommands commands={['deploy infra my-app-dev/*']} />
|
|
219
|
+
|
|
220
|
+
The deploy script:
|
|
221
|
+
1. Extracts the stage name `my-app-dev` from the command arguments
|
|
222
|
+
2. Looks up credentials in the config: first under `projects['packages/infra']`, then under `shared`
|
|
223
|
+
3. If found, sets `AWS_PROFILE` (or assumes the IAM role) for the CDK child process only
|
|
224
|
+
4. If not found, falls back to whatever AWS credentials are in your environment
|
|
225
|
+
|
|
226
|
+
This means existing workflows without any config continue to work — the script only applies credentials when it finds a matching entry.
|
|
227
|
+
|
|
228
|
+
#### Credential Types
|
|
229
|
+
|
|
230
|
+
Two credential strategies are supported:
|
|
231
|
+
|
|
232
|
+
- **`profile`** — Uses a named [AWS CLI profile](https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-profiles.html) from `~/.aws/config`. The script sets `AWS_PROFILE` for the CDK process.
|
|
233
|
+
- **`assumeRole`** — Calls [STS AssumeRole](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) with the specified role ARN and passes the temporary credentials to CDK. You can optionally specify a `profile` as the source credentials for the AssumeRole call, an `externalId` for cross-account trust policies, and a `sessionDuration` in seconds.
|
|
234
|
+
|
|
235
|
+
#### Account and Region
|
|
236
|
+
|
|
237
|
+
Each stage config includes a required `region` and an optional `account`:
|
|
238
|
+
|
|
239
|
+
- **`region`** (required) — The AWS region to deploy to (e.g., `us-east-1`, `eu-west-2`).
|
|
240
|
+
- **`account`** (optional) — The AWS account ID. If omitted, CDK infers it from the active credentials at deploy time. See the [CDK environments documentation](https://docs.aws.amazon.com/cdk/v2/guide/environments.html) for how CDK resolves account and region.
|
|
241
|
+
|
|
242
|
+
The generated `main.ts` reads these values from the config so that CDK synthesis and deployment use the same environment settings:
|
|
243
|
+
|
|
244
|
+
```ts title="src/main.ts"
|
|
245
|
+
const sandboxConfig = projectStages['my-app-sandbox'];
|
|
246
|
+
new ApplicationStage(app, 'my-app-sandbox', {
|
|
247
|
+
env: {
|
|
248
|
+
account: sandboxConfig?.account ?? process.env.CDK_DEFAULT_ACCOUNT,
|
|
249
|
+
region: sandboxConfig?.region ?? process.env.CDK_DEFAULT_REGION,
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
#### Shared vs Project-Specific Stages
|
|
255
|
+
|
|
256
|
+
Shared stages (under `shared.stages`) apply to any infra project in the workspace. This is useful when multiple projects deploy to the same sandbox account — you define the credentials once instead of repeating them for each project.
|
|
257
|
+
|
|
258
|
+
Project-specific stages (under `projects['packages/infra'].stages`) only apply to that project. When both exist for the same stage name, the project-specific entry takes priority.
|
|
259
|
+
|
|
260
|
+
:::tip[Commit Stage Config]
|
|
261
|
+
We recommend committing `stages.config.ts` so the team shares a single source of truth for stage credentials. If it contains personal profile names, you can add it to `.gitignore` and use a local override instead.
|
|
262
|
+
:::
|
|
263
|
+
|
|
264
|
+
### API Infrastructure
|
|
265
|
+
|
|
266
|
+
If you have used the <Link path="guides/trpc">tRPC API</Link> or <Link path="guides/fastapi">FastAPI</Link> generators to create APIs, you will notice you already have some constructs available in `packages/common/constructs` to deploy them.
|
|
267
|
+
|
|
268
|
+
If, for example, you created a tRPC API called `my-api`, you can simply import and instantiate the construct to add all necessary infrastructure to deploy it:
|
|
269
|
+
|
|
270
|
+
```ts title="src/stacks/application-stack.ts" {3, 9-12}
|
|
271
|
+
import { Stack, StackProps } from 'aws-cdk-lib';
|
|
272
|
+
import { Construct } from 'constructs';
|
|
273
|
+
import { MyApi } from ':my-scope/common-constructs';
|
|
274
|
+
|
|
275
|
+
export class ApplicationStack extends Stack {
|
|
276
|
+
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
277
|
+
super(scope, id, props);
|
|
278
|
+
|
|
279
|
+
// Add infrastructure for your API
|
|
280
|
+
new MyApi(this, 'MyApi', {
|
|
281
|
+
integrations: MyApi.defaultIntegrations(this).build(),
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Website Infrastructure
|
|
288
|
+
|
|
289
|
+
If you have used the <Link path="guides/react-website">CloudScape website</Link> generator, you will notice you already have a construct in `packages/common/constructs` to deploy it. For example:
|
|
290
|
+
|
|
291
|
+
```ts title="src/stacks/application-stack.ts" {3, 9-10}
|
|
292
|
+
import { Stack, StackProps } from 'aws-cdk-lib';
|
|
293
|
+
import { Construct } from 'constructs';
|
|
294
|
+
import { MyWebsite } from ':my-scope/common-constructs';
|
|
295
|
+
|
|
296
|
+
export class ApplicationStack extends Stack {
|
|
297
|
+
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
298
|
+
super(scope, id, props);
|
|
299
|
+
|
|
300
|
+
// Add infrastructure for your website
|
|
301
|
+
new MyWebsite(this, 'MyWebsite');
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
:::note[CDK Website Construct]
|
|
307
|
+
With CDK, the website construct can be declared at any point in your stack — runtime configuration is resolved lazily at synth time. For Terraform, ensure the website module has appropriate `depends_on` for modules that add to the <Link path="guides/react-website#runtime-configuration">Runtime Config</Link>.
|
|
308
|
+
:::
|
|
309
|
+
|
|
310
|
+
## Synthesizing your Infrastructure
|
|
311
|
+
|
|
312
|
+
As part of your `build` target, as well as running the <Link path="guides/typescript-project#building">default compile, lint and test targets</Link>, your infrastructure project is _synthesized_ to CloudFormation. This can also be executed in a standalone fashion, by running the `synth` target:
|
|
313
|
+
|
|
314
|
+
<NxCommands commands={['synth <my-infra>']} />
|
|
315
|
+
|
|
316
|
+
You will find your synthesized cloud assembly in the root `dist` folder, under `dist/packages/<my-infra-project>/cdk.out`.
|
|
317
|
+
|
|
318
|
+
## Security Testing
|
|
319
|
+
|
|
320
|
+
A `checkov` target is added to your project which runs security checks on your infrastructure using [Checkov](https://www.checkov.io/).
|
|
321
|
+
|
|
322
|
+
<NxCommands commands={['checkov <my-infra>']} />
|
|
323
|
+
|
|
324
|
+
You will find your security test results in the root `dist` folder, under `dist/packages/<my-infra-project>/checkov`.
|
|
325
|
+
|
|
326
|
+
:::note[Checkov via UV]
|
|
327
|
+
Checkov is run using `uvx`, so you will need to [install `uv` if you haven't already](https://docs.astral.sh/uv/getting-started/installation/).
|
|
328
|
+
:::
|
|
329
|
+
|
|
330
|
+
:::caution[Suppressed Checkov Rules]
|
|
331
|
+
Some Checkov rules are suppressed by default via the `checkov.yml` file. It is recommended that you review these based on your use case.
|
|
332
|
+
:::
|
|
333
|
+
|
|
334
|
+
### Suppressing Checkov Checks
|
|
335
|
+
|
|
336
|
+
There may be instances where you want to suppress certain rules on resources. You can do this in two ways:
|
|
337
|
+
|
|
338
|
+
#### Supress a rule on a given construct
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
import { suppressRules } from ':my-scope/common-constructs';
|
|
342
|
+
|
|
343
|
+
// suppresses the CKV_AWS_XXX for the given construct.
|
|
344
|
+
suppressRules(construct, ['CKV_AWS_XXX'], 'Reason');
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
#### Supress a rule on a descendant construct
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
import { suppressRules } from ':my-scope/common-constructs';
|
|
351
|
+
|
|
352
|
+
// Supresses the CKV_AWS_XXX for the construct or any of its descendants if it is an instance of Bucket
|
|
353
|
+
suppressRules(construct, ['CKV_AWS_XXX'], 'Reason', (construct) => construct instanceof Bucket);
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## Bootstrapping your AWS Account(s)
|
|
357
|
+
|
|
358
|
+
If you are deploying a CDK application to an AWS Account for the first time, it will need to be [bootstrapped](https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping-env.html). Bootstrapping creates the resources CDK needs to manage deployments (an S3 bucket for assets, IAM roles, etc.).
|
|
359
|
+
|
|
360
|
+
First, ensure that you have [configured credentials for your AWS account](https://docs.aws.amazon.com/sdkref/latest/guide/access.html).
|
|
361
|
+
|
|
362
|
+
Next, run the bootstrap command for each account and region you plan to deploy to:
|
|
363
|
+
|
|
364
|
+
```bash
|
|
365
|
+
npx cdk bootstrap aws://<account-id>/<region>
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
For more details, please refer to the [CDK bootstrapping documentation](https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping-env.html).
|
|
369
|
+
|
|
370
|
+
## Deploying to AWS
|
|
371
|
+
|
|
372
|
+
After a build, you can deploy your infrastructure to AWS using the `deploy` target.
|
|
373
|
+
|
|
374
|
+
:::caution[CI Deployment]
|
|
375
|
+
Use the `deploy-ci` target if deploying in a CI/CD pipeline. See below for more details.
|
|
376
|
+
:::
|
|
377
|
+
|
|
378
|
+
First, make sure you have AWS credentials configured. If you generated with `enableStageConfig` and have configured stage credentials in `packages/common/infra-config/src/stages.config.ts`, the deploy command will automatically resolve and apply the correct credentials for the target stage. Otherwise, ensure your AWS credentials are set in your environment (e.g., via `AWS_PROFILE` or environment variables). See the [AWS credentials documentation](https://docs.aws.amazon.com/sdkref/latest/guide/access.html) for the available options.
|
|
379
|
+
|
|
380
|
+
Then run the deploy target:
|
|
381
|
+
|
|
382
|
+
<NxCommands commands={['deploy <my-infra> <my-infra>-sandbox/*']} />
|
|
383
|
+
|
|
384
|
+
:::tip[Selective Stack Deployment]
|
|
385
|
+
The above command deploys _all_ stacks for the `<my-infra>-sandbox` stage. You can specify other stages so long as they are defined in `main.ts`.
|
|
386
|
+
|
|
387
|
+
You can also deploy individual stacks by specifying the full stack name, for example:
|
|
388
|
+
|
|
389
|
+
<NxCommands commands={['deploy <my-infra> <my-infra>-sandbox/Application']} />
|
|
390
|
+
:::
|
|
391
|
+
|
|
392
|
+
## Deploying to AWS in a CI/CD Pipeline
|
|
393
|
+
|
|
394
|
+
Use the `deploy-ci` target if you are deploying to AWS as part of a CI/CD pipeline.
|
|
395
|
+
|
|
396
|
+
<NxCommands commands={['deploy-ci <my-infra> my-stage/*']} />
|
|
397
|
+
|
|
398
|
+
This target differs slightly from the regular `deploy` target in that it deploys a pre-synthesized cloud assembly rather than synthesizing on the fly. This avoids potential non-determinism from package version changes, ensuring that every pipeline stage deploys using the same cloud assembly.
|
|
399
|
+
|
|
400
|
+
## Tearing Down AWS Infrastructure
|
|
401
|
+
|
|
402
|
+
Use the `destroy` target to tear down your resources:
|
|
403
|
+
|
|
404
|
+
<NxCommands commands={['destroy <my-infra> <my-infra>-sandbox/*']} />
|
|
405
|
+
|
|
406
|
+
## More Information
|
|
407
|
+
|
|
408
|
+
For more information about CDK, please refer to the [CDK Developer Guide](https://docs.aws.amazon.com/cdk/v2/guide/core_concepts.html) and [API Reference](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-construct-library.html).
|