Skip to content

Commit ade0e02

Browse files
fix: CDK error Cannot find entry file
1 parent 8244950 commit ade0e02

File tree

10 files changed

+169
-135
lines changed

10 files changed

+169
-135
lines changed

test/cdk-basic.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ async function getFunctionName(folder: string, functionName: string) {
153153
const cdkOutputs = JSON.parse(
154154
await fs.readFile(path.join(folder, 'cdk-outputs.json'), 'utf-8'),
155155
);
156-
const lambdaName = cdkOutputs['test-lld-cdk-basic'][functionName];
156+
let lambdaName = cdkOutputs['test-lld-cdk-basic'][functionName];
157+
158+
if (!lambdaName) {
159+
lambdaName = cdkOutputs['test-lld-cdk-basic2'][functionName];
160+
}
161+
162+
if (!lambdaName) {
163+
throw new Error(
164+
`Lambda name not found for ${functionName} in cdk-outputs.json`,
165+
);
166+
}
167+
157168
return lambdaName;
158169
}

test/cdk-basic/bin/cdk-basic.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,16 @@
22
import 'source-map-support/register';
33
import * as cdk from 'aws-cdk-lib';
44
import { CdkbasicStack } from '../lib/cdk-basic-stack';
5+
import { CdkbasicStack2 } from '../lib/subfolder/cdk-basic-stack2';
56

67
const app = new cdk.App();
78

89
const environment = 'test';
910

1011
new CdkbasicStack(app, 'CdkbasicStack', {
1112
stackName: `${environment}-lld-cdk-basic`,
12-
/* If you don't specify 'env', this stack will be environment-agnostic.
13-
* Account/Region-dependent features and context lookups will not work,
14-
* but a single synthesized template can be deployed anywhere. */
15-
16-
/* Uncomment the next line to specialize this stack for the AWS Account
17-
* and Region that are implied by the current CLI configuration. */
18-
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
19-
20-
/* Uncomment the next line if you know exactly what Account and Region you
21-
* want to deploy the stack to. */
22-
// env: { account: '123456789012', region: 'us-east-1' },
13+
});
2314

24-
/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
15+
new CdkbasicStack2(app, 'CdkbasicStack2', {
16+
stackName: `${environment}-lld-cdk-basic2`,
2517
});

test/cdk-basic/lib/cdk-basic-stack.ts

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,11 @@ import * as lambda_nodejs from 'aws-cdk-lib/aws-lambda-nodejs';
44
import * as lambda from 'aws-cdk-lib/aws-lambda';
55
import * as log from 'aws-cdk-lib/aws-logs';
66
import * as path from 'path';
7-
import * as ec2 from 'aws-cdk-lib/aws-ec2';
87

