arabold / serverless-export-env

Serverless plugin to export environment variables into a .env file
MIT License
103 stars 34 forks source link

Using `provider.environment` as replacement for exporting outputs can lead to circular dependencies #58

Open btisdall opened 1 year ago

btisdall commented 1 year ago

Sorry if I'm missing somnething here but the suggested workaround for cases that previously used exported outputs is to make use of provider.environment can result in circular dependencies. Placing a reference in provider.environment of course this places the ref in all functions' environments and can lead to this situation:

Resource B [via environment] <-- Resource A <-- Resource B [referenced in provider.environment]

The hack I'm using to work around this is to create a dummy lambda purely to export Resouce B's reference:

  dummyHandler:
    handler: functions/dummy.handler
    environment:
      RESOURCE_B_REF: !Ref CognitoUserPool

Thus Resource A no longer depends on Resource B but the plugin is still able to aggregate the exports.

The above is pretty horrible and I would not use this in production but it unblocks me at a moment when I don't have time to use a new solution.