thoreinstein / serverless-offline-ssm

Read SSM parameters from a .env file instead of AWS
MIT License
94 stars 24 forks source link

Serverless 3 Breaking Change? #255

Open jdesrochers opened 2 years ago

jdesrochers commented 2 years ago

The serverless-offline-ssm works fine with Serverless 2. However, it doesn't seem to work with Serverless 3. The following serverless.yml has the important snippets for the problem that we are seeing. This works with version 2 but not 3.

plugins:
  - serverless-offline-ssm
  - serverless-offline

custom
  stages:
    - local
    - dev
    - staging
    - production
  myTest:
    local: 'local value'
    dev: ${ssm:DEVELOPMENT.MY_TEST}
    staging: ${ssm:STAGING.MY_TEST}
    production: ${ssm:PRODUCTION.MY_TEST}
  serverless-offline-ssm:
    stages:
      - local
    ssm:
      'DEVELOPMENT.MY_TEST': 'dev value'
      'STAGING.MY_TEST': 'staging value'
      'PRODUCTION.MY_TEST': 'production value'

To start we use the following

sls offline -s local

Then we get this error

TypeError: Cannot read property 'find' of undefined
    at new ServerlessOfflineSSM (.../node_modules/serverless-offline-ssm/dist/index.js:57:18)
    at PluginManager.addPlugin (.../node_modules/serverless/lib/classes/plugin-manager.js:88:28)
    at .../node_modules/serverless/lib/classes/plugin-manager.js:134:69
    at Array.forEach (<anonymous>)
    at PluginManager.loadAllPlugins (.../node_modules/serverless/lib/classes/plugin-manager.js:134:44)
    at async Serverless.init (.../node_modules/serverless/lib/serverless.js:137:5)
    at async .../node_modules/serverless/scripts/serverless.js:530:7

Line 57 has the following

            this.ssmResolver = serverless.variables.variableResolvers
                .find(({ serviceName }) => serviceName === 'SSM');

The issue is that variableResolvers doesn't seem to exist in serverless 3. This works fine with serverless 2. Have not been able to find what the exact change was in serverless 3 or I would have looked at a PR option.

kgonyon commented 2 years ago

I am also having this issue. I downgraded to serverless 2.72.3 for the time being, but for obvious reasons I don't want to keep it that way. Any work to fix this issue would be appreciated. I don't know much about writing plugins for serverless otherwise I would take a stab at it.

cmendes0101 commented 2 years ago

There looks to be a workaround for now. I was able to get this working on my setup to keep version 3: https://github.com/janders223/serverless-offline-ssm/issues/191

jponc commented 2 years ago

I've updated to serverless-offline-ssm v6.1.0 but I'm still getting errors.

Environment: darwin, node 14.19.0, framework 3.7.5 (local), plugin 6.1.5, SDK 4.3.2
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
TypeError: Plugin is not a constructor
    at PluginManager.addPlugin (/Users/julianalfonsoponce/xxxx/node_modules/serverless/lib/classes/plugin-manager.js:93:28)

I then added some logging and found out that ServerlessOfflineSSM is wrapped in a default key compared to other Plugin

[class AwsCompileCloudFrontEvents]
[class HttpApiEvents]
[class AwsDeployFunction]
[class AwsDeployList]
[class AwsInvokeLocal]
[class Standalone]
{ default: [class ServerlessOfflineSSM] } <<<<<<<<<<<<<<<<<<< this one

I've added console.log within addPlugin function of PluginManager class

gustavopedroni commented 2 years ago

I think the export default ServerlessOfflineSSM ended up breaking the plugin, maybe should be replaced to export = ServerlessOfflineSSM. 😥😮‍💨

I'll do some tests and then do the PR fixing the problem.

Update: Follow the PR with the fix: https://github.com/janders223/serverless-offline-ssm/pull/266

jponc commented 2 years ago

@gustavopedroni thanks for the updates mate 🎉 🚀