I don’t know whether this has been discussed befor...
# help
a
I don’t know whether this has been discussed before or not but how would I attempt blue-green deployments using HTTP APIs? I need this to perform A/B testing as well as to experiment with multiple microservices that might use different third-party services to achieve the same outcome. For ex: I could have a media service that uses mongodb atlas and another similar service that uses dynamodb. They might be the same service in code but their deployment needs to be such that I can redirect incoming traffic to use separate stages (I am assuming they have to be separate stages at least). Do you think this is achievable using SST, AWS APIGateway and lambda functions or do I need to setup custom loadbalancing to achieve this. I have heard people were using ECS with ALB to achieve this. Any guidance would be really appreciated as this makes life a lot simpler for me and my team.
t
Interesting question let me think about it
I probably would try to handle this at the application layer and not the infrastructure layer. So creating an adapters in my code for each of the methodologies you want to swap between and having application level rules (maybe randomizing?) to determine which to use. Doing at the infrastructure level is possible but I can't think of anything elegant
An inelegant way would be to define a lambda that then randomly calls a different lambda passing through the event
Another inelegant way is via DNS. Deploy two
sst.APIs
and set up cnames to them under the same dns. People will roughly 50/50 between them
a
I was already thinking of approaching the DNS way. The reason why I want them to run as separate services is so that I can manipulate them using env vars. The code would have both the adapters but one that would be used would be decided using env vars, this also helps me track my service usage individually.
t
Ah I see. Can you randomize it on the client side by having it be aware of two different api endpoints?
Unfortunately I don't think there's a servereless native way to do this. Probably would have to setup a load balancer in front of 2 api gateways to do this without DNS tricks or client side switching
a
oh! that’s an interesting suggestion. My frontend team will vote to fire me probably for suggesting this though. 😂 It could work. I was thinking of using ALB routes which are supported by HTTP APIs, I’m still figuring it out. I’ll see if I come across a better idea. Thank you.
s
If your services are just for lambda functions, then it is possible to use traffic splitting, based on the alias tags on the deployed lambdas. The default behaviour is that everything goes to latest, but you can configure a split ratio, to send traffic to different versions of the lambda. I don't know if the different versions can have separate environment config, but I expect so. I know that this is how AWS SAM enables canary releases of lambda functions, so it should theoretically be possible to maintain the same HTTP API routing. I am going to take a look at how this works with the cdk.