getlift / lift

Expanding Serverless Framework beyond functions using the AWS CDK
MIT License
912 stars 109 forks source link

Fails to automatically truncate and uniquify long generated names #347

Open tomchiverton opened 1 year ago

tomchiverton commented 1 year ago

Description

In main Serverless, if a resource name ends up being too long, it's truncated and made unique e.g. 'my-long-name-trunc-H6E8'

Constructs do not appear fo this for their workers, so deployments of projects with "too long" service and/or stage and/or resource (type: queue) names fails.

How to Reproduce

sls deploy --stage the-stage-name

service: something-service

constructs:
    pdf-email-send-queue-no-vpc:
    type: queue
    worker:
        handler: pdfEmail.emailSender

Additional Information

✖ Stack something-service-the-stage-name failed to deploy (218s)
Environment: linux, node 18.16.1, framework 3.19.0 (local) 3.25.1v (global), plugin 6.2.2, SDK 4.3.2
Credentials: Local, "something-serverless-dev" profile
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
CREATE_FAILED: PdfDashemailDashsendDashqueueDashnoDashvpcWorkerLambdaFunction (AWS::Lambda::Function)
Resource handler returned message: "1 validation error detected: Value 'something-service-the-stage-name-pdf-email-send-queue-no-vpcWorker' at 'functionName' failed to satisfy constraint: Member must have length less than or equal to 64 (Service: Lambda, Status Code: 400, Request ID: 44d3a373-b40e-4192-ba9b-9ec1a3a30fb5)" (RequestToken: 8caf219f-3128-0f61-2e61-45ba0b7271a4, HandlerErrorCode: InvalidRequest)
fredericbarthelet commented 12 months ago

Thanks for reporting this issue @tomchiverton. To my knowledge, there is no mechanism to automatically trim long resource name in the Serverless framework packaging process. That is one of the reason for the existence of the name property, available in lambda function definition in the service file definition (see https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/#functions).

The following exemple service file, using solely core serverless framework (not this plugin), results in the exact same error:

# serverless.yml

service: myService

provider:
  name: aws
  runtime: nodejs14.x

functions:
  myVeryVeryLongAndDefinitelyOverTheLimitOfSixtyFourCharsFunctionName:
    handler: handler.index

Could you let me know which trimming logic you're referring to ?

On the other hand, the AWS CDK, used within Lift, to provision all non-Lambda function resources, does indeed handle resource name generation to guarantee those generated strings are within services constraints.

Finally, you can use any property existing within Serverless framework documentation in the worker property of the queue construct. You can therefore refer to worker.name property, defining a short acceptable name, to bypass this problem.

service: something-service

constructs:
    pdf-email-send-queue-no-vpc:
    type: queue
    worker:
        handler: pdfEmail.emailSender
        name: short-name
tomchiverton commented 11 months ago

I think I was thinking of things like the S3 deploy bucket name being truncated.

That work around is a handy trick.