Skip to content

This is not possible to delete stacks with name longer than 128 chars #6840

Closed

Description

@ikhvostenkov

Describe the bug

This is possible to create stack with name longer than 128 chars through CDK, but this is not possible to delete stack with AWS cli with stack name longer than 128 chars. Probably this should be prohibited to create stacks with name longer than 128 char in CDK, but as soon as this is possible you should have chance to delete it, especially if you have ~100 such stacks, doing this through AWS Console manually is annoying.

Expected Behavior

Stack is successfully deleted.

Current Behavior

An error occurred (ValidationError) when calling the DeleteStack operation: Stack name cannot exceed 128 characters

Reproduction Steps

Steps to Reproduce:

  1. Create any CFN stack with name longer than 128 characters, not from AWS console, but using cdk construct. This is possible to do it with cdk constructs.
  2. Try to delete stack with aws cli:
    aws cloudformation delete-stack --stack-name {name}

Possible Solution

No response

Additional Information/Context

No response

CLI version used

aws --version aws-cli/1.20.6 Python/3.8.6 Darwin/21.3.0 botocore/1.21.7

Environment details (OS name and version, etc.)

sw_vers ProductName: macOS ProductVersion: 12.2.1 BuildVersion: 21D62

Activity

  1. added
    bug
    needs-triage
    on Apr 1, 2022
  2. removed
    needs-triage
    on Apr 1, 2022
  3. self-assigned this
    on Apr 1, 2022
  4. added
    investigating
    on Apr 1, 2022
  5. kdaily commented on Apr 1, 2022

    @kdaily
    Member

    Hi @ikhvostenkov,

    Thanks for writing. According to the CloudFormation CreateStack documentation, stack names are limited to 128 characters:

    StackName

    The name that's associated with the stack. The name must be unique in the Region in which you are creating the stack.
    

    Note

    A stack name can contain only alphanumeric characters (case sensitive) and hyphens. It must start with an alphabetical character and can't be longer than 128 characters.

    It looks like that would be a server side Validation error (if you provide --debug logs we can confirm), as the API does not model the length limitations for us to do validation on client side.

    I'll check in with the CDK team for some more information.

  6. kellertk commented on Apr 1, 2022

    @kellertk
    Member

    While it appears that CDK does not check for this at synthesis time,, I wasn't able to get a test stack deployed with a really long name:

    #!/usr/bin/env node
    import * as cdk from 'aws-cdk-lib';
    import { CdkTestStack } from '../lib/cdk-test-stack';
    
    const app = new cdk.App();
    new CdkTestStack(app, 'LookAtMyReallyLongStackNameThisStackNameIsLongerThan128CharactersThatIsNutsIDontThinkThereIsEnoughAWSAvailableToLetEveryoneHaveStackNamesThisLong');
    PS C:\Users\theto\Documents\GitHub\cdk-test> cdk deploy   
    
    ✨  Synthesis time: 8.85s
    
    
    Stack name cannot exceed 128 characters
    PS C:\Users\theto\Documents\GitHub\cdk-test>

    It will actually synth fine though. 🤔

    Edit: After some digging it looks like this error is coming right from the CloudFormation service API.

  7. added
    guidance
    and removed
    bug
    investigating
    on Apr 1, 2022
  8. peterwoodworth commented on Apr 1, 2022

    @peterwoodworth

    @ikhvostenkov I'm curious how you initially deployed the stacks (i.e. cdk deploy), and how long ago?

  9. added
    response-requested
    on Apr 1, 2022
  10. ikhvostenkov commented on Apr 1, 2022

    @ikhvostenkov
    Author

    @kdaily @peterwoodworth @kellertk Sorry, I confused you. I just checked the code and these stacks were created with JAVA SDK, not with cdk, by some reason I thought these stacks were created with cdk. Here is the code snippet:

    createStackRequest = CreateStackRequest.builder()
                .stackName({NAME})
                .templateBody({BODY})
                .roleARN({ROLE})
                .parameters(parameters)
                .build()
    
            cloudFormationClient.createStack(createStackRequest)
            ```
    
    These stacks were created ~ 6 months ago. I dropped everything, I can reproduce it later if required. 
    
  11. removed
    response-requested
    on Apr 1, 2022
  12. kdaily commented on Apr 2, 2022

    @kdaily
    Member

    Thanks @ikhvostenkov! I'll check with our Java team too, but since the error comes from the service, the Java SDK should now also error with the same response.

  13. ikhvostenkov commented on Apr 4, 2022

    @ikhvostenkov
    Author

    @kdaily I totally agree, that this is a bug in Java SDK, however, I think, this should be possible to delete any stack despite the stack's name length via AWS cli, as that might be other people having the same problem. And also this is possible to delete stack with name longer than 128 chars via AWS Console and then there is discrepancy between how AWS Console works and how AWS cli works.

  14. kdaily commented on Apr 4, 2022

    @kdaily
    Member

    Hi @ikhvostenkov,

    I'm checked with the Java team, and supplying a stack name greater than 128 characters fails with the following error, which is the same server side error received through the AWS CLI:

    software.amazon.awssdk.services.cloudformation.model.CloudFormationException: Stack name cannot exceed 128 characters (Service: CloudFormation, Status Code: 400, Request ID: e4ae2cb4-2433-4654-9baa-ef7b0a618bdd)
    

    I also tried to create a stack with the AWS console, which failed as well:

    Screen Shot 2022-04-04 at 1 06 13 PM

    So, I think I'll need to see how you can reproduce this issue with a longer stack name!

  15. kdaily commented on Apr 4, 2022

    @kdaily
    Member

    Just a heads up that I'm going to migrate this question to the AWS CLI GitHub discussions to continue our conversation. Thanks!

  16. locked and limited conversation to collaborators on Apr 4, 2022
  17. converted this issue into a discussion #6847 on Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

guidance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions