@go-to-k/cdkd 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +164 -61
- package/dist/cli.js.map +3 -3
- package/dist/go-to-k-cdkd-0.3.4.tgz +0 -0
- package/package.json +1 -1
- package/dist/go-to-k-cdkd-0.3.3.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -11023,9 +11023,21 @@ var LambdaFunctionProvider = class {
|
|
|
11023
11023
|
// Lambda VPC ENI detach is async and can take 20-40 minutes in the worst case;
|
|
11024
11024
|
// we poll up to 10 minutes and then warn-and-continue, since downstream Subnet/SG
|
|
11025
11025
|
// deletion has its own retry logic that handles a small remaining window.
|
|
11026
|
+
// Budget for waiting on UpdateFunctionConfiguration to fully apply
|
|
11027
|
+
// (LastUpdateStatus -> Successful) after pre-delete VPC detach.
|
|
11026
11028
|
eniWaitTimeoutMs = 10 * 60 * 1e3;
|
|
11027
11029
|
eniWaitInitialDelayMs = 1e4;
|
|
11028
11030
|
eniWaitMaxDelayMs = 3e4;
|
|
11031
|
+
// delstack-style ENI cleanup tunables.
|
|
11032
|
+
// - initial sleep: gives AWS time to publish post-detach ENI state via
|
|
11033
|
+
// DescribeNetworkInterfaces (right after the update, the API can return
|
|
11034
|
+
// an empty list even though ENIs still exist).
|
|
11035
|
+
// - per-ENI retry budget: an in-use ENI cannot be deleted until AWS
|
|
11036
|
+
// finishes the asynchronous detach; budget gives that time to land.
|
|
11037
|
+
// - retry interval: polling cadence inside the per-ENI loop.
|
|
11038
|
+
eniInitialSleepMs = 1e4;
|
|
11039
|
+
eniDeleteRetryBudgetMs = 9e4;
|
|
11040
|
+
eniDeleteRetryIntervalMs = 5e3;
|
|
11029
11041
|
constructor() {
|
|
11030
11042
|
const awsClients = getAwsClients();
|
|
11031
11043
|
this.lambdaClient = awsClients.lambda;
|
|
@@ -11375,57 +11387,44 @@ var LambdaFunctionProvider = class {
|
|
|
11375
11387
|
}
|
|
11376
11388
|
}
|
|
11377
11389
|
async cleanupLambdaEnis(functionName) {
|
|
11390
|
+
this.logger.debug(`Cleaning up Lambda VPC ENIs for function ${functionName}`);
|
|
11391
|
+
await this.sleep(this.eniInitialSleepMs);
|
|
11392
|
+
let enis = [];
|
|
11393
|
+
try {
|
|
11394
|
+
enis = await this.listLambdaEnis(functionName);
|
|
11395
|
+
} catch (error) {
|
|
11396
|
+
this.logger.warn(
|
|
11397
|
+
`DescribeNetworkInterfaces failed for ${functionName}: ${error instanceof Error ? error.message : String(error)} \u2014 downstream Subnet/SG deletion will fall back to its own ENI cleanup`
|
|
11398
|
+
);
|
|
11399
|
+
return;
|
|
11400
|
+
}
|
|
11401
|
+
if (enis.length === 0) {
|
|
11402
|
+
this.logger.debug(`No Lambda ENIs found for ${functionName} after initial sleep`);
|
|
11403
|
+
return;
|
|
11404
|
+
}
|
|
11405
|
+
await Promise.all(enis.map((eni) => this.deleteEniWithRetry(eni.id, functionName)));
|
|
11406
|
+
}
|
|
11407
|
+
async deleteEniWithRetry(eniId, functionName) {
|
|
11378
11408
|
const start = Date.now();
|
|
11379
|
-
let delay = this.eniWaitInitialDelayMs;
|
|
11380
|
-
let attempt = 0;
|
|
11381
|
-
this.logger.debug(
|
|
11382
|
-
`Cleaning up Lambda VPC ENIs for function ${functionName} (timeout ${this.eniWaitTimeoutMs}ms)`
|
|
11383
|
-
);
|
|
11384
11409
|
for (; ; ) {
|
|
11385
|
-
attempt++;
|
|
11386
|
-
let enis = [];
|
|
11387
|
-
let listFailed = false;
|
|
11388
11410
|
try {
|
|
11389
|
-
|
|
11390
|
-
|
|
11391
|
-
this.logger.warn(
|
|
11392
|
-
`DescribeNetworkInterfaces failed while cleaning up Lambda ENIs of ${functionName}: ${error instanceof Error ? error.message : String(error)}`
|
|
11393
|
-
);
|
|
11394
|
-
listFailed = true;
|
|
11395
|
-
}
|
|
11396
|
-
if (!listFailed && enis.length === 0) {
|
|
11397
|
-
this.logger.debug(
|
|
11398
|
-
`Lambda ENIs for ${functionName} fully cleaned up after ${attempt} attempt(s) / ${Date.now() - start}ms`
|
|
11399
|
-
);
|
|
11400
|
-
return;
|
|
11401
|
-
}
|
|
11402
|
-
if (enis.length > 0) {
|
|
11403
|
-
await Promise.all(
|
|
11404
|
-
enis.map(async (eni) => {
|
|
11405
|
-
try {
|
|
11406
|
-
await this.ec2Client.send(
|
|
11407
|
-
new DeleteNetworkInterfaceCommand({ NetworkInterfaceId: eni.id })
|
|
11408
|
-
);
|
|
11409
|
-
this.logger.debug(`Deleted Lambda ENI ${eni.id} for ${functionName}`);
|
|
11410
|
-
} catch (error) {
|
|
11411
|
-
this.logger.debug(
|
|
11412
|
-
`ENI ${eni.id} (status=${eni.status}) not yet deletable: ${error instanceof Error ? error.message : String(error)}`
|
|
11413
|
-
);
|
|
11414
|
-
}
|
|
11415
|
-
})
|
|
11416
|
-
);
|
|
11417
|
-
}
|
|
11418
|
-
const elapsed = Date.now() - start;
|
|
11419
|
-
if (elapsed >= this.eniWaitTimeoutMs) {
|
|
11420
|
-
this.logger.warn(
|
|
11421
|
-
`Timeout (${this.eniWaitTimeoutMs}ms) cleaning up Lambda VPC ENIs of ${functionName} (${enis.length} remaining). Continuing \u2014 downstream Subnet/SG deletion will retry as needed.`
|
|
11422
|
-
);
|
|
11411
|
+
await this.ec2Client.send(new DeleteNetworkInterfaceCommand({ NetworkInterfaceId: eniId }));
|
|
11412
|
+
this.logger.debug(`Deleted Lambda ENI ${eniId} for ${functionName}`);
|
|
11423
11413
|
return;
|
|
11414
|
+
} catch (error) {
|
|
11415
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
11416
|
+
if (msg.includes("InvalidNetworkInterfaceID.NotFound") || msg.includes("does not exist")) {
|
|
11417
|
+
return;
|
|
11418
|
+
}
|
|
11419
|
+
const elapsed = Date.now() - start;
|
|
11420
|
+
if (elapsed >= this.eniDeleteRetryBudgetMs) {
|
|
11421
|
+
this.logger.warn(
|
|
11422
|
+
`Gave up deleting ENI ${eniId} for ${functionName} after ${elapsed}ms: ${msg} \u2014 downstream Subnet/SG deletion will retry`
|
|
11423
|
+
);
|
|
11424
|
+
return;
|
|
11425
|
+
}
|
|
11426
|
+
await this.sleep(this.eniDeleteRetryIntervalMs);
|
|
11424
11427
|
}
|
|
11425
|
-
const remaining = this.eniWaitTimeoutMs - elapsed;
|
|
11426
|
-
const sleepMs = Math.min(delay, remaining);
|
|
11427
|
-
await this.sleep(sleepMs);
|
|
11428
|
-
delay = Math.min(delay * 2, this.eniWaitMaxDelayMs);
|
|
11429
11428
|
}
|
|
11430
11429
|
}
|
|
11431
11430
|
/**
|
|
@@ -13890,7 +13889,9 @@ import {
|
|
|
13890
13889
|
CreateNetworkAclEntryCommand,
|
|
13891
13890
|
DeleteNetworkAclEntryCommand,
|
|
13892
13891
|
ReplaceNetworkAclAssociationCommand,
|
|
13893
|
-
DescribeNetworkAclsCommand
|
|
13892
|
+
DescribeNetworkAclsCommand,
|
|
13893
|
+
DescribeNetworkInterfacesCommand as DescribeNetworkInterfacesCommand2,
|
|
13894
|
+
DeleteNetworkInterfaceCommand as DeleteNetworkInterfaceCommand2
|
|
13894
13895
|
} from "@aws-sdk/client-ec2";
|
|
13895
13896
|
init_aws_clients();
|
|
13896
13897
|
var EC2Provider = class {
|
|
@@ -14356,23 +14357,82 @@ var EC2Provider = class {
|
|
|
14356
14357
|
}
|
|
14357
14358
|
async deleteSubnet(logicalId, physicalId, resourceType) {
|
|
14358
14359
|
this.logger.debug(`Deleting Subnet ${logicalId}: ${physicalId}`);
|
|
14359
|
-
|
|
14360
|
-
|
|
14361
|
-
|
|
14362
|
-
|
|
14363
|
-
|
|
14364
|
-
this.logger.debug(`Subnet ${physicalId} does not exist, skipping deletion`);
|
|
14360
|
+
const maxAttempts = 10;
|
|
14361
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
14362
|
+
try {
|
|
14363
|
+
await this.ec2Client.send(new DeleteSubnetCommand({ SubnetId: physicalId }));
|
|
14364
|
+
this.logger.debug(`Successfully deleted Subnet ${logicalId}`);
|
|
14365
14365
|
return;
|
|
14366
|
+
} catch (error) {
|
|
14367
|
+
if (this.isNotFoundError(error)) {
|
|
14368
|
+
this.logger.debug(`Subnet ${physicalId} does not exist, skipping deletion`);
|
|
14369
|
+
return;
|
|
14370
|
+
}
|
|
14371
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
14372
|
+
const isDependencyError = msg.includes("has dependencies") || msg.includes("DependencyViolation");
|
|
14373
|
+
if (isDependencyError && attempt < maxAttempts) {
|
|
14374
|
+
await this.cleanupSubnetLambdaEnis(physicalId);
|
|
14375
|
+
this.logger.debug(
|
|
14376
|
+
`Subnet ${physicalId} has dependencies (attempt ${attempt}/${maxAttempts}), retrying in ${attempt * 5}s...`
|
|
14377
|
+
);
|
|
14378
|
+
await new Promise((resolve4) => setTimeout(resolve4, attempt * 5e3));
|
|
14379
|
+
continue;
|
|
14380
|
+
}
|
|
14381
|
+
const cause = error instanceof Error ? error : void 0;
|
|
14382
|
+
throw new ProvisioningError(
|
|
14383
|
+
`Failed to delete Subnet ${logicalId}: ${msg}`,
|
|
14384
|
+
resourceType,
|
|
14385
|
+
logicalId,
|
|
14386
|
+
physicalId,
|
|
14387
|
+
cause
|
|
14388
|
+
);
|
|
14366
14389
|
}
|
|
14367
|
-
|
|
14368
|
-
|
|
14369
|
-
|
|
14370
|
-
|
|
14371
|
-
|
|
14372
|
-
|
|
14373
|
-
|
|
14390
|
+
}
|
|
14391
|
+
}
|
|
14392
|
+
/**
|
|
14393
|
+
* Best-effort: list Lambda-managed ENIs in the given subnet and try to
|
|
14394
|
+
* delete each one. Used as a side-channel cleanup when DeleteSubnet
|
|
14395
|
+
* fails with "has dependencies" — the Lambda provider's own ENI cleanup
|
|
14396
|
+
* may have run out of budget before AWS finished detaching, so a second
|
|
14397
|
+
* attempt from the subnet side typically succeeds a few seconds later
|
|
14398
|
+
* once the ENIs flip from `in-use` to `available`.
|
|
14399
|
+
*/
|
|
14400
|
+
async cleanupSubnetLambdaEnis(subnetId) {
|
|
14401
|
+
let enis;
|
|
14402
|
+
try {
|
|
14403
|
+
const resp = await this.ec2Client.send(
|
|
14404
|
+
new DescribeNetworkInterfacesCommand2({
|
|
14405
|
+
Filters: [
|
|
14406
|
+
{ Name: "subnet-id", Values: [subnetId] },
|
|
14407
|
+
{ Name: "requester-id", Values: ["*:awslambda_*"] }
|
|
14408
|
+
]
|
|
14409
|
+
})
|
|
14410
|
+
);
|
|
14411
|
+
enis = (resp.NetworkInterfaces ?? []).filter((ni) => ni.NetworkInterfaceId).map((ni) => ({ id: ni.NetworkInterfaceId, status: ni.Status ?? "unknown" }));
|
|
14412
|
+
} catch (err) {
|
|
14413
|
+
this.logger.debug(
|
|
14414
|
+
`cleanupSubnetLambdaEnis: DescribeNetworkInterfaces failed for ${subnetId}: ${err instanceof Error ? err.message : String(err)}`
|
|
14374
14415
|
);
|
|
14416
|
+
return;
|
|
14375
14417
|
}
|
|
14418
|
+
if (enis.length === 0)
|
|
14419
|
+
return;
|
|
14420
|
+
await Promise.all(
|
|
14421
|
+
enis.map(async (eni) => {
|
|
14422
|
+
try {
|
|
14423
|
+
await this.ec2Client.send(
|
|
14424
|
+
new DeleteNetworkInterfaceCommand2({ NetworkInterfaceId: eni.id })
|
|
14425
|
+
);
|
|
14426
|
+
this.logger.debug(
|
|
14427
|
+
`cleanupSubnetLambdaEnis: deleted Lambda ENI ${eni.id} in subnet ${subnetId}`
|
|
14428
|
+
);
|
|
14429
|
+
} catch (err) {
|
|
14430
|
+
this.logger.debug(
|
|
14431
|
+
`cleanupSubnetLambdaEnis: ENI ${eni.id} (status=${eni.status}) not yet deletable: ${err instanceof Error ? err.message : String(err)}`
|
|
14432
|
+
);
|
|
14433
|
+
}
|
|
14434
|
+
})
|
|
14435
|
+
);
|
|
14376
14436
|
}
|
|
14377
14437
|
async getSubnetAttribute(physicalId, attributeName) {
|
|
14378
14438
|
if (attributeName === "SubnetId")
|
|
@@ -14872,6 +14932,7 @@ var EC2Provider = class {
|
|
|
14872
14932
|
}
|
|
14873
14933
|
const msg = error instanceof Error ? error.message : String(error);
|
|
14874
14934
|
if (msg.includes("dependent object") && attempt < maxAttempts) {
|
|
14935
|
+
await this.cleanupSecurityGroupLambdaEnis(physicalId);
|
|
14875
14936
|
this.logger.debug(
|
|
14876
14937
|
`SecurityGroup ${physicalId} has dependent objects (attempt ${attempt}/${maxAttempts}), retrying in ${attempt * 5}s...`
|
|
14877
14938
|
);
|
|
@@ -14889,6 +14950,48 @@ var EC2Provider = class {
|
|
|
14889
14950
|
}
|
|
14890
14951
|
}
|
|
14891
14952
|
}
|
|
14953
|
+
/**
|
|
14954
|
+
* Best-effort: list Lambda-managed ENIs that reference the given security
|
|
14955
|
+
* group and try to delete each one. Mirror of cleanupSubnetLambdaEnis but
|
|
14956
|
+
* filtered by `group-id`.
|
|
14957
|
+
*/
|
|
14958
|
+
async cleanupSecurityGroupLambdaEnis(groupId) {
|
|
14959
|
+
let enis;
|
|
14960
|
+
try {
|
|
14961
|
+
const resp = await this.ec2Client.send(
|
|
14962
|
+
new DescribeNetworkInterfacesCommand2({
|
|
14963
|
+
Filters: [
|
|
14964
|
+
{ Name: "group-id", Values: [groupId] },
|
|
14965
|
+
{ Name: "requester-id", Values: ["*:awslambda_*"] }
|
|
14966
|
+
]
|
|
14967
|
+
})
|
|
14968
|
+
);
|
|
14969
|
+
enis = (resp.NetworkInterfaces ?? []).filter((ni) => ni.NetworkInterfaceId).map((ni) => ({ id: ni.NetworkInterfaceId, status: ni.Status ?? "unknown" }));
|
|
14970
|
+
} catch (err) {
|
|
14971
|
+
this.logger.debug(
|
|
14972
|
+
`cleanupSecurityGroupLambdaEnis: DescribeNetworkInterfaces failed for ${groupId}: ${err instanceof Error ? err.message : String(err)}`
|
|
14973
|
+
);
|
|
14974
|
+
return;
|
|
14975
|
+
}
|
|
14976
|
+
if (enis.length === 0)
|
|
14977
|
+
return;
|
|
14978
|
+
await Promise.all(
|
|
14979
|
+
enis.map(async (eni) => {
|
|
14980
|
+
try {
|
|
14981
|
+
await this.ec2Client.send(
|
|
14982
|
+
new DeleteNetworkInterfaceCommand2({ NetworkInterfaceId: eni.id })
|
|
14983
|
+
);
|
|
14984
|
+
this.logger.debug(
|
|
14985
|
+
`cleanupSecurityGroupLambdaEnis: deleted Lambda ENI ${eni.id} for SG ${groupId}`
|
|
14986
|
+
);
|
|
14987
|
+
} catch (err) {
|
|
14988
|
+
this.logger.debug(
|
|
14989
|
+
`cleanupSecurityGroupLambdaEnis: ENI ${eni.id} (status=${eni.status}) not yet deletable: ${err instanceof Error ? err.message : String(err)}`
|
|
14990
|
+
);
|
|
14991
|
+
}
|
|
14992
|
+
})
|
|
14993
|
+
);
|
|
14994
|
+
}
|
|
14892
14995
|
async getSecurityGroupAttribute(physicalId, attributeName) {
|
|
14893
14996
|
if (attributeName === "GroupId")
|
|
14894
14997
|
return physicalId;
|
|
@@ -27656,7 +27759,7 @@ function reorderArgs(argv) {
|
|
|
27656
27759
|
}
|
|
27657
27760
|
async function main() {
|
|
27658
27761
|
const program = new Command8();
|
|
27659
|
-
program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.3.
|
|
27762
|
+
program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.3.4");
|
|
27660
27763
|
program.addCommand(createBootstrapCommand());
|
|
27661
27764
|
program.addCommand(createSynthCommand());
|
|
27662
27765
|
program.addCommand(createDeployCommand());
|