Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ab2dabb
MI-246: Update dependencies
kai-nguyen-aligent Aug 19, 2025
b7e0075
MI-246: Added default handler
kai-nguyen-aligent Aug 19, 2025
3933cc1
MI-246: Removed CDK's bundle configuration
kai-nguyen-aligent Aug 19, 2025
f9f1667
MI-246: Update nx & vite configuration
kai-nguyen-aligent Aug 19, 2025
c3f3295
MI-246: Update templates
kai-nguyen-aligent Aug 19, 2025
ebecb0e
MI-246: Remove incorrect config
kai-nguyen-aligent Aug 19, 2025
8e44cde
MI-246: Fixed vite config for bundling
kai-nguyen-aligent Aug 19, 2025
a8424e8
MI-246: Fixed import of infra code & run nx sync
kai-nguyen-aligent Aug 19, 2025
64fd594
MI-246: Migrate to Nx 21.4
kai-nguyen-aligent Aug 19, 2025
3c7f5d4
MI-246: Disable build step if there is no lambda
kai-nguyen-aligent Aug 20, 2025
4113621
MI-246: Update Readme
kai-nguyen-aligent Aug 20, 2025
d7b3b5a
MI-246: Use nodenext for module
kai-nguyen-aligent Aug 21, 2025
dee19ce
MI-246: `moduleResolution` is now managed by `module`
kai-nguyen-aligent Aug 21, 2025
dcc8512
MI-246: Explicitly set module, target and moduleResolution
kai-nguyen-aligent Aug 21, 2025
718347a
MI-246: Remove redundant inlineDynamicImports RollUp config
kai-nguyen-aligent Aug 22, 2025
039d23d
MI-246: Fixed code path resolver & added handler
kai-nguyen-aligent Aug 22, 2025
cdb7fcb
MI-246: Retain relative path for bundled handlers
tvhees Aug 22, 2025
2977608
Merge pull request #1115 from aligent/feature/MI-246_retain-relative-…
tvhees Aug 24, 2025
c6b0e15
Merge pull request #1104 from aligent/feat/MI-246-vite-bundle-lambda-…
tvhees Aug 24, 2025
56b78cf
Bump minor version to 4.1.0
tvhees Aug 24, 2025
290886a
Merge pull request #1116 from aligent/release/v4.1.0
tvhees Aug 24, 2025
1d8233c
Bump form-data from 4.0.3 to 4.0.4
dependabot[bot] Aug 24, 2025
761dfbb
fix: ensure example service instantiation works
toddhainsworth Aug 28, 2025
b62a8fe
Merge pull request #1126 from aligent/fix/readme-service-scope
tvhees Aug 28, 2025
d7b2bd6
MI-259: Fix step 2 of setup documentation
tvhees Sep 1, 2025
394d1ba
Bump the patch version of Nx and associated plugins
tvhees Sep 1, 2025
4542581
Merge pull request #1128 from aligent/chore/bump-nx-21.4.1
tvhees Sep 1, 2025
adcb125
Merge pull request #1117 from aligent/dependabot/npm_and_yarn/form-da…
tvhees Sep 1, 2025
2edb178
Merge pull request #1127 from aligent/chore/MI-259_separate-install-a…
tvhees Sep 1, 2025
69c6e90
Merge pull request #1129 from aligent/release/v4.1.1
tvhees Sep 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/instructions/nx.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
applyTo: '**'
---

// This file is automatically generated by Nx Console

You are in an nx workspace using Nx 21.3.11 and yarn as the package manager.

You have access to the Nx MCP server and the tools it provides. Use them. Follow these guidelines in order to best help the user:

# General Guidelines
- When answering questions, use the nx_workspace tool first to gain an understanding of the workspace architecture
- For questions around nx configuration, best practices or if you're unsure, use the nx_docs tool to get relevant, up-to-date docs!! Always use this instead of assuming things about nx configuration
- If the user needs help with an Nx configuration or project graph error, use the 'nx_workspace' tool to get any errors
- To help answer questions about the workspace structure or simply help with demonstrating how tasks depend on each other, use the 'nx_visualize_graph' tool

# Generation Guidelines
If the user wants to generate something, use the following flow:

