CDK scaffold bin/cdk.ts async entry point breaks cdk ls/synth/deploy
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- aws, node.js, typescript
- Lĩnh vực
- cli, infrastructure
Hướng nghiên cứu
Bắt đầu với scaffold template tại src/assets/cdk/bin/cdk.ts và xem xét cách các lệnh gọi ConfigIO bất đồng bộ của nó đăng ký các stack trước synth tự động của CDK. Chạy bản tái hiện bằng agentcore create, npx tsc và npx cdk ls. Hoàn tất khi project được tạo liệt kê AgentCore-myagent-main và synth tạo ra template của nó thay vì một assembly rỗng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Description
The generated bin/cdk.ts from agentcore create uses an async main() function with await configIO.readProjectSpec() and await configIO.readAWSDeploymentTargets(). This causes cdk ls, cdk synth, and cdk deploy to silently produce zero stacks with exit code 0.
Root Cause
The CDK App class has an autoSynth property that defaults to true when CDK_OUTDIR is set (i.e., when run by the CDK CLI). autoSynth uses Node.js process.on('beforeExit') to call app.synth() automatically. However, beforeExit fires when the synchronous event loop drains — before async main() completes.
Timeline when CDK CLI runs the app:
- CDK CLI spawns
node dist/bin/cdk.jswithCDK_OUTDIRset to a temp dir main().catch(...)starts the async function but returns immediately (it's a promise)- Synchronous event loop drains →
beforeExitfires →autoSynthcallsapp.synth()on an empty App (stacks are inside the unresolvedmain()) - CDK CLI reads the empty cloud assembly → zero stacks
The explicit app.synth() at the end of main() eventually runs, but by then the CDK CLI has already read the output.
Reference: CDK AppProps.autoSynth docs — "Automatically call synth() before the program exits. Default: true if running via CDK CLI (CDK_OUTDIR is set)"
Reproduction
# 1. Create a fresh project
agentcore create --name myagent --defaults
# 2. Add a deployment target
cat > myagent/agentcore/aws-targets.json << 'EOF'
[{"name": "main", "account": "123456789012", "region": "us-east-1"}]
EOF
# 3. Install and compile
cd myagent/agentcore/cdk
npm install
npx tsc
# 4. List stacks — expect "AgentCore-myagent-main", get nothing
npx cdk ls
# Output: (empty, exit code 0)
# 5. Verify the app DOES create stacks when run directly
node -e "
const { AgentCoreStack } = require('./dist/lib/cdk-stack');
const cdk = require('aws-cdk-lib');
const app = new cdk.App();
console.log('Stacks:', app.node.children.length);
"
# This also shows 0 because stacks are inside async main()
Expected Behavior
npx cdk ls should output:
AgentCore-myagent-main
Actual Behavior
npx cdk ls outputs nothing (empty stdout, exit code 0). cdk synth also exits 0 but produces no template. cdk deploy would silently deploy nothing.
Proposed Fix
Replace async ConfigIO calls with synchronous fs.readFileSync in the scaffold template (src/assets/cdk/bin/cdk.ts):
#!/usr/bin/env node
import { AgentCoreStack } from '../lib/cdk-stack';
import type { AgentCoreProjectSpec, AwsDeploymentTarget } from '@aws/agentcore-cdk';
import { App, type Environment } from 'aws-cdk-lib';
import * as path from 'path';
import * as fs from 'fs';
// Synchronous reads — CDK CLI requires stacks registered before process exits.
// Async ConfigIO calls race with the CDK CLI's autoSynth (beforeExit hook).
const configRoot = path.resolve(__dirname, '..', '..', '..');
const spec: AgentCoreProjectSpec = JSON.parse(
fs.readFileSync(path.join(configRoot, 'agentcore.json'), 'utf8'),
);
const targets: AwsDeploymentTarget[] = JSON.parse(
fs.readFileSync(path.join(configRoot, 'aws-targets.json'), 'utf8'),
);
if (targets.length === 0) {
throw new Error('No deployment targets configured.');
}
const app = new App();
for (const target of targets) {
new AgentCoreStack(app, `AgentCore-${spec.name}-${target.name}`, {
spec,
env: { account: target.account, region: target.region },
});
}
app.synth();
The agentcore.json and aws-targets.json files are small local JSON — there's no benefit to reading them asynchronously, and doing so breaks CDK CLI compatibility.
Environment
@aws/agentcoreCLI: 0.8.0@aws/agentcore-cdk: 0.1.0-alpha.17aws-cdk-lib: 2.189.1- CDK CLI: 2.1100.1
- Node.js: v22.x
- OS: macOS (Darwin 25.3.0)
- Ngôn ngữ chính
- TypeScript
- Star
- 291
- Fork
- 96
- Merge trung bình
- 20 giờ 50 phút
- Pull request đã merge (30 ngày)
- 214
Chuẩn bị môi trường
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aws/agentcore-cli
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
aws/agentcore-cli#2395 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
aws/agentcore-cli#2392 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
aws/agentcore-cli#2267 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
aws/agentcore-cli#2258 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
aws/agentcore-cli#2176 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của aws/agentcore-cli
Issue tương tự
-
ADD openalgoĐang mởtemplate
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
factory-active factory-automatic task-bug-reproduction-success task-identify-harness-labels-done task-identify-issue-type-done
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
vercel/ai#21528 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug Needs: Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
microsoft/fluentui-contrib#671 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
sveltejs/acorn-typescript#150 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100