@aws/nx-plugin 0.1.6 → 0.2.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/LICENSE-THIRD-PARTY +114 -244
- package/generators.json +1 -7
- package/package.json +1 -1
- package/src/cloudscape-website/app/README.md +84 -48
- package/src/cloudscape-website/app/__snapshots__/generator.spec.ts.snap +157 -218
- package/src/cloudscape-website/app/files/app/README.md.template +44 -0
- package/src/cloudscape-website/app/files/app/src/layouts/App/index.tsx.template +40 -43
- package/src/cloudscape-website/app/files/app/src/layouts/App/navitems.ts.template +3 -3
- package/src/cloudscape-website/app/files/app/src/layouts/Routes/index.tsx.template +4 -6
- package/src/cloudscape-website/app/files/app/src/main.tsx.template +7 -10
- package/src/cloudscape-website/app/files/app/src/pages/Home/index.tsx.template +0 -2
- package/src/cloudscape-website/app/files/common/constructs/src/app/static-websites/__websiteNameKebabCase__.ts.template +13 -0
- package/src/cloudscape-website/app/files/common/constructs/src/{__websiteNameKebabCase__ → core}/static-website.ts.template +74 -144
- package/src/cloudscape-website/app/generator.js +74 -64
- package/src/cloudscape-website/app/generator.js.map +1 -1
- package/src/cloudscape-website/app/schema.d.ts +3 -4
- package/src/cloudscape-website/app/schema.json +1 -24
- package/src/cloudscape-website/cognito-auth/README.md +53 -32
- package/src/cloudscape-website/cognito-auth/__snapshots__/generator.spec.ts.snap +161 -125
- package/src/cloudscape-website/cognito-auth/files/app/components/CognitoAuth/index.tsx.template +53 -39
- package/src/cloudscape-website/cognito-auth/files/common/constructs/src/core/user-identity.ts.template +168 -0
- package/src/cloudscape-website/cognito-auth/generator.js +129 -46
- package/src/cloudscape-website/cognito-auth/generator.js.map +1 -1
- package/src/cloudscape-website/cognito-auth/schema.d.ts +1 -0
- package/src/cloudscape-website/cognito-auth/schema.json +7 -1
- package/src/cloudscape-website/runtime-config/__snapshots__/generator.spec.ts.snap +15 -17
- package/src/cloudscape-website/runtime-config/files/app/components/RuntimeConfig/index.tsx.template +7 -10
- package/src/cloudscape-website/runtime-config/files/app/hooks/useRuntimeConfig.tsx.template +13 -0
- package/src/cloudscape-website/runtime-config/generator.js +3 -1
- package/src/cloudscape-website/runtime-config/generator.js.map +1 -1
- package/src/infra/app/README.md +71 -46
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +114 -252
- package/src/infra/app/files/app/README.md.template +76 -0
- package/src/infra/app/files/app/src/main.ts.template +18 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/aws-prototyping.guard +1282 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/cfn-nag.guard +6839 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/hipaa-security.guard +2807 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/nist-csf.guard +2585 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/pci-dss-3-2-1.guard +2236 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/wa-reliability-pillar.guard +885 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/wa-security-pillar.guard +2205 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard.ts.template +63 -0
- package/src/infra/app/generator.js +17 -3
- package/src/infra/app/generator.js.map +1 -1
- package/src/infra/app/schema.d.ts +10 -1
- package/src/infra/app/schema.json +16 -8
- package/src/trpc/backend/README.md +102 -80
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +37 -17
- package/src/trpc/backend/files/backend/README.md.template +33 -0
- package/src/trpc/backend/files/common/constructs/src/app/trpc-apis/__apiNameKebabCase__.ts.template +18 -0
- package/src/trpc/backend/files/common/constructs/src/{__apiNameKebabCase__/index.ts.template → core/trpc-api.ts.template} +12 -16
- package/src/trpc/backend/files/schema/README.md.template +33 -0
- package/src/trpc/backend/generator.js +29 -43
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/backend/schema.d.ts +3 -1
- package/src/trpc/backend/schema.json +8 -13
- package/src/trpc/react/README.md +46 -66
- package/src/trpc/react/__snapshots__/generator.spec.ts.snap +104 -65
- package/src/trpc/react/files/src/components/TrpcClients/IsolatedTrpcProvider.tsx.template +75 -0
- package/src/trpc/react/files/src/components/TrpcClients/TrpcApis.tsx.template +1 -0
- package/src/trpc/react/files/src/components/TrpcClients/TrpcClientProviders.tsx.template +10 -0
- package/src/trpc/react/files/src/components/TrpcClients/index.tsx.template +5 -0
- package/src/trpc/react/files/src/hooks/useSigV4.tsx.template +38 -0
- package/src/trpc/react/files/src/hooks/use__apiNameClassName__.tsx.template +3 -0
- package/src/trpc/react/generator.js +123 -24
- package/src/trpc/react/generator.js.map +1 -1
- package/src/trpc/react/schema.json +2 -2
- package/src/ts/cjs-to-esm/generator.js.map +1 -1
- package/src/ts/lib/eslint.d.ts +1 -1
- package/src/ts/lib/eslint.js +59 -11
- package/src/ts/lib/eslint.js.map +1 -1
- package/src/ts/lib/files/README.md.template +33 -0
- package/src/ts/lib/generator.js +11 -4
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/schema.d.ts +1 -3
- package/src/ts/lib/schema.json +2 -15
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/lib/vitest.js +14 -0
- package/src/ts/lib/vitest.js.map +1 -1
- package/src/utils/ast.d.ts +13 -0
- package/src/utils/ast.js +102 -0
- package/src/utils/ast.js.map +1 -0
- package/src/utils/files/common/constructs/src/app/index.ts.template +0 -0
- package/src/utils/files/common/constructs/src/{runtime-config → core}/runtime-config.ts.template +3 -5
- package/src/utils/files/common/constructs/src/index.ts.template +2 -1
- package/src/utils/files/common/readme/README.md.template +33 -0
- package/src/utils/files/common/types/src/runtime-config.ts.template +1 -13
- package/src/utils/format.js.map +1 -1
- package/src/utils/names.d.ts +2 -0
- package/src/utils/names.js +27 -0
- package/src/utils/names.js.map +1 -0
- package/src/utils/npm-scope.js.map +1 -1
- package/src/utils/paths.js.map +1 -1
- package/src/utils/shared-constructs.js +37 -4
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/versions.d.ts +15 -9
- package/src/utils/versions.js +14 -8
- package/src/utils/versions.js.map +1 -1
- package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/cloudfront-web-acl.ts.template +0 -317
- package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/index.ts.template +0 -4
- package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/webacl_event_handler/index.ts.template +0 -301
- package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/index.ts.template +0 -4
- package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/user-identity.ts.template +0 -66
- package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/userpool-with-mfa.ts.template +0 -70
- package/src/gitlab/generator.d.ts +0 -8
- package/src/gitlab/generator.js +0 -16
- package/src/gitlab/generator.js.map +0 -1
- package/src/gitlab/schema.d.ts +0 -9
- package/src/gitlab/schema.json +0 -52
- package/src/infra/app/files/src/main.ts.template +0 -37
- package/src/trpc/react/files/src/components/TRPCClientProvider/index.tsx.template +0 -34
- package/src/trpc/react/files/src/hooks/useTrpc.tsx.template +0 -5
- /package/src/infra/app/files/{cdk.json → app/cdk.json} +0 -0
- /package/src/infra/app/files/{src → app/src}/stacks/application-stack.ts.template +0 -0
- /package/src/utils/files/common/constructs/src/{runtime-config → core}/index.ts.template +0 -0
package/src/infra/app/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Infrastructure App Generator
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
This generator creates a new AWS CDK infrastructure application. The generated application includes security best practices through CFN guard checks. The codebase is structured using TypeScript and ES Modules (ESM) for modern development practices.
|
|
5
6
|
|
|
6
7
|
## Usage
|
|
7
8
|
|
|
@@ -10,12 +11,14 @@ You can generate a new infrastructure application in two ways:
|
|
|
10
11
|
### 1. Using VSCode IDE
|
|
11
12
|
|
|
12
13
|
First, install the NX Console extension for VSCode:
|
|
14
|
+
|
|
13
15
|
1. Open VSCode
|
|
14
16
|
2. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
|
|
15
17
|
3. Search for "Nx Console"
|
|
16
18
|
4. Install [Nx Console](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console)
|
|
17
19
|
|
|
18
20
|
Then generate your application:
|
|
21
|
+
|
|
19
22
|
1. Open the NX Console in VSCode
|
|
20
23
|
2. Click on "Generate"
|
|
21
24
|
3. Search for "infra#app"
|
|
@@ -25,33 +28,38 @@ Then generate your application:
|
|
|
25
28
|
### 2. Using CLI
|
|
26
29
|
|
|
27
30
|
Generate the application:
|
|
31
|
+
|
|
28
32
|
```bash
|
|
29
33
|
nx g @aws/nx-plugin:infra#app my-infra --directory=apps/infrastructure
|
|
30
34
|
```
|
|
31
35
|
|
|
32
36
|
You can also perform a dry-run to see what files would be generated without actually creating them:
|
|
37
|
+
|
|
33
38
|
```bash
|
|
34
39
|
nx g @aws/nx-plugin:infra#app my-infra --directory=apps/infrastructure --dry-run
|
|
35
40
|
```
|
|
36
41
|
|
|
37
42
|
## Input Parameters
|
|
38
43
|
|
|
39
|
-
| Parameter
|
|
40
|
-
|
|
41
|
-
| name
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
+
| Parameter | Type | Default | Description |
|
|
45
|
+
| -------------- | ------ | --------------- | ---------------------------------------------------------------------------------------- |
|
|
46
|
+
| name\* | string | - | The name of the application (required). Must start with a letter and not contain colons. |
|
|
47
|
+
| ruleSet\* | string | aws_prototyping | cfn guard ruleset to use |
|
|
48
|
+
| directory | string | "packages" | The directory to store the application in. |
|
|
49
|
+
| unitTestRunner | string | "vitest" | Test runner for unit tests. Options: jest, vitest, none |
|
|
44
50
|
|
|
45
|
-
|
|
51
|
+
\*Required parameter
|
|
46
52
|
|
|
47
53
|
## Expected Output
|
|
48
54
|
|
|
49
|
-
The generator creates
|
|
55
|
+
The generator creates two main components:
|
|
56
|
+
|
|
57
|
+
### 1. Infra app code
|
|
50
58
|
|
|
51
59
|
```
|
|
52
60
|
<directory>/<name>/
|
|
53
61
|
├── src/
|
|
54
|
-
│
|
|
62
|
+
│ └── main.ts # Application entry point with CDK and PDK setup
|
|
55
63
|
│ └── stacks/ # CDK stack definitions
|
|
56
64
|
│ └── application-stack.ts # Main application stack
|
|
57
65
|
├── cdk.json # CDK configuration
|
|
@@ -59,12 +67,24 @@ The generator creates an infrastructure application with the following structure
|
|
|
59
67
|
└── project.json # Project configuration and build targets
|
|
60
68
|
```
|
|
61
69
|
|
|
70
|
+
### 2. Infra library code
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
common/constructs
|
|
74
|
+
└── src
|
|
75
|
+
└── core
|
|
76
|
+
└── cfn-guard.ts # Provides a wrapper around @cdklabs/cdk-validator-cfnguard along with a suppressRule function
|
|
77
|
+
└── cfn-guard-rules
|
|
78
|
+
└── *.guard # cfn guard ruleset definitions
|
|
79
|
+
```
|
|
80
|
+
|
|
62
81
|
Additionally, it:
|
|
82
|
+
|
|
63
83
|
1. Configures build settings for CDK synthesis and deployment
|
|
64
84
|
2. Installs required dependencies:
|
|
65
|
-
- @aws/pdk
|
|
66
85
|
- aws-cdk-lib
|
|
67
86
|
- aws-cdk
|
|
87
|
+
- @cdklabs/cdk-validator-cfnguard
|
|
68
88
|
- constructs
|
|
69
89
|
- esbuild
|
|
70
90
|
- source-map-support
|
|
@@ -72,42 +92,24 @@ Additionally, it:
|
|
|
72
92
|
|
|
73
93
|
## Features
|
|
74
94
|
|
|
75
|
-
### 1.
|
|
76
|
-
The generated application includes PDK (Project Development Kit) integration which provides:
|
|
77
|
-
- Security best practices through PDK Nag checks
|
|
78
|
-
- Infrastructure visualization with CDK Graph
|
|
79
|
-
- Threat modeling capabilities through Threat Composer
|
|
95
|
+
### 1. Cfn Guard integration
|
|
80
96
|
|
|
81
|
-
|
|
82
|
-
The application automatically generates infrastructure diagrams using CDK Graph:
|
|
83
|
-
```typescript
|
|
84
|
-
const graph = new CdkGraph(app, {
|
|
85
|
-
plugins: [
|
|
86
|
-
new CdkGraphDiagramPlugin({
|
|
87
|
-
defaults: {
|
|
88
|
-
filterPlan: {
|
|
89
|
-
preset: FilterPreset.COMPACT,
|
|
90
|
-
filters: [{ store: Filters.pruneCustomResources() }],
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
}),
|
|
94
|
-
new CdkGraphThreatComposerPlugin(),
|
|
95
|
-
],
|
|
96
|
-
});
|
|
97
|
-
```
|
|
97
|
+
The generated application includes Cfn guard integration which ensures security best practices via automated policy checks.
|
|
98
98
|
|
|
99
|
-
### 3. Security Checks
|
|
100
|
-
PDK Nag is configured with AWS Prototyping Checks to ensure infrastructure security:
|
|
101
99
|
```typescript
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
import { CfnGuardValidator, RuleSet } from ':e2e-test/common-constructs';
|
|
101
|
+
|
|
102
|
+
const app = new App({
|
|
103
|
+
policyValidationBeta1: [new CfnGuardValidator(RuleSet.AWS_PROTOTYPING)],
|
|
104
104
|
});
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
###
|
|
107
|
+
### 2. Build and Deploy Targets
|
|
108
|
+
|
|
108
109
|
The generator configures two main targets in your project.json:
|
|
109
110
|
|
|
110
111
|
1. **Build Target**
|
|
112
|
+
|
|
111
113
|
- Synthesizes CDK templates
|
|
112
114
|
- Caches results for faster subsequent builds
|
|
113
115
|
- Outputs to `dist/<directory>/cdk.out`
|
|
@@ -126,19 +128,17 @@ Add AWS resources to your stack in `src/stacks/application-stack.ts`:
|
|
|
126
128
|
```typescript
|
|
127
129
|
import * as cdk from 'aws-cdk-lib';
|
|
128
130
|
import { Construct } from 'constructs';
|
|
129
|
-
|
|
130
|
-
import {
|
|
131
|
+
/* Replace MyWebsite and MyApi with whatever you called them */
|
|
132
|
+
import { UserIdentity, MyWebsite, MyApi } from ':my-org/common-constructs';
|
|
131
133
|
|
|
132
134
|
export class ApplicationStack extends cdk.Stack {
|
|
133
135
|
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
|
|
134
136
|
super(scope, id, props);
|
|
135
137
|
|
|
136
138
|
const identity = new UserIdentity(this, 'UserIdentity');
|
|
137
|
-
const myapi = new MyApi(this, 'MyApi'
|
|
138
|
-
defaultAuthorizer: new HttpIamAuthorizer(),
|
|
139
|
-
});
|
|
139
|
+
const myapi = new MyApi(this, 'MyApi');
|
|
140
140
|
myapi.grantInvokeAccess(identity.identityPool.authenticatedRole);
|
|
141
|
-
new
|
|
141
|
+
new MyWebsite(this, 'Website');
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
```
|
|
@@ -148,14 +148,15 @@ The generated code serves as a starting point that you can adapt to your specifi
|
|
|
148
148
|
### Building the Application
|
|
149
149
|
|
|
150
150
|
To create a production build:
|
|
151
|
+
|
|
151
152
|
```bash
|
|
152
153
|
nx build my-infra
|
|
153
154
|
```
|
|
154
155
|
|
|
155
156
|
All built code is located in the `dist` folder at the root of your workspace. For example, if your infrastructure application is in `apps/infrastructure/my-infra`, the built code will be in `dist/apps/infrastructure/my-infra`. This includes:
|
|
157
|
+
|
|
156
158
|
- Compiled TypeScript files
|
|
157
159
|
- CDK synthesized templates in `dist/apps/infrastructure/my-infra/cdk.out`
|
|
158
|
-
- Generated infrastructure diagrams
|
|
159
160
|
- Source maps for debugging
|
|
160
161
|
|
|
161
162
|
### Deploying to AWS
|
|
@@ -163,7 +164,7 @@ All built code is located in the `dist` folder at the root of your workspace. Fo
|
|
|
163
164
|
To deploy your infrastructure:
|
|
164
165
|
|
|
165
166
|
```bash
|
|
166
|
-
nx deploy my-infra
|
|
167
|
+
nx deploy my-infra --all
|
|
167
168
|
```
|
|
168
169
|
|
|
169
170
|
This command will deploy your infrastructure to AWS using the account and region configured in your AWS CLI.
|
|
@@ -172,4 +173,28 @@ You can also perform a hotswap deployment if you are only making modifications t
|
|
|
172
173
|
|
|
173
174
|
```bash
|
|
174
175
|
nx deploy my-infra --hotswap
|
|
175
|
-
```
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Cfn Guard Suppressions
|
|
179
|
+
|
|
180
|
+
There may be instances where you want to suppress certain rules on resources. You can do this in two ways:
|
|
181
|
+
|
|
182
|
+
#### Supress a rule on a given construct
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { suppressRule } from ':my-org/common-constructs';
|
|
186
|
+
|
|
187
|
+
...
|
|
188
|
+
// suppresses the RULE_NAME for the given construct.
|
|
189
|
+
suppressRule(construct, 'RULE_NAME');
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
#### Supress a rule on a descendant construct
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { suppressRule } from ':my-org/common-constructs';
|
|
196
|
+
|
|
197
|
+
...
|
|
198
|
+
// Supresses the RULE_NAME for the construct or any of its descendants if it is an instance of Bucket
|
|
199
|
+
suppressRule(construct, 'RULE_NAME', (construct) => construct instanceof Bucket);
|
|
200
|
+
```
|