98
export class CdkbasicStack extends cdk.Stack {
109
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
1110
super(scope, id, props);
1211

13-
// to test internal CDK internal handler restrict-default-security-group-handler/index.js
14-
new ec2.Vpc(this, 'vpc', {
15-
ipAddresses: ec2.IpAddresses.cidr('10.0.0.0/24'),
16-
ipProtocol: ec2.IpProtocol.DUAL_STACK,
17-
restrictDefaultSecurityGroup: true,
18-
natGateways: 0,
19-
});
20-
2112
const functionTestTsCommonJs = new lambda_nodejs.NodejsFunction(
2213
this,
2314
'TestTsCommonJs',
@@ -55,43 +46,6 @@ export class CdkbasicStack extends cdk.Stack {
5546
},
5647
);
5748

58-
//testJsEsModule
59-
const functionTestJsEsModule = new lambda_nodejs.NodejsFunction(
60-
this,
61-
'TestJsEsModule',
62-
{
63-
entry: 'services/testJsEsModule/lambda.js',
64-
handler: 'lambdaHandler',
65-
runtime: lambda.Runtime.NODEJS_20_X,
66-
bundling: {
67-
format: lambda_nodejs.OutputFormat.ESM,
68-
},
69-
logRetention: log.RetentionDays.ONE_DAY,
70-
},
71-
);
72-
73-
const functionTestJsCommonJsBase = new lambda.Function(
74-
this,
75-
'TestJsCommonJsBase',
76-
{
77-
runtime: lambda.Runtime.NODEJS_20_X,
78-
handler: 'lambda.lambdaHandler',
79-
code: lambda.Code.fromAsset('services/testJsCommonJs'),
80-
logRetention: log.RetentionDays.ONE_DAY,
81-
},
82-
);
83-
84-
const functionTestJsEsModuleBase = new lambda.Function(
85-
this,
86-
'TestJsEsModuleBase',
87-
{
88-
runtime: lambda.Runtime.NODEJS_20_X,
89-
handler: 'lambda.lambdaHandler',
90-
code: lambda.Code.fromAsset('services/testJsEsModule'),
91-
logRetention: log.RetentionDays.ONE_DAY,
92-
},
93-
);
94-
9549
new cdk.CfnOutput(this, 'FunctionNameTestTsCommonJs', {
9650
value: functionTestTsCommonJs.functionName,
9751
});
@@ -103,17 +57,5 @@ export class CdkbasicStack extends cdk.Stack {
10357
new cdk.CfnOutput(this, 'FunctionNameTestJsCommonJs', {
10458
value: functionTestJsCommonJs.functionName,
10559
});
106-
107-
new cdk.CfnOutput(this, 'FunctionNameTestJsEsModule', {
108-
value: functionTestJsEsModule.functionName,
109-
});
110-
111-
new cdk.CfnOutput(this, 'FunctionNameTestJsCommonJsBase', {
112-
value: functionTestJsCommonJsBase.functionName,
113-
});
114-
115-
new cdk.CfnOutput(this, 'FunctionNameTestJsEsModuleBase', {
116-
value: functionTestJsEsModuleBase.functionName,
117-
});
11860
}
11961
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Construct } from 'constructs';
3+
import * as lambda_nodejs from 'aws-cdk-lib/aws-lambda-nodejs';
4+
import * as lambda from 'aws-cdk-lib/aws-lambda';
5+
import * as log from 'aws-cdk-lib/aws-logs';
6+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
7+
import * as path from 'path';
8+
9+
export class CdkbasicStack2 extends cdk.Stack {
10+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
11+
super(scope, id, props);
12+
13+
// to test internal CDK internal handler restrict-default-security-group-handler/index.js
14+
new ec2.Vpc(this, 'vpc', {
15+
ipAddresses: ec2.IpAddresses.cidr('10.0.0.0/24'),
16+
ipProtocol: ec2.IpProtocol.DUAL_STACK,
17+
restrictDefaultSecurityGroup: true,
18+
natGateways: 0,
19+
});
20+
21+
//testJsEsModule
22+
const functionTestJsEsModule = new lambda_nodejs.NodejsFunction(
23+
this,
24+
'TestJsEsModule',
25+
{
26+
entry: path.join(__dirname, '../../services/testJsEsModule/lambda.js'),
27+
handler: 'lambdaHandler',
28+
runtime: lambda.Runtime.NODEJS_20_X,
29+
bundling: {
30+
format: lambda_nodejs.OutputFormat.ESM,
31+
},
32+
logRetention: log.RetentionDays.ONE_DAY,
33+
},
34+
);
35+
36+
const functionTestJsCommonJsBase = new lambda.Function(
37+
this,
38+
'TestJsCommonJsBase',
39+
{
40+
runtime: lambda.Runtime.NODEJS_20_X,
41+
handler: 'lambda.lambdaHandler',
42+
code: lambda.Code.fromAsset('services/testJsCommonJs'),
43+
logRetention: log.RetentionDays.ONE_DAY,
44+
},
45+
);
46+
47+
const functionTestJsEsModuleBase = new lambda.Function(
48+
this,
49+
'TestJsEsModuleBase',
50+
{
51+
runtime: lambda.Runtime.NODEJS_20_X,
52+
handler: 'lambda.lambdaHandler',
53+
code: lambda.Code.fromAsset('services/testJsEsModule'),
54+
logRetention: log.RetentionDays.ONE_DAY,
55+
},
56+
);
57+
58+
new cdk.CfnOutput(this, 'FunctionNameTestJsEsModule', {
59+
value: functionTestJsEsModule.functionName,
60+
});
61+
62+
new cdk.CfnOutput(this, 'FunctionNameTestJsCommonJsBase', {
63+
value: functionTestJsCommonJsBase.functionName,
64+
});
65+
66+
new cdk.CfnOutput(this, 'FunctionNameTestJsEsModuleBase', {
67+
value: functionTestJsEsModuleBase.functionName,
68+
});
69+
}
70+
}

test/cdk-basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"cdk-basic": "bin/cdk-basic.js"
66
},
77
"scripts": {
8-
"deploy": "cdk deploy -c environment=test --require-approval never --outputs-file cdk-outputs.json",
8+
"deploy": "cdk deploy --all -c environment=test --require-approval never --outputs-file cdk-outputs.json",
99
"build": "cdk synth -c environment=test",
1010
"destroy": "cdk destroy -c environment=test --force"
1111
},

test/cdk-esm.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ async function getFunctionName(folder: string, functionName: string) {
153153
const cdkOutputs = JSON.parse(
154154
await fs.readFile(path.join(folder, 'cdk-outputs.json'), 'utf-8'),
155155
);
156-
const lambdaName = cdkOutputs['test-lld-cdk-esm'][functionName];
156+
let lambdaName = cdkOutputs['test-lld-cdk-esm'][functionName];
157+
158+
if (!lambdaName) {
159+
lambdaName = cdkOutputs['test-lld-cdk-esm2'][functionName];
160+
}
161+
162+
if (!lambdaName) {
163+
throw new Error(
164+
`Lambda name not found for ${functionName} in cdk-outputs.json`,
165+
);
166+
}
167+
157168
return lambdaName;
158169
}

test/cdk-esm/bin/cdk-esm.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,17 @@ import 'source-map-support/register';
33
import * as cdk from 'aws-cdk-lib';
44
// @ts-ignore
55
import { CdkEsmStack } from '../lib/cdk-esm-stack';
6+
// @ts-ignore
7+
import { CdkEsmStack2 } from '../lib/subfolder/cdk-esm-stack2';
68

79
const app = new cdk.App();
810

911
const environment = 'test';
1012

1113
new CdkEsmStack(app, 'CdkEsmStack', {
1214
stackName: `${environment}-lld-cdk-esm`,
13-
/* If you don't specify 'env', this stack will be environment-agnostic.
14-
* Account/Region-dependent features and context lookups will not work,
15-
* but a single synthesized template can be deployed anywhere. */
16-
17-
/* Uncomment the next line to specialize this stack for the AWS Account
18-
* and Region that are implied by the current CLI configuration. */
19-
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
20-
21-
/* Uncomment the next line if you know exactly what Account and Region you
22-
* want to deploy the stack to. */
23-
// env: { account: '123456789012', region: 'us-east-1' },
15+
});
2416

25-
/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
17+
new CdkEsmStack2(app, 'CdkEsmStack2', {
18+
stackName: `${environment}-lld-cdk-esm2`,
2619
});

test/cdk-esm/lib/cdk-esm-stack.ts

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -61,43 +61,6 @@ export class CdkEsmStack extends cdk.Stack {
6161
},
6262
);
6363

