(aws-eks): Inconsistent fargateProfileName Handling Causes Deletion Failure When PhysicalResourceId Exceeds 100 Characters #32909
Description
Describe the bug
When creating an EKS FargateProfile using the AWS CDK,
the onCreate event correctly handles long fargateProfileName values by generating a valid name using the generateProfileName() function if none is provided.
However, in the onDelete event, this logic is missing.
The deletion process directly uses the physicalResourceId as the fargateProfileName without validating its length.
If the physicalResourceId exceeds 100 characters, it results in an error during deletion
because
- AWS EKS enforces a maximum length of 100 characters for fargateProfileName.
- The fargate profile with that name does not exist.
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Version
No response
Expected Behavior
The onDelete event should handle long physicalResourceId values consistently with the creation process.
and use the same function to generate the fargateProfileName for the delete action
Current Behavior
Stack deleting failed due to that reason
Received response status [FAILED] from custom resource. Message returned: The Fargate profile name parameter should not be greater than 100 characters. Logs:
Reproduction Steps
- Deploy a CDK stack that creates a FargateProfile without specifying fargateProfileName, allowing it to auto-generate one.
- Ensure the generated PhysicalResourceId exceeds 100 characters.
- Attempt to delete the stack.
- Observe the deletion failure due to the long fargateProfileName.
Possible Solution
Adding the same logic to the onDelete event.
protected async onDelete() {
if (!this.physicalResourceId) {
throw new Error('Cannot delete a profile without a physical id');
}
const fargateProfileName = this.event.ResourceProperties.Config.fargateProfileName ?? this.generateProfileName();
const deleteFargateProfile: EKS.DeleteFargateProfileCommandInput = {
clusterName: this.event.ResourceProperties.Config.clusterName,
fargateProfileName: fargateProfileName,
};
this.log({ deleteFargateProfile });
const deleteFargateProfileResponse = await this.eks.deleteFargateProfile(deleteFargateProfile);
this.log({ deleteFargateProfileResponse });
return;
}
Additional Information/Context
No response
CDK CLI Version
2.175.1
Framework Version
No response
Node.js Version
22
OS
MacOS
Language
TypeScript
Language Version
No response
Other information
No response