Search code examples
serverless-framework

Read the package.json name in the serverless.yml


Instead of manually defining the service name in serverless.yml I'd like to read the name from the package.json


Solution

  • To achieve a dynamic service name based on the package.json app name I took advantage of the variable import Serverless Framework feature.

    https://www.serverless.com/framework/docs/providers/aws/guide/variables/#reference-variables-in-javascript-files

    This loads the file package.json and specifies that the name property should be applied to the service entry.

    # serverless.yml
    service: ${file(./package.json):name}