- learn about the nx workspace and any specifics the user needs by using the 'nx_workspace' tool and the 'nx_project_details' tool if applicable
- get the available generators using the 'nx_generators' tool
- decide which generator to use. If no generators seem relevant, check the 'nx_available_plugins' tool to see if the user could install a plugin to help them
- get generator details using the 'nx_generator_schema' tool
- you may use the 'nx_docs' tool to learn more about a specific generator or technology if you're unsure
- decide which options to provide in order to best complete the user's request. Don't make any assumptions and keep the options minimalistic
- open the generator UI using the 'nx_open_generate_ui' tool
- wait for the user to finish the generator
- read the generator log file using the 'nx_read_generator_log' tool
- use the information provided in the log file to answer the user's question or continue with what they were doing

# Running Tasks Guidelines
If the user wants help with tasks or commands (which include keywords like "test", "build", "lint", or other similar actions), use the following flow:
- Use the 'nx_current_running_tasks_details' tool to get the list of tasks (this can include tasks that were completed, stopped or failed).
- If there are any tasks, ask the user if they would like help with a specific task then use the 'nx_current_running_task_output' tool to get the terminal output for that task/command
- Use the terminal output from 'nx_current_running_task_output' to see what's wrong and help the user fix their problem. Use the appropriate tools if necessary
- If the user would like to rerun the task or command, always use `nx run <taskId>` to rerun in the terminal. This will ensure that the task will run in the nx context and will be run the same way it originally executed
- If the task was marked as "continuous" do not offer to rerun the task. This task is already running and the user can see the output in the terminal. You can use 'nx_current_running_task_output' to get the output of the task to verify the output.



