question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

After upgrading to cdk v2, getting Stack name must be <= 128 characters

See original GitHub issue

Describe the bug

I have been using cdk with version 1.147.1, and my cdk apps were successfully deployed. After upgrading to cdk v2, I cant deploy my cdk app, getting “Stack name must be <= 128 characters” error message.

Looking at the stack name it tried to create, I cant understand what is going on, why is this name generated when I have provided a short logical id to all my resources and to the stack name itself.

I have a construct that exports an existing eks cluster (code is simplified just for example)

class EksCluster(Construct):
    def __init__(
        self,
        scope: Construct,
        stack_name: str,
        stage: str,
    ) -> None:
        super().__init__(scope, stack_name)
       self.cluster = self.import_cluster()

    def import_cluster(self) -> aws_eks.ICluster:
        return aws_eks.Cluster.from_cluster_attributes(
            self,
            id="imported-eks-cluster",
            cluster_name=cluster_name,
            kubectl_role_arn=kubectl_role_arn,
            open_id_connect_provider=open_id_provider,
            vpc=vpc,
        )

Then a simple app.py with the cdk app

app = App()
aws_lb_controller_stack = AwsLBControllerStack(
    app,
    f"aws-load-balancer-controller-{STAGE}",
    stage=STAGE,
    cluster_config=cluster_config,
    env=Environment(region=REGION, account=ACCOUNT),
)
app.synth()

And finally the stack itself, that uses the construct to use the eks cluster and create a service account for example

class AwsLBControllerStack(Stack):
    def __init__(
        self,
        scope: Construct,
        construct_id: str,
        stage: str,
        cluster_config: dict,
        **kwargs,
    ) -> None:
        super().__init__(scope, construct_id, **kwargs)
        self.eks_cluster = EksCluster(self, "eks-cluster", stage=stage)
        service_account = self.eks_cluster.cluster.add_service_account(
            "aws-lb-controller-service-account",
            name=AWS_LB_CONTROLLER_SERVICE_ACCOUNT_NAME,
            namespace=AWS_LB_CONTROLLER_NAMESPACE,
        )

This worked fine on cdk v1.147.1, but now after upgrading the cdk version and trying to deploy this code, it returns the following error:

jsii.errors.JSIIError: Stack name must be <= 128 characters. Stack name: 'awsloadbalancercontrollersandboxzolaawsloadbalancercontrollersandboxzolaeksclusterimportedeksekscluster980273B4KubectlProviderC92A5312'

Can you please explain what generated such a long name? And most importantly, how can this be fixed?

Expected Behavior

Stack names should be short and understandable like they are defined in their logical ids, and most importantly it should allow me to deploy my cdk app without generating the name and then not allowing me to deploy when I did not define such name anywhere in the app.

Current Behavior

Stack names are generated with multiple duplicates inside and just unreadable names.

Reproduction Steps

Posted above a simple setup in python

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.21.1

Framework Version

No response

Node.js Version

v17.9.0

OS

macOS monterey 12.3.1

Language

Python

Language Version

3.10.2

Other information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
comcalvicommented, May 25, 2022

Thanks @michaelsatish, that reproduces the issue. I’ll be working on a fix for this asap.

0reactions
github-actions[bot]commented, Jul 12, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting common AWS CDK issues
You must then delete the resource manually after the stack is destroyed. Until you do, redeploying the stack fails. This is because the...
Read more >
ValidationError Stack:arn aws cloudformation stack is in ...
This happens when stack creation fails. By default the stack will remain in place with a status of ROLLBACK_COMPLETE .
Read more >
CloudFormation — Boto3 Docs 1.26.36 documentation
A stack name can contain only alphanumeric characters (case-sensitive) and hyphens. It must start with an alphabetic character and can't be longer than...
Read more >
awscdk - Go Packages
AWS Cloud Development Kit Library. The AWS CDK construct library provides APIs to define your CDK application and add CDK constructs to the...
Read more >
aws-cdk | Yarn - Package Manager
Cluster is allowed per CloudFormation stack. eks: The securityGroups attribute of ClusterAttributes is now securityGroupIds . cli: --qualifier must be ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found