64-
//testJsEsModule
65-
const functionTestJsEsModule = new lambda_nodejs.NodejsFunction(
66-
this,
67-
'TestJsEsModule',
68-
{
69-
entry: 'services/testJsEsModule/lambda.js',
70-
handler: 'lambdaHandler',
71-
runtime: lambda.Runtime.NODEJS_20_X,
72-
bundling: {
73-
format: lambda_nodejs.OutputFormat.ESM,
74-
},
75-
logRetention: log.RetentionDays.ONE_DAY,
76-
},
77-
);
78-
79-
const functionTestJsCommonJsBase = new lambda.Function(
80-
this,
81-
'TestJsCommonJsBase',
82-
{
83-
runtime: lambda.Runtime.NODEJS_20_X,
84-
handler: 'lambda.lambdaHandler',
85-
code: lambda.Code.fromAsset('services/testJsCommonJs'),
86-
logRetention: log.RetentionDays.ONE_DAY,
87-
},
88-
);
89-
90-
const functionTestJsEsModuleBase = new lambda.Function(
91-
this,
92-
'TestJsEsModuleBase',
93-
{
94-
runtime: lambda.Runtime.NODEJS_20_X,
95-
handler: 'lambda.lambdaHandler',
96-
code: lambda.Code.fromAsset('services/testJsEsModule'),
97-
logRetention: log.RetentionDays.ONE_DAY,
98-
},
99-
);
100-
10164
new cdk.CfnOutput(this, 'FunctionNameTestTsCommonJs', {
10265
value: functionTestTsCommonJs.functionName,
10366
});
@@ -109,17 +72,5 @@ export class CdkEsmStack extends cdk.Stack {
10972
new cdk.CfnOutput(this, 'FunctionNameTestJsCommonJs', {
11073
value: functionTestJsCommonJs.functionName,
11174
});
112-
113-
new cdk.CfnOutput(this, 'FunctionNameTestJsEsModule', {
114-
value: functionTestJsEsModule.functionName,
115-
});
116-
117-
new cdk.CfnOutput(this, 'FunctionNameTestJsCommonJsBase', {
118-
value: functionTestJsCommonJsBase.functionName,
119-
});
120-
121-
new cdk.CfnOutput(this, 'FunctionNameTestJsEsModuleBase', {
122-
value: functionTestJsEsModuleBase.functionName,
123-
});
12475
}
12576
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Construct } from 'constructs';
3+
import * as lambda_nodejs from 'aws-cdk-lib/aws-lambda-nodejs';
4+
import * as lambda from 'aws-cdk-lib/aws-lambda';
5+
import * as log from 'aws-cdk-lib/aws-logs';
6+
import * as path from 'path';
7+
import * as url from 'url';
8+
9+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
10+
11+
export class CdkEsmStack2 extends cdk.Stack {
12+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
13+
super(scope, id, props);
14+
15+
//testJsEsModule
16+
const functionTestJsEsModule = new lambda_nodejs.NodejsFunction(
17+
this,
18+
'TestJsEsModule',
19+
{
20+
entry: path.join(__dirname, '../../services/testJsEsModule/lambda.js'),
21+
handler: 'lambdaHandler',
22+
runtime: lambda.Runtime.NODEJS_20_X,
23+
bundling: {
24+
format: lambda_nodejs.OutputFormat.ESM,
25+
},
26+
logRetention: log.RetentionDays.ONE_DAY,
27+
},
28+
);
29+
30+
const functionTestJsCommonJsBase = new lambda.Function(
31+
this,
32+
'TestJsCommonJsBase',
33+
{
34+
runtime: lambda.Runtime.NODEJS_20_X,
35+
handler: 'lambda.lambdaHandler',
36+
code: lambda.Code.fromAsset('services/testJsCommonJs'),
37+
logRetention: log.RetentionDays.ONE_DAY,
38+
},
39+
);
40+
41+
const functionTestJsEsModuleBase = new lambda.Function(
42+
this,
43+
'TestJsEsModuleBase',
44+
{
45+
runtime: lambda.Runtime.NODEJS_20_X,
46+
handler: 'lambda.lambdaHandler',
47+
code: lambda.Code.fromAsset('services/testJsEsModule'),
48+
logRetention: log.RetentionDays.ONE_DAY,
49+
},
50+
);
51+
52+
new cdk.CfnOutput(this, 'FunctionNameTestJsEsModule', {
53+
value: functionTestJsEsModule.functionName,
54+
});
55+
56+
new cdk.CfnOutput(this, 'FunctionNameTestJsCommonJsBase', {
57+
value: functionTestJsCommonJsBase.functionName,
58+
});
59+
60+
new cdk.CfnOutput(this, 'FunctionNameTestJsEsModuleBase', {
61+
value: functionTestJsEsModuleBase.functionName,
62+
});
63+
}
64+
}

test/cdk-esm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"cdk-esm": "bin/cdk-esm.js"
77
},
88
"scripts": {
9-
"deploy": "cdk deploy -c environment=test --require-approval never --outputs-file cdk-outputs.json",
9+
"deploy": "cdk deploy --all -c environment=test --require-approval never --outputs-file cdk-outputs.json",
1010
"build": "cdk synth -c environment=test",
1111
"destroy": "cdk destroy -c environment=test --force"
1212
},

0 commit comments

Comments
 (0)