Fix: AWS CDK deployments now work with AWS SSO profiles - #925
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes AWS CDK deployment issues with AWS SSO profiles by configuring credential exports and environment variables in nx.json, while also upgrading Node.js runtimes and AWS CDK dependencies across the monorepo.
Key changes include:
- Added global CDK target defaults in nx.json that export AWS credentials and set CDK environment variables for SSO profile support
- Updated CDK app.ts files to read account/region from environment variables instead of hardcoded values
- Upgraded Node.js runtimes from 18.x to 20.x/22.x across Lambda functions and development environment
- Attempted upgrade of AWS CDK packages (contains version issues - see comments)
Reviewed changes
Copilot reviewed 50 out of 53 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| nx.json | Added global CDK command targets (deploy, destroy, diff, synth, bootstrap) with AWS SSO credential export logic |
| platform/message-bus/bin/app.ts | Updated to use CDK_DEFAULT_ACCOUNT and CDK_DEFAULT_REGION environment variables |
| platform/lambda-layers/bin/app.ts | Updated to use CDK_DEFAULT_ACCOUNT and CDK_DEFAULT_REGION environment variables |
| platform/message-bus/project.json | Added CDK target overrides to use global nx.json configuration |
| platform/lambda-layers/project.json | Added CDK target overrides to use global nx.json configuration |
| platform/message-bus/stacks/message-bus.stack.ts | Updated bucket name, removal policy, and added unused imports |
| platform/lambda-layers/stacks/nestjs-layer.stack.ts | Updated Node.js runtime from 18.x to 20.x for bundling |
| platform/lambda-layers/stacks/chromium-layer.stack.ts | Updated compatible runtime from nodejs18.x to nodejs20.x |
| platform/constructs/src/nestjs/nestjs.ts | Updated Lambda runtime from nodejs18.x to nodejs20.x |
| services/*/package.json | Upgraded aws-cdk and aws-cdk-lib versions (version 2.1034.0 appears invalid) |
| middleware/*/package.json | Upgraded aws-cdk and aws-cdk-lib versions (version 2.1034.0 appears invalid) |
| clients/*/package.json | Upgraded aws-cdk and aws-cdk-lib versions (version 2.1034.0 appears invalid) |
| platform/*/package.json | Upgraded aws-cdk and aws-cdk-lib versions (version 2.1034.0 appears invalid) |
| .nvmrc | Updated Node version from 18.18.0 to 20.9.0 |
| .github/workflows/*.yml | Updated Node.js version to 20.9.0 across all workflows |
| libraries/promare-gradients/src/scss/* | Migrated to dart-sass using sass:math module |
| libraries/promare-gradients/package.json | Removed node-sass, updated build command to use sass CLI |
| services//stacks/snapshots/ | Updated snapshots reflecting runtime upgrades and CDK version changes |
Comments suppressed due to low confidence (2)
platform/message-bus/stacks/message-bus.stack.ts:3
- Unused import CustomResource.
platform/message-bus/stacks/message-bus.stack.ts:9 - Unused import cr.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 51 out of 54 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix promare-gradients SCSS map formatting and phi calculation syntax - Update RemovalPolicy from invalid RETAIN_ON_UPDATE_OR_DELETE to RETAIN - Add error handling to setup-aws-cdk-env.sh script
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 51 out of 54 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 68 out of 85 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,33 @@ | |||
| #!/bin/bash | |||
There was a problem hiding this comment.
The shebang line includes a leading space which may cause issues on some systems. Shell scripts should start with #!/bin/bash without any leading whitespace to ensure proper execution.
* fix: correct SCSS syntax by closing math.div on same line Co-authored-by: hxtree <19890291+hxtree@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Problem
CDK deployments were failing with "Unable to resolve AWS account" and "no credentials configured" errors, even when AWS_PROFILE=DeveloperSandbox was set in the environment.
Root Cause
AWS SSO profiles use credential_process which wasn't accessible to CDK when running through npx in subprocesses, despite AWS_PROFILE being set or --profile flags being used.
Solution
Updated nx.json to add global targetDefaults for CDK commands that:
Export actual AWS credentials using aws configure export-credentials
Dynamically fetch account/region at runtime from the active AWS profile
Set CDK_DEFAULT_ACCOUNT and CDK_DEFAULT_REGION environment variables
Apply to all CDK projects workspace-wide
Updated CDK stack files to use environment variables for account/region configuration instead of hardcoded values.
Changes
nx.json: Added global CDK target defaults (cdk:deploy, cdk:destroy, cdk:diff, cdk:synth, cdk:bootstrap)
app.ts: Stack now uses CDK_DEFAULT_ACCOUNT and CDK_DEFAULT_REGION from environment
project.json: Override targets to use global nx.json configuration
Testing
✅ nx cdk:synth lambda-layers - successful
✅ nx cdk:deploy lambda-layers - credentials working (blocked on permissions, not credentials)