@aligent/nx-cdk 0.0.1
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/README.md +130 -0
- package/generators.json +15 -0
- package/package.json +20 -0
- package/src/generators/helpers/configs/nxJson.d.ts +4 -0
- package/src/generators/helpers/configs/nxJson.js +52 -0
- package/src/generators/helpers/configs/packageJson.d.ts +61 -0
- package/src/generators/helpers/configs/packageJson.js +65 -0
- package/src/generators/helpers/configs/tsConfigs.d.ts +12 -0
- package/src/generators/helpers/configs/tsConfigs.js +40 -0
- package/src/generators/helpers/utilities.d.ts +82 -0
- package/src/generators/helpers/utilities.js +100 -0
- package/src/generators/preset/files/.editorconfig.template +18 -0
- package/src/generators/preset/files/.git-hooks/pre-push.template +68 -0
- package/src/generators/preset/files/.github/CODEOWNERS.template +3 -0
- package/src/generators/preset/files/.github/dependabot.yml.template +7 -0
- package/src/generators/preset/files/.github/workflows/ci-cd.yml.template +27 -0
- package/src/generators/preset/files/.gitignore.template +62 -0
- package/src/generators/preset/files/.nvmrc.template +1 -0
- package/src/generators/preset/files/.prettierignore.template +10 -0
- package/src/generators/preset/files/.yarnrc.yml.template +6 -0
- package/src/generators/preset/files/LICENSE.template +21 -0
- package/src/generators/preset/files/README.md.template +77 -0
- package/src/generators/preset/files/application/README.md.template +61 -0
- package/src/generators/preset/files/application/_internal/log-group-defaults-injector.ts.template +100 -0
- package/src/generators/preset/files/application/_internal/microservice-checks.ts.template +58 -0
- package/src/generators/preset/files/application/_internal/nodejs-function-defaults-injector.ts.template +110 -0
- package/src/generators/preset/files/application/_internal/step-function-defaults-injector.ts.template +126 -0
- package/src/generators/preset/files/application/_internal/version-functions-aspect.ts.template +74 -0
- package/src/generators/preset/files/application/bin/main.ts.template +72 -0
- package/src/generators/preset/files/application/cdk.context.json.template +4 -0
- package/src/generators/preset/files/application/cdk.json.template +92 -0
- package/src/generators/preset/files/application/eslint.config.mjs.template +3 -0
- package/src/generators/preset/files/application/lib/service-stacks.ts.template +21 -0
- package/src/generators/preset/files/application/package.json.template +27 -0
- package/src/generators/preset/files/cdk-config.yml.template +16 -0
- package/src/generators/preset/files/eslint.config.mjs.template +54 -0
- package/src/generators/preset/files/prettier.config.mjs.template +3 -0
- package/src/generators/preset/files/rolldown.config.base.mjs.template +46 -0
- package/src/generators/preset/files/tsconfig.json.template +6 -0
- package/src/generators/preset/files/vitest.config.base.mjs.template +39 -0
- package/src/generators/preset/files/vitest.global.setup.mjs.template +109 -0
- package/src/generators/preset/preset.d.ts +4 -0
- package/src/generators/preset/preset.js +35 -0
- package/src/generators/preset/schema.d.ts +7 -0
- package/src/generators/preset/schema.json +32 -0
- package/src/generators/service/files/README.md.template +29 -0
- package/src/generators/service/files/eslint.config.mjs.template +20 -0
- package/src/generators/service/files/package.json.template +32 -0
- package/src/generators/service/files/rolldown.config.mjs.template +3 -0
- package/src/generators/service/files/src/index.ts.template +75 -0
- package/src/generators/service/files/src/infra/.gitkeep.template +0 -0
- package/src/generators/service/files/src/runtime/handlers/.gitkeep.template +0 -0
- package/src/generators/service/files/src/runtime/lib/utils/.gitkeep.template +0 -0
- package/src/generators/service/files/tests/__data__/.gitkeep.template +0 -0
- package/src/generators/service/files/vitest.config.mjs.template +18 -0
- package/src/generators/service/generator.d.ts +4 -0
- package/src/generators/service/generator.js +43 -0
- package/src/generators/service/schema.d.ts +4 -0
- package/src/generators/service/schema.json +20 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +19 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { type InjectionContext, type IPropertyInjector } from 'aws-cdk-lib';
|
|
2
|
+
import { LogGroup } from 'aws-cdk-lib/aws-logs';
|
|
3
|
+
import {
|
|
4
|
+
LogLevel,
|
|
5
|
+
StateMachine,
|
|
6
|
+
StateMachineType,
|
|
7
|
+
type StateMachineProps,
|
|
8
|
+
} from 'aws-cdk-lib/aws-stepfunctions';
|
|
9
|
+
import type { Construct } from 'constructs';
|
|
10
|
+
|
|
11
|
+
type StepFunctionDefaults = Omit<StateMachineProps, 'definition' | 'definitionSubstitutions'>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Property injector for Step Functions with configuration-aware defaults
|
|
15
|
+
*
|
|
16
|
+
* Applies configuration-specific settings to Step Functions. All configurations enable
|
|
17
|
+
* X-Ray tracing by default for observability. For EXPRESS state machines, automatically
|
|
18
|
+
* creates log groups and configures comprehensive logging.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Apply configuration-specific defaults
|
|
23
|
+
* PropertyInjectors.of(scope).add(
|
|
24
|
+
* new StepFunctionDefaultsInjector('dev').withProps({
|
|
25
|
+
* timeout: Duration.minutes(30),
|
|
26
|
+
* })
|
|
27
|
+
* );
|
|
28
|
+
*
|
|
29
|
+
* // Step Functions automatically inherit defaults
|
|
30
|
+
* new StateMachine(stack, 'MyWorkflow', {
|
|
31
|
+
* stateMachineType: StateMachineType.EXPRESS,
|
|
32
|
+
* definitionBody: DefinitionBody.fromFile('workflow.asl.yaml'),
|
|
33
|
+
* // tracing enabled and logging configured automatically for EXPRESS
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.StateMachine.html
|
|
38
|
+
*/
|
|
39
|
+
export class StepFunctionDefaultsInjector implements IPropertyInjector {
|
|
40
|
+
public readonly constructUniqueId = StateMachine.PROPERTY_INJECTION_ID;
|
|
41
|
+
private readonly config: Record<string, never>;
|
|
42
|
+
private defaultProps: StateMachineProps;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new StepFunctionDefaultsInjector
|
|
46
|
+
*
|
|
47
|
+
* @param config - Configuration identifier (currently unused but maintained for consistency).
|
|
48
|
+
* All configurations enable tracing by default.
|
|
49
|
+
*/
|
|
50
|
+
constructor(config: Record<string, never> = {}) {
|
|
51
|
+
this.config = { ...config };
|
|
52
|
+
this.defaultProps = { tracingEnabled: true };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Creates a new injector instance with additional properties
|
|
57
|
+
*
|
|
58
|
+
* Returns a new injector that inherits the current configuration but includes
|
|
59
|
+
* additional properties that override the configuration defaults.
|
|
60
|
+
*
|
|
61
|
+
* @param props - Additional properties to merge with configuration defaults
|
|
62
|
+
* @returns A new injector instance with merged properties
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const customInjector = new StepFunctionDefaultsInjector('prod')
|
|
67
|
+
* .withProps({
|
|
68
|
+
* timeout: Duration.hours(1),
|
|
69
|
+
* stateMachineName: 'custom-workflow',
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
public withProps(props: StateMachineProps) {
|
|
74
|
+
const modifiedInjector = new StepFunctionDefaultsInjector(this.config);
|
|
75
|
+
modifiedInjector.defaultProps = { ...this.defaultProps, ...props };
|
|
76
|
+
return modifiedInjector;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Injects configuration-appropriate defaults into Step Function properties
|
|
81
|
+
*
|
|
82
|
+
* Enables X-Ray tracing for all state machines. For EXPRESS state machines,
|
|
83
|
+
* automatically creates log groups and configures comprehensive logging.
|
|
84
|
+
*
|
|
85
|
+
* @param originalProps - Properties provided when creating the state machine
|
|
86
|
+
* @param context - CDK injection context containing construct information
|
|
87
|
+
* @returns Merged properties with injected defaults and logging configuration
|
|
88
|
+
*/
|
|
89
|
+
public inject(originalProps: StateMachineProps, context: InjectionContext) {
|
|
90
|
+
// Prepare logging configuration for EXPRESS step functions
|
|
91
|
+
const logging = expressLogProperties(context.scope, context.id, originalProps);
|
|
92
|
+
return { ...this.defaultProps, ...originalProps, ...logging };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Build the logging configuration for an express step function, respecting
|
|
98
|
+
* existing logging configuration.
|
|
99
|
+
*
|
|
100
|
+
* @param machineScope - The scope of the step function.
|
|
101
|
+
* @param machineId - The id of the step function.
|
|
102
|
+
* @param props - The properties for the step function.
|
|
103
|
+
* @returns The logging configuration for an express step function
|
|
104
|
+
*/
|
|
105
|
+
function expressLogProperties(
|
|
106
|
+
machineScope: Construct,
|
|
107
|
+
machineId: string,
|
|
108
|
+
props: StepFunctionDefaults
|
|
109
|
+
) {
|
|
110
|
+
if (props.stateMachineType !== StateMachineType.EXPRESS) {
|
|
111
|
+
return {};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Create a new log group if one is not provided
|
|
115
|
+
const logGroup =
|
|
116
|
+
props.logs?.destination ?? new LogGroup(machineScope, `/aws/states/${machineId}`);
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
logs: {
|
|
120
|
+
destination: logGroup,
|
|
121
|
+
level: LogLevel.ALL,
|
|
122
|
+
includeExecutionData: true,
|
|
123
|
+
...props.logs,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
package/src/generators/preset/files/application/_internal/version-functions-aspect.ts.template
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { IAspect } from 'aws-cdk-lib';
|
|
2
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import {
|
|
4
|
+
CfnStateMachineAlias,
|
|
5
|
+
CfnStateMachineVersion,
|
|
6
|
+
StateMachine,
|
|
7
|
+
} from 'aws-cdk-lib/aws-stepfunctions';
|
|
8
|
+
import { IConstruct } from 'constructs';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Aspect that automatically adds versioning and aliases to Lambda and Step Functions
|
|
12
|
+
*
|
|
13
|
+
* Visits all constructs in the scope and automatically creates versions and aliases
|
|
14
|
+
* for supported resource types. This enables blue-green deployments, traffic shifting,
|
|
15
|
+
* and provides stable ARNs for external integrations.
|
|
16
|
+
*
|
|
17
|
+
* Currently supports:
|
|
18
|
+
* - Lambda Functions: Creates function aliases
|
|
19
|
+
* - Step Functions: Creates versions and aliases with 100% traffic routing
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Apply to entire app for automatic versioning
|
|
24
|
+
* Aspects.of(app).add(new VersionFunctionsAspect());
|
|
25
|
+
*
|
|
26
|
+
* // Or with custom alias name
|
|
27
|
+
* Aspects.of(app).add(new VersionFunctionsAspect({ alias: 'PROD' }));
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class VersionFunctionsAspect implements IAspect {
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new VersionFunctionsAspect
|
|
33
|
+
*
|
|
34
|
+
* @param props - Configuration for the aspect
|
|
35
|
+
* @param props.alias - Name for the alias to create. Defaults to 'LATEST'
|
|
36
|
+
*/
|
|
37
|
+
constructor(
|
|
38
|
+
private readonly props: {
|
|
39
|
+
alias: string;
|
|
40
|
+
} = {
|
|
41
|
+
alias: 'LATEST',
|
|
42
|
+
}
|
|
43
|
+
) {}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Visits a construct and applies versioning if it's a supported resource type
|
|
47
|
+
*
|
|
48
|
+
* For Lambda Functions: Adds a function alias pointing to $LATEST
|
|
49
|
+
* For Step Functions: Creates a version and alias with 100% traffic routing
|
|
50
|
+
*
|
|
51
|
+
* @param node - The construct to potentially add versioning to
|
|
52
|
+
*/
|
|
53
|
+
visit(node: IConstruct): void {
|
|
54
|
+
if (node instanceof StateMachine) {
|
|
55
|
+
const version = new CfnStateMachineVersion(node, `Version`, {
|
|
56
|
+
stateMachineArn: node.stateMachineArn,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
new CfnStateMachineAlias(node, `Alias`, {
|
|
60
|
+
name: this.props.alias,
|
|
61
|
+
routingConfiguration: [
|
|
62
|
+
{
|
|
63
|
+
stateMachineVersionArn: version.attrArn,
|
|
64
|
+
weight: 100,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (node instanceof Function) {
|
|
71
|
+
node.addAlias(this.props.alias);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { App, Aspects, Tags } from 'aws-cdk-lib';
|
|
3
|
+
import { Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
4
|
+
import { ApplicationStage } from '../lib/service-stacks.js';
|
|
5
|
+
|
|
6
|
+
// TODO [MI-277] Pull this out to constructs repo so we can import and use later
|
|
7
|
+
import { LogGroupDefaultsInjector } from '../_internal/log-group-defaults-injector.js';
|
|
8
|
+
import { MicroserviceChecks } from '../_internal/microservice-checks.js';
|
|
9
|
+
import { NodeJsFunctionDefaultsInjector } from '../_internal/nodejs-function-defaults-injector.js';
|
|
10
|
+
import { StepFunctionDefaultsInjector } from '../_internal/step-function-defaults-injector.ts';
|
|
11
|
+
import { VersionFunctionsAspect } from '../_internal/version-functions-aspect.js';
|
|
12
|
+
|
|
13
|
+
const APPLICATION_CONTEXT = { APPLICATION_OWNER: 'aligent' } as const;
|
|
14
|
+
|
|
15
|
+
const app = new App({
|
|
16
|
+
context: APPLICATION_CONTEXT,
|
|
17
|
+
propertyInjectors: [
|
|
18
|
+
new NodeJsFunctionDefaultsInjector({ runtime: <%= nodeRuntime %> }),
|
|
19
|
+
new StepFunctionDefaultsInjector(),
|
|
20
|
+
],
|
|
21
|
+
});
|
|
22
|
+
Tags.of(app).add('OWNER', APPLICATION_CONTEXT.APPLICATION_OWNER);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Static Stage Creation Approach
|
|
26
|
+
*
|
|
27
|
+
* We use static stage creation (explicitly defining development, staging, production) for several reasons:
|
|
28
|
+
*
|
|
29
|
+
* 1. **Predictability**: All stages are known at synthesis time, making the CDK app
|
|
30
|
+
* behavior deterministic and easier to reason about.
|
|
31
|
+
*
|
|
32
|
+
* 2. **Type Safety**: Static definitions provide better IDE support, autocompletion,
|
|
33
|
+
* and compile-time type checking for stage-specific configurations.
|
|
34
|
+
*
|
|
35
|
+
* 3. **Explicit Configuration**: Each stage's unique settings (e.g., log retention
|
|
36
|
+
* durations, aspects, property injectors) are clearly visible in the code without
|
|
37
|
+
* needing to trace through dynamic logic.
|
|
38
|
+
*
|
|
39
|
+
* 4. **Simpler Deployment**: CDK can synthesize all stages in a single pass without
|
|
40
|
+
* requiring runtime context lookups or conditional logic.
|
|
41
|
+
*
|
|
42
|
+
* 5. **CI/CD Integration**: Static stages integrate seamlessly with standard CI/CD
|
|
43
|
+
* pipelines where environment configuration is managed externally.
|
|
44
|
+
*
|
|
45
|
+
* @see {@link https://dev.to/aws-heroes/how-to-use-aws-cdk-stage-and-when-to-choose-static-vs-dynamic-stack-creation-35h|Static vs Dynamic Stack Creation}
|
|
46
|
+
*
|
|
47
|
+
* @remarks Property Injector Behavior
|
|
48
|
+
* Property injectors are applied based on their class type and will only execute once per
|
|
49
|
+
* construct tree. When the same injector type is defined at both app and stage levels, the
|
|
50
|
+
* stage-level injector takes precedence and overrides the app-level configuration.
|
|
51
|
+
*/
|
|
52
|
+
const development = new ApplicationStage(app, 'development', {
|
|
53
|
+
propertyInjectors: [new LogGroupDefaultsInjector({ duration: 'SHORT' })],
|
|
54
|
+
});
|
|
55
|
+
Aspects.of(development).add(new MicroserviceChecks());
|
|
56
|
+
|
|
57
|
+
const staging = new ApplicationStage(app, 'staging', {
|
|
58
|
+
propertyInjectors: [new LogGroupDefaultsInjector({ duration: 'MEDIUM' })],
|
|
59
|
+
});
|
|
60
|
+
Aspects.of(staging).add(new MicroserviceChecks());
|
|
61
|
+
|
|
62
|
+
const production = new ApplicationStage(app, 'production', {
|
|
63
|
+
propertyInjectors: [new LogGroupDefaultsInjector({ duration: 'LONG' })],
|
|
64
|
+
});
|
|
65
|
+
Aspects.of(production).add(new MicroserviceChecks());
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* This aspect ensures all Lambda functions and Step Functions in production
|
|
69
|
+
* are automatically versioned and have a stable 'live' alias pointing to the
|
|
70
|
+
* current version, enabling zero-downtime deployments.
|
|
71
|
+
*/
|
|
72
|
+
Aspects.of(production).add(new VersionFunctionsAspect());
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"app": "npx tsx bin/main.ts",
|
|
3
|
+
"watch": {
|
|
4
|
+
"include": ["**"],
|
|
5
|
+
"exclude": [
|
|
6
|
+
"README.md",
|
|
7
|
+
"cdk*.json",
|
|
8
|
+
"**/*.d.ts",
|
|
9
|
+
"**/*.js",
|
|
10
|
+
"tsconfig.json",
|
|
11
|
+
"package*.json",
|
|
12
|
+
"yarn.lock",
|
|
13
|
+
"node_modules",
|
|
14
|
+
"test"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"context": {
|
|
18
|
+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
|
|
19
|
+
"@aws-cdk/core:checkSecretUsage": true,
|
|
20
|
+
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"],
|
|
21
|
+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
|
|
22
|
+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
|
|
23
|
+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
|
|
24
|
+
"@aws-cdk/aws-iam:minimizePolicies": true,
|
|
25
|
+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
|
|
26
|
+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
|
|
27
|
+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
|
|
28
|
+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
|
|
29
|
+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
|
|
30
|
+
"@aws-cdk/core:enablePartitionLiterals": true,
|
|
31
|
+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
|
|
32
|
+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
|
|
33
|
+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
|
|
34
|
+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
|
|
35
|
+
"@aws-cdk/aws-route53-patters:useCertificate": true,
|
|
36
|
+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
|
|
37
|
+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
|
|
38
|
+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
|
|
39
|
+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
|
|
40
|
+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
|
|
41
|
+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
|
|
42
|
+
"@aws-cdk/aws-redshift:columnId": true,
|
|
43
|
+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
|
|
44
|
+
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
|
|
45
|
+
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
|
|
46
|
+
"@aws-cdk/aws-kms:aliasNameRef": true,
|
|
47
|
+
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
|
|
48
|
+
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
|
|
49
|
+
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
|
|
50
|
+
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
|
|
51
|
+
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
|
|
52
|
+
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
|
|
53
|
+
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
|
|
54
|
+
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
|
|
55
|
+
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
|
|
56
|
+
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
|
|
57
|
+
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
|
|
58
|
+
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
|
|
59
|
+
"@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
|
|
60
|
+
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
|
|
61
|
+
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
|
|
62
|
+
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
|
|
63
|
+
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
|
|
64
|
+
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false,
|
|
65
|
+
"@aws-cdk/aws-s3:keepNotificationInImportedBucket": false,
|
|
66
|
+
"@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature": false,
|
|
67
|
+
"@aws-cdk/aws-ecs:disableEcsImdsBlocking": true,
|
|
68
|
+
"@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": true,
|
|
69
|
+
"@aws-cdk/aws-dynamodb:resourcePolicyPerReplica": true,
|
|
70
|
+
"@aws-cdk/aws-ec2:ec2SumTImeoutEnabled": true,
|
|
71
|
+
"@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermission": true,
|
|
72
|
+
"@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId": true,
|
|
73
|
+
"@aws-cdk/core:cfnIncludeRejectComplexResourceUpdateCreatePolicyIntrinsics": true,
|
|
74
|
+
"@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": true,
|
|
75
|
+
"@aws-cdk/aws-stepfunctions-tasks:fixRunEcsTaskPolicy": true,
|
|
76
|
+
"@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault": true,
|
|
77
|
+
"@aws-cdk/aws-route53-targets:userPoolDomainNameMethodWithoutCustomResource": true,
|
|
78
|
+
"@aws-cdk/aws-elasticloadbalancingV2:albDualstackWithoutPublicIpv4SecurityGroupRulesDefault": true,
|
|
79
|
+
"@aws-cdk/aws-iam:oidcRejectUnauthorizedConnections": true,
|
|
80
|
+
"@aws-cdk/core:enableAdditionalMetadataCollection": true,
|
|
81
|
+
"@aws-cdk/aws-lambda:createNewPoliciesWithAddToRolePolicy": false,
|
|
82
|
+
"@aws-cdk/aws-s3:setUniqueReplicationRoleName": true,
|
|
83
|
+
"@aws-cdk/aws-events:requireEventBusPolicySid": true,
|
|
84
|
+
"@aws-cdk/core:aspectPrioritiesMutating": true,
|
|
85
|
+
"@aws-cdk/aws-dynamodb:retainTableReplica": true,
|
|
86
|
+
"@aws-cdk/aws-stepfunctions:useDistributedMapResultWriterV2": true,
|
|
87
|
+
"@aws-cdk/s3-notifications:addS3TrustKeyPolicyForSnsSubscriptions": true,
|
|
88
|
+
"@aws-cdk/aws-ec2:requirePrivateSubnetsForEgressOnlyInternetGateway": true,
|
|
89
|
+
"@aws-cdk/aws-s3:publicAccessBlockedByDefault": true,
|
|
90
|
+
"@aws-cdk/aws-lambda:useCdkManagedLogGroup": true
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Stage, Tags, type StageProps } from 'aws-cdk-lib';
|
|
2
|
+
import type { Construct } from 'constructs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Application Stage
|
|
6
|
+
*
|
|
7
|
+
* This is the main entry point for the application.
|
|
8
|
+
* It is used to define context and compose service stacks.
|
|
9
|
+
*
|
|
10
|
+
* Service stacks are automatically instantiated here when generated using the service generator.
|
|
11
|
+
* Each service stack will be initialized with this stage as the parent scope, ensuring proper
|
|
12
|
+
* stack composition and resource organization within the CDK application.
|
|
13
|
+
*/
|
|
14
|
+
export class ApplicationStage extends Stage {
|
|
15
|
+
constructor(scope: Construct, id: string, props?: StageProps) {
|
|
16
|
+
super(scope, id, props);
|
|
17
|
+
Tags.of(this).add('STAGE', id);
|
|
18
|
+
|
|
19
|
+
// Service stacks initialization
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "application",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"main": "./bin/main.ts",
|
|
5
|
+
"types": "./bin/main.ts",
|
|
6
|
+
"nx": {
|
|
7
|
+
"tags": [
|
|
8
|
+
"scope:application"
|
|
9
|
+
],
|
|
10
|
+
"targets": {
|
|
11
|
+
"cdk": {
|
|
12
|
+
"executor": "nx:run-commands",
|
|
13
|
+
"options": {
|
|
14
|
+
"color": true,
|
|
15
|
+
"command": "cdk",
|
|
16
|
+
"cwd": "{projectRoot}"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"parameters": {
|
|
20
|
+
"executor": "nx:run-commands",
|
|
21
|
+
"options": {
|
|
22
|
+
"path": "/application/dev"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
cdk-pipe:
|
|
2
|
+
commands:
|
|
3
|
+
cdk:
|
|
4
|
+
bootstrap: yarn nx run application:cdk bootstrap
|
|
5
|
+
deploy: yarn nx run application:cdk deploy
|
|
6
|
+
synth: yarn nx run application:cdk synth
|
|
7
|
+
diff: yarn nx run application:cdk diff
|
|
8
|
+
npm:
|
|
9
|
+
checks:
|
|
10
|
+
lint: yarn lint
|
|
11
|
+
format: yarn lint # Formatting is controlled by the lint step, we turn this off in the pipeline anyway
|
|
12
|
+
install: yarn install --immutable
|
|
13
|
+
beforeScripts:
|
|
14
|
+
- yarn --version
|
|
15
|
+
afterScripts:
|
|
16
|
+
- echo "Deployment is completed"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { eslintConfigs } from '@aligent/ts-code-standards';
|
|
2
|
+
import nxEslintPlugin from '@nx/eslint-plugin';
|
|
3
|
+
import jsonParser from 'jsonc-eslint-parser';
|
|
4
|
+
|
|
5
|
+
const eslintBaseConfig = [
|
|
6
|
+
...eslintConfigs.base,
|
|
7
|
+
{
|
|
8
|
+
ignores: [
|
|
9
|
+
'**/*.js',
|
|
10
|
+
'**/*.cjs',
|
|
11
|
+
'**/*.mjs',
|
|
12
|
+
'**/coverage',
|
|
13
|
+
'**/cdk.out',
|
|
14
|
+
'**/dist',
|
|
15
|
+
'**/out-tsc',
|
|
16
|
+
'**/vite.config.*.timestamp*',
|
|
17
|
+
'**/vitest.config.*.timestamp*',
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
files: ['**/*.ts'],
|
|
22
|
+
plugins: { '@nx': nxEslintPlugin },
|
|
23
|
+
rules: {
|
|
24
|
+
'@nx/enforce-module-boundaries': [
|
|
25
|
+
'error',
|
|
26
|
+
{
|
|
27
|
+
allow: ['^.*/eslint(\\.base)?\\.config\\.[cm]?[jt]s$'],
|
|
28
|
+
enforceBuildableLibDependency: true,
|
|
29
|
+
depConstraints: [
|
|
30
|
+
{
|
|
31
|
+
sourceTag: 'scope:application',
|
|
32
|
+
onlyDependOnLibsWithTags: ['scope:libs', 'scope:services'],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
sourceTag: 'scope:services',
|
|
36
|
+
onlyDependOnLibsWithTags: ['scope:libs', 'scope:services'],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
sourceTag: 'scope:libs',
|
|
40
|
+
onlyDependOnLibsWithTags: ['scope:libs'],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
'no-console': 'warn',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
files: ['**/*.json'],
|
|
50
|
+
languageOptions: { parser: jsonParser },
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
export default eslintBaseConfig;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fg from 'fast-glob';
|
|
2
|
+
import { builtinModules } from 'node:module';
|
|
3
|
+
import { extname, resolve } from 'node:path';
|
|
4
|
+
import { defineConfig } from 'rolldown';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Prepare Rolldown config that bundles all typescript files in a single directory in to separate files
|
|
8
|
+
* This is used to bundle lambda handlers with their own dependencies for separate upload to AWS Lambda
|
|
9
|
+
*
|
|
10
|
+
* @param {string} subPath Relative path to the handlers directory
|
|
11
|
+
* @returns Rolldown config for multiple lambda handlers
|
|
12
|
+
*/
|
|
13
|
+
export function defineLambdaConfig(subPath) {
|
|
14
|
+
if (subPath.includes('..')) throw new Error('Invalid path provided');
|
|
15
|
+
const handlersPath = resolve(process.cwd(), subPath);
|
|
16
|
+
const handlers = fg.sync(`${handlersPath}/**/*.ts`);
|
|
17
|
+
|
|
18
|
+
return handlers.map(handler => {
|
|
19
|
+
const bundledPath = handler.replace(`${handlersPath}/`, '');
|
|
20
|
+
const entryName = bundledPath.replace(extname(bundledPath), '');
|
|
21
|
+
|
|
22
|
+
return defineConfig({
|
|
23
|
+
input: { [entryName]: handler },
|
|
24
|
+
platform: 'node',
|
|
25
|
+
tsconfig: 'tsconfig.lib.json',
|
|
26
|
+
logLevel: 'info',
|
|
27
|
+
watch: false,
|
|
28
|
+
external: [...builtinModules],
|
|
29
|
+
output: {
|
|
30
|
+
entryFileNames: '[name]/index.mjs',
|
|
31
|
+
format: 'esm',
|
|
32
|
+
// TODO: [MI-251] Support sourcemap enable/disable base on environment
|
|
33
|
+
sourcemap: true,
|
|
34
|
+
// FIXME: [MI-251] Rolldown is still in Beta and built-in minification is not production ready yet
|
|
35
|
+
minify: false,
|
|
36
|
+
legalComments: 'none',
|
|
37
|
+
inlineDynamicImports: true,
|
|
38
|
+
// TODO: [MI-251] Support shims only when needed instead consider looking at tsup, tsdown and rollup shims plugins
|
|
39
|
+
banner: `import { fileURLToPath } from 'node:url';
|
|
40
|
+
import { dirname } from 'node:path';
|
|
41
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
42
|
+
const __dirname = dirname(__filename);`,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { defineConfig } from 'vitest/config';
|
|
3
|
+
|
|
4
|
+
// More information about mode: https://vite.dev/guide/env-and-mode.html#node-env-and-modes
|
|
5
|
+
export const vitestBaseConfig = defineConfig(({ command, mode }) => {
|
|
6
|
+
return {
|
|
7
|
+
test: {
|
|
8
|
+
globals: true,
|
|
9
|
+
watch: false,
|
|
10
|
+
environment: 'node',
|
|
11
|
+
reporters: ['default'],
|
|
12
|
+
coverage: {
|
|
13
|
+
provider: 'v8',
|
|
14
|
+
exclude: [
|
|
15
|
+
'node_modules/',
|
|
16
|
+
'**/types',
|
|
17
|
+
'*.mjs',
|
|
18
|
+
'**/__data__',
|
|
19
|
+
'**/dist',
|
|
20
|
+
'**/out-tsc',
|
|
21
|
+
],
|
|
22
|
+
thresholds: {
|
|
23
|
+
branches: 80,
|
|
24
|
+
functions: 80,
|
|
25
|
+
lines: 80,
|
|
26
|
+
statements: 80,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
include: [
|
|
30
|
+
'src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
|
|
31
|
+
'tests/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
|
|
32
|
+
],
|
|
33
|
+
setupFiles: [
|
|
34
|
+
// Include the root setup file in all tests that extend this config
|
|
35
|
+
resolve(import.meta.dirname, './vitest.global.setup.mjs'),
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
});
|