serverless-nextjs / serverless-next.js

⚑ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
MIT License
4.44k stars 451 forks source link

Allow pages names to have a length greater than 64. #58

Closed ulysset closed 5 years ago

ulysset commented 5 years ago

Hi, Thanks again for this super cool library. Currently when I create a page with the name /co2-emissions-per-capita it maps to a Lambda function with the name : tsp-data-portal-v2-client-production-co2-emissions-per-capitaPage which is longer than 64 characters so sls won't upload it :

An error occurred: Co2DashemissionsDashperDashcapitaPageLambdaFunction - 1 validation error detected: Value 'tsp-data-portal-v2-client-production-co2-emissions-per-capitaPage' at 'functionName' failed to satisfy constraint: Member must have length less than or equal to 64 (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: 96b996e3-6ce0-11e9-bdb8-e754b5f7535f).

For the moment I can just rename my service with a shorter name so that it leaves space for page naming. Maybe in the future, it will create problems for others.

The solution I see is creating a hash of the page name but it won't be human readable anymore...

Cheers

danielcondemarin commented 5 years ago

I don't like the idea of using a hash for the page name as this will affect discoverability of the page functions.

The default lambda name is {serviceName}-{stage}-{pageName}. A solution would be to provide a config key in the plugin which allows you to change the page name prefix:

For example:

custom:
  serverless-nextjs:
    nextConfigDir: "./"
    pageNamePrefix: "tsp-${self:provider:stage}"

Which would result in shorter lambda function names: tsp-production-co2-emissions-per-capitaPage

Should be possible to implement this using the optional name field for functions as documented here

ulysset commented 5 years ago

Thanks again @danielcondemarin This seems nice! Your solution is way better than a hash indeed.

stan-sack commented 5 years ago

@danielcondemarin can we please explore some other solutions for this. I'm using relay modern which generates folders as follows: ./__generated__/<queryname>.graphql.js which is like 20 characters of just boilerplate naming. It makes it basically impossible to stay under the character limit. Maybe the hash could be an optional custom config? Maybe we can specify a custom alias for long names so they are still identifiable?

I'm happy to make the changes if we can decide on a solution.

stan-sack commented 5 years ago

Something like this maybe: https://github.com/danielcondemarin/serverless-nextjs-plugin/pull/122/files?

mattdell commented 5 years ago

I've also run into this using descriptive dynamic endpoints. I've shorted it for now but will be good to think about a longer term solution.

danielcondemarin commented 5 years ago

Hi folks πŸ‘‹ I've recently released the next iteration of this project https://github.com/danielcondemarin/serverless-next.js/tree/master/packages/serverless-nextjs-component which solves this particular problem! Sorry it would mean migrating over to it, but I truly think it is worth it πŸš€Any issues please let me know πŸ‘