Skip to content

Commit afce0ba

Browse files
Merge pull request #50 from ServerlessLife/48-cannot-find-cdk-handler
fix: [#48] Cannot find cdk handler
2 parents 95f1c6c + 1c18538 commit afce0ba

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/frameworks/cdkFrameworkWorker.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ async function fixCdkPaths(awsCdkLibPath) {
6666
const pathsFix = {
6767
'custom-resource-handlers/': `${awsCdkLibPath}/custom-resource-handlers/`,
6868
'aws-custom-resource-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/custom-resources/aws-custom-resource-handler`,
69+
'auto-delete-objects-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-s3/auto-delete-objects-handler`,
70+
'notifications-resource-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-s3/notifications-resource-handler`,
71+
'drop-spam-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-ses/drop-spam-handler`,
72+
'aws-stepfunctions-tasks/role-policy-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-stepfunctions-tasks/role-policy-handler`,
73+
'eval-nodejs-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-stepfunctions-tasks/eval-nodejs-handler`,
74+
'cross-account-zone-delegation-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-route53/cross-account-zone-delegation-handler`,
75+
'delete-existing-record-set-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-route53/delete-existing-record-set-handler`,
76+
'aws-api-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-events-targets/aws-api-handler`,
77+
'log-retention-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-logs/log-retention-handler`,
78+
'cluster-resource-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-eks/cluster-resource-handler`,
79+
'auto-delete-images-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-ecr/auto-delete-images-handler`,
80+
'bucket-deployment-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-s3-deployment/bucket-deployment-handler`,
81+
'nodejs-entrypoint-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/core/nodejs-entrypoint-handler`,
82+
'restrict-default-security-group-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-ec2/restrict-default-security-group-handler`,
83+
'dns-validated-certificate-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-certificatemanager/dns-validated-certificate-handler`,
84+
'auto-delete-underlying-resources-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-synthetics/auto-delete-underlying-resources-handler`,
85+
'replica-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-dynamodb/replica-handler`,
86+
'oidc-handler': `${awsCdkLibPath}/custom-resource-handlers/dist/aws-iam/oidc-handler`,
6987
};
7088

7189
// Create a proxy to intercept calls to the path module so we can fix paths
@@ -90,6 +108,23 @@ async function fixCdkPaths(awsCdkLibPath) {
90108

91109
return resolvedPath;
92110
}
111+
if (prop === 'join') {
112+
let resolvedPath = target[prop].apply(target, args);
113+
114+
for (const [key, value] of Object.entries(pathsFix)) {
115+
if (resolvedPath.includes(key)) {
116+
// replace the beginning of the path with the value
117+
const i = resolvedPath.indexOf(key);
118+
const newResolvedPath = `${value}${resolvedPath.substring(i + key.length)}`;
119+
Logger.verbose(
120+
`[CDK] [Worker] Fixing path ${resolvedPath} -> ${newResolvedPath}`,
121+
);
122+
resolvedPath = newResolvedPath;
123+
}
124+
}
125+
126+
return resolvedPath;
127+
}
93128
return target[prop].apply(target, args);
94129
};
95130
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@ 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';
78

89
export class CdkbasicStack extends cdk.Stack {
910
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
1011
super(scope, id, props);
1112

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+
1221
const functionTestTsCommonJs = new lambda_nodejs.NodejsFunction(
1322
this,
1423
'TestTsCommonJs',

0 commit comments

Comments
 (0)