Skip to content

aws-lambda: function description length is not validated #20475

@Gtofig

Description

@Gtofig

Describe the bug

Lambda function description has length limit of 256 characters, but it is not currently validated by CDK

Expected Behavior

Lambda function description length should be validated at build time and build should fail if length is above 256 char limit

Current Behavior

Lambda function description length is not validated and issue will be caught at deployment time

Reproduction Steps

    const stack = new cdk.Stack();
    new lambda.Function(stack, 'MyFunction', {
      code: lambda.Code.fromInline('foo'),
      runtime: lambda.Runtime.NODEJS_14_X,
      handler: 'index.handler',
      description: 'a'.repeat(257),
    });

Possible Solution

Validate description length:

    if (props.description && !Token.isUnresolved(props.description)) {
      if (props.description.length > 256) {
        throw new Error(`Function description can not be longer than 256 characters but has ${props.description.length} characters.`);
      }
    }

Additional Information/Context

No response

CDK CLI Version

2.21.1

Framework Version

No response

Node.js Version

v14.19.1

OS

Ubuntu 20

Language

Typescript

Language Version

3.8.3

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-lambdaRelated to AWS Lambdaeffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions