Search code examples
serverless-framework

How to run custom code to parse a string in serverless.yaml?


I am using the fantastic tool serverless and the useDotenv: true config.

I am loading .env file like:

app_url: https:/www.example.com

and can use it perfectly fine by referring to it ${env:app_url}

Now I don't want to use this variable but extract only the host out of this value something like extractHost(${env:app_url})

Can I declare nodejs code inside serverless.yaml to run later or make some custom extension to do it ?


Solution

  • It is possible to do it by writing custom variable resolvers in a plugin as described here: https://www.serverless.com/framework/docs/guides/plugins/custom-variables

    Great example of a plugin that does just that can be found here: https://github.com/whardier/serverless-plugin-powertools