Open chris-hinds opened 2 years ago
We would absolutely use a feature like this if it supported conditions based on region. At the moment we are doing this with environment variables, so as long as --region
isn't supported by serverless compose it would be great if something like if: ${env:region} == 'ap-southeast-2'
was also possible.
@tom-dq very interesting, thank you for providing another use case. That will be helpful if we start working on that to make sure the syntax/feature supports this.
To anyone reading this: I'd be interested to learn more about your use case. So far the typical use case we have is: "deploy service X only in production".
Let us know if you have other use cases.
We have a use case where we only need specific infrastructure deployed in one region. We currently do this by deploying our services separately with GH actions. It would be awesome to be able to define services that are only used in X regions. An example for us is our auth service which manages and contains our Cognito instance and some related hooks, which we currently maintain in one region and share.
Thanks @mnapoli - after reading @Hawki101's comment I should say, if serverless compose could natively support multi-region deploys, that would be a next-level developer experience for us. We have an architecture where most of the services are in multiple regions, but a few are global. So a great implementation for us would be:
I'm not sure if this has crept beyond the scope of the original issue - sorry if it has!
Yeah, this would be a better solution for us rather than deploying compose multiple times across regions and conditionally deploying services.
I was also thinking about having a service/stack in my Compose file, that would allow to do deploy a feature branch for some infrastructure. I obviously do not want the feature branch to run on normal PRs or merges, but thinking about running it when someone commits to a branch named feature*
that I could just pass in as the stage
name.
I would also like to maybe append to the initial request because I could use this same IF
statement so that I can conditionally deploy a stack as a feature branch.
In my application, I'm using an authoriser Lambda function specifically for non-prod environments. Since this function is deployed as a Lambda@Edge it needs to be in us-east-1 which is a different region to the rest of my application, so it must be in a separate Serverless stack from the rest of my application.
I use serverless-compose to orchestrate these two stacks. It passes the authoriser's ARN to my main stack so that it can be attached to the Cloudfront distribution in my non-prod environments.
Since my production environment is public it doesn't need the authoriser function. This is a challenge in serverless-compose without conditional logic.
My current workaround involves deploying the authoriser function to all environments (including production) and using Cloudformation logic in the main application's Serverless service to prevent the authoriser from being attached in the production environment.
I tried using the serverless-plugin-conditional-functions plugin to deploy the authoriser function only in non-prod environments, but it's not possible to deploy the application to production in this way because Serverless complains about the missing parameter (since the ARN of the authoriser function doesn't exist in the production environment)
Having conditional logic available in serverless-compose would significantly simplify and this architecture and make it more efficient.
Use case description
Right now if you want to conditionally deploy infrastructure say based on the stage you need to add a conditional to each resource is your serverless config files.
If you are using serverless compose it would make this much easier as a single top-level conditional could skip the service deployment.
Proposed solution