compose icon indicating copy to clipboard operation
compose copied to clipboard

Add compatibility with serverless-offline

Open throrin19 opened this issue 2 years ago • 5 comments

Is there an existing issue for this?

  • [X] I have searched existing issues, it hasn't been reported yet

Use case description

In a world where projects are becoming more and more complex, a realization following monorepo (lerna, nx, turborepo, workspaces, ...) becomes a prerequisite to facilitate their development.

In this case, we can end up with several modules using the same APIGateway for cost reasons but also to gather everything behind the same domain.

In order to facilitate the development, which can be quite tedious during the build and deployment of the different modules on AWS, it would be more than interesting to make serverless-compose compatible with serverless-offline.

In this way, we end up using the same local server, launching all the routes of the different modules, through a single command.

Using serverless-compose also allows to manage the prioritization of routes according to the dependencies between modules.

Would it be possible to bring compatibility (or use) of serverless-offline through compose?

Proposed solution (optional)

No response

throrin19 avatar Mar 09 '23 13:03 throrin19

@throrin19 for that to happen. I believe first this functionality will need to be integrated into Framework core (so it works in realm of the single process) and then eventually new version of serverless offline plugin could emerge out of that.

Unfortunately at this point, there's no work involved in this feature so I cannot provide any ETA on Framework core integration

medikoo avatar Mar 09 '23 13:03 medikoo

@medikoo thanks for your response. I understand the problem 😢

throrin19 avatar Mar 09 '23 15:03 throrin19

+1, I tried serverless-compose bc Cloudformation/Serverless does not currently support multiple Websocket APIs in the same service. Offline's incompatibility w/ Compose breaks existing workflow. I'll be mirroring my service to a second repo to workaround in the meantime, though I bemoan the code duplication

hustlerman avatar Mar 29 '23 23:03 hustlerman

This doesn't just relate to serverless-offline, but also many other plugins which might spawn offline test resources like serverless-s3-local or serverless-dynamodb-local.

darylteo avatar Apr 14 '23 04:04 darylteo

Terragrunt has a run-all command that can be used to run commands in all of a project's sub-modules. For example, you can run terragrunt run-all plan or terragrunt run-all apply to run the plan or apply command respectively in sub-modules.

I wonder if we could take a similar approach here instead of integrating all these various plugins into serverless-core. For example, we could implement a new serverless-compose command like serverless run-in-service --service <service> <command> that runs the supplied command within the context of the specified service, while also fetching and passing in the relevant parameters that are required in that service (and normally supplied by serverless-compose).

A full example of the command would be: serverless run-in-service --service frontend invoke-local --function search

The equivalent can be achieved by cding into the frontend service's subdirectory and using the serverless --param argument, and manually copying and pasting all the parameters that are normally supplied by serverless-compose - but this is obviously tedious and inefficient (especially once the project has grown to use several cross-service parameters). It would be better if serverless-compose could do this automatically. This is what the above run-in-service command would look like with this manual approach:

cd frontend
serverless invoke-local --function search --param="<serverless-compose param...>

This approach would provide the following benefits:

  • Extensible to additional plugins with no modification to the command's logic
  • Doesn't rely on plugins being integrated into serverless-core
  • Shouldn't be too complex from an implementation logic perspective

calebplum avatar Oct 14 '23 00:10 calebplum