26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ A template for developing a suite of AWS microservices using [AWS CDK](https://d

Example: `@aligent-int/integrations`

2. Install the template and validate it's passing code standards
2. Install the template, then validate all code standard tests are passing

```bash
nvm use && yarn install && yarn audit
nvm use && yarn install
yarn audit
```

3. (Optional) Commit the initial state of the template. This ensures subsequent changes are easy to review, rather than getting lost in the template boilerplate
Expand Down Expand Up @@ -69,6 +70,22 @@ yarn nx g service test-app --type=general
# Will create a project called @services/test-app in the services/ folder
```

Newly added service may not be detected by Nx immediately. You will need to update lockfile then reset Nx cache & stop its daemon and update Nx’s internal dependency graph and ensure your workspace is in sync.

```bash
# Update lockfile
yarn install

# Reset Nx cache and stop the daemon
yarn nx reset

# Update Nx's internal dependency graph and ensure workspace is in sync
yarn nx sync

# Alternatively, you can combine them into one line
yarn install && yarn nx reset && yarn nx sync
```

Import and instantiate the service in `ApplicationStage` inside `applications/core/bin/main.ts`:

```typescript
Expand All @@ -83,16 +100,14 @@ class ApplicationStage extends Stage {
Tags.of(this).add('STAGE', id);

// Instantiate service stacks here as required..
new YourServiceStack(scope, 'your-service-name', {
new YourServiceStack(this, 'your-service-name', {
...props,
description: 'Your service description',
});
}
}
```

Note: You will need to run `yarn install` and `yarn nx sync` before other projects will detect the new service

---

### 🧪 Testing the application
Expand Down Expand Up @@ -161,6 +176,7 @@ yarn nx g remove <service-name>

You may need to remove imports of the service from the application first.
You may need to remove references to the service in `nx.json` afterwards.
You may need to run `yarn install` to remove the service reference from the lock file.

### 🧪 Testing with Mock Services

Expand Down
8 changes: 2 additions & 6 deletions applications/core/bin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
NodeJsFunctionDefaultsInjector,
StepFunctionDefaultsInjector,
VersionFunctionsAspect,
} from '@libs/cdk-utils';
} from '@libs/cdk-utils/infra';
import { App, Aspects, Duration, Stage, Tags, type StageProps } from 'aws-cdk-lib';
import { Architecture, Runtime } from 'aws-cdk-lib/aws-lambda';
import type { Construct } from 'constructs';
Expand Down Expand Up @@ -48,11 +48,7 @@ new ApplicationStage(app, 'dev', {
propertyInjectors: [
// NOTE: Property Injectors will only apply ONCE each, so adding one here
// overrides the same injector at the app level
new NodeJsFunctionDefaultsInjector({
sourceMap: false,
esm: true,
minify: false,
}).withProps({
new NodeJsFunctionDefaultsInjector({ sourceMap: false }).withProps({
timeout: Duration.seconds(6),
memorySize: 192,
runtime: Runtime.NODEJS_22_X,
Expand Down
19 changes: 13 additions & 6 deletions libs/cdk-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
"version": "0.0.1",
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"import": "./src/index.ts",
"default": "./src/index.ts"
},
"./infra": {
"types": "./src/infra.ts",
"import": "./src/infra.ts"
Expand All @@ -19,5 +14,17 @@
"./package.json": "./package.json"
},
"main": "./src/index.ts",
"types": "./src/index.ts"
"types": "./src/index.ts",
"nx": {
"targets": {
"build": {
"executor": "nx:run-commands",
"options": {
"command": "tsc --build tsconfig.lib.json",
"color": true,
"cwd": "{projectRoot}"
}
}
}
}
}
2 changes: 2 additions & 0 deletions libs/cdk-utils/src/infra.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* v8 ignore start */
export * from './lib/aspects';
export * from './lib/constructs';
export * from './lib/injectors';
export * from './lib/rules/microservice-checks';
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,13 @@ describe('NodeJsFunctionDefaultsInjector', () => {
});

test('merges bundling and environment properties correctly', () => {
PropertyInjectors.of(stack).add(
new NodeJsFunctionDefaultsInjector({
sourceMap: false,
esm: true,
minify: false,
})
);
// Sourcemaps would normally be false in 'dev' configuration
PropertyInjectors.of(stack).add(new NodeJsFunctionDefaultsInjector({ sourceMap: true }));

new NodejsFunction(stack, 'TestFunction', {
runtime: Runtime.NODEJS_22_X,
handler: 'index.handler',
code: Code.fromInline('exports.handler = async () => ({ statusCode: 200 });'),
bundling: {
// Sourcemaps would normally be false in 'dev' configuration
sourceMap: true,
},
environment: {
BUCKET_NAME: 'test-bucket',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
import { type InjectionContext, type IPropertyInjector } from 'aws-cdk-lib';
import { Runtime, Tracing } from 'aws-cdk-lib/aws-lambda';
import {
NodejsFunction,
OutputFormat,
type NodejsFunctionProps,
} from 'aws-cdk-lib/aws-lambda-nodejs';
import { NodejsFunction, type NodejsFunctionProps } from 'aws-cdk-lib/aws-lambda-nodejs';
import { logInjector } from './log-injector';

/**
* ESM support banner
*
* This is a workaround to support ESM in Lambda functions.
* Aliases are used to avoid name conflicts, this may not be a real issue
*
* @see https://github.com/evanw/esbuild/issues/1944
* @see https://aws.plainenglish.io/significantly-improve-typescript-lambda-function-readability-in-aws-console-613bc5ae98f6
*/
const ESM_SUPPORT_BANNER = [
`import { fileURLToPath } from 'url';`,
`import { createRequire as topLevelCreateRequire } from 'module';`,
`import { dirname as ddirname } from 'path';`,
`const require = topLevelCreateRequire(import.meta.url);`,
`const __filename = fileURLToPath(import.meta.url);`,
`const __dirname = ddirname(__filename);`,
].join(''); // Must be a single line, if the banner has `\n` characters they cause a syntax error

/**
* Property injector for Node.js Lambda functions with configuration-aware defaults
*
Expand Down Expand Up @@ -66,23 +44,16 @@ export class NodeJsFunctionDefaultsInjector implements IPropertyInjector {
*
* @param configuration - Configuration identifier used to select appropriate defaults. Uses production defaults if not specified.
* @param configuration.sourceMap - Whether to enable source maps.
* @param configuration.esm - Whether to enable ESM support.
* @param configuration.minify - Whether to enable minification.
*/
constructor(
private readonly configuration: {
sourceMap: boolean;
esm: boolean;
minify: boolean;
} = {
sourceMap: true,
esm: true,
minify: true,
}
) {
this.defaultProps = {
runtime: Runtime.NODEJS_22_X,
bundling: bundlingProperties(configuration),
tracing: Tracing.ACTIVE,
};
}
Expand All @@ -100,8 +71,6 @@ export class NodeJsFunctionDefaultsInjector implements IPropertyInjector {
* ```typescript
* const customInjector = new NodeJsFunctionDefaultsInjector({
* sourceMaps: false,
* esm: false,
* minify: false,
* })
* .withProps({
* timeout: Duration.minutes(5),
Expand Down Expand Up @@ -143,7 +112,7 @@ export class NodeJsFunctionDefaultsInjector implements IPropertyInjector {
// If source maps are enabled in our bundling, add the required NODE_OPTIONS flag to the environment
const environment = {
...props.environment,
...(props.bundling?.sourceMap ? { NODE_OPTIONS: '--enable-source-maps' } : {}),
...(this.configuration.sourceMap ? { NODE_OPTIONS: '--enable-source-maps' } : {}),
};

return {
Expand All @@ -152,37 +121,3 @@ export class NodeJsFunctionDefaultsInjector implements IPropertyInjector {
};
}
}

/**
* Returns configuration-specific bundling properties for Lambda functions
*
* Provides optimized bundling configurations for different environments:
* - 'dev': Fast builds for development (no minification, bundle analysis enabled)
* - 'stg': Balanced configuration for staging
* - Default: Production-optimized (minified, tree-shaking enabled)
*
* @param configuration - Configuration identifier to determine bundling strategy
* @returns Bundling properties optimized for the specified configuration
*/
function bundlingProperties({
sourceMap,
esm,
minify,
}: {
sourceMap: boolean;
esm: boolean;
minify: boolean;
}) {
return {
...(sourceMap && { sourceMap: true }),
...(esm && { format: OutputFormat.ESM, banner: ESM_SUPPORT_BANNER }),
...(minify && {
keepNames: true,
minify: true,
buildArgs: {
bundle: 'true',
treeShaking: 'true',
},
}),
};
}
18 changes: 9 additions & 9 deletions libs/cdk-utils/vite.config.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { defineConfig, mergeConfig } from 'vitest/config';
import { viteBaseConfig } from '../../vite.config.base.mjs';

export default mergeConfig(
viteBaseConfig,
defineConfig({
cacheDir: '../../node_modules/.vite/cdk-utils',
test: {
environment: {
NODE_ENV: 'test',
export default defineConfig(configEnv =>
mergeConfig(
viteBaseConfig(configEnv),
defineConfig({
cacheDir: '../../node_modules/.vite/cdk-utils',
test: {
env: { NODE_ENV: 'test' },
},
},
})
})
)
);
5 changes: 5 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@
"dependsOn": ["^build"],
"inputs": ["production", "^production"]
},
"cdk": {
"dependsOn": ["^build"],
"inputs": ["production", "^production"]
},
"pg": {
"executor": "nx:run-commands",
"dependsOn": ["^build"],
"options": {
"color": true,
"cwd": "{workspaceRoot}/applications/core"
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aligent/app",
"version": "4.0.0",
"version": "4.1.0",
"description": "Aligent AWS microservices template using Typescript and AWS CDK",
"author": "Aligent Consulting",
"type": "module",
Expand All @@ -25,13 +25,13 @@
],
"devDependencies": {
"@aligent/ts-code-standards": "^4.0.2",
"@nx/devkit": "21.3.11",
"@nx/esbuild": "21.3.11",
"@nx/eslint": "21.3.11",
"@nx/eslint-plugin": "21.3.11",
"@nx/js": "21.3.11",
"@nx/vite": "21.3.11",
"@nx/web": "21.3.11",
"@nx/devkit": "21.4.1",
"@nx/esbuild": "21.4.1",
"@nx/eslint": "21.4.1",
"@nx/eslint-plugin": "21.4.1",
"@nx/js": "21.4.1",
"@nx/vite": "21.4.1",
"@nx/web": "21.4.1",
"@swc-node/register": "^1.10.10",
"@swc/core": "^1.13.3",
"@swc/helpers": "^0.5.17",
Expand All @@ -49,16 +49,16 @@
"esbuild-visualizer": "^0.7.0",
"eslint": "^9.32.0",
"eslint-config-prettier": "10.1.8",
"fast-glob": "^3.3.3",
"jiti": "2.5.1",
"jsonc-eslint-parser": "^2.4.0",
"nx": "21.3.11",
"nx": "21.4.1",
"open": "^10.2.0",
"prettier": "^3.6.2",
"store-parameters": "^1.0.6",
"tslib": "^2.8.1",
"typescript": "~5.9.2",
"vite": "6.3.5",
"vite-tsconfig-paths": "~4.3.2",
"vitest": "^3.2.4"
},
"engines": {
Expand Down
Loading
Loading