aws / aws/aws-cdk

(aws-eks): Inconsistent fargateProfileName Handling Causes Deletion Failure When PhysicalResourceId Exceeds 100 Characters

Open
#32,909 1 comment 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-eks bug effort/medium p1
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

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
1. AWS EKS enforces a maximum length of 100 characters for fargateProfileName.
2. 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

1. Deploy a CDK stack that creates a FargateProfile without specifying fargateProfileName, allowing it to auto-generate one.
2. Ensure the generated PhysicalResourceId exceeds 100 characters.
3. Attempt to delete the stack.
4. Observe the deletion failure due to the long fargateProfileName.

### Possible Solution

Adding the same logic to the onDelete event.

```typescript
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_

Contributor guide

Open the contributing guide

Research direction

Start by locating the EKS FargateProfile custom-resource entry points onCreate and onDelete, along with generateProfileName(). Compare how creation and deletion derive fargateProfileName, then verify that deleting a profile whose physicalResourceId exceeds 100 characters succeeds without violating the AWS EKS name limit.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.