Home » Find out how to Use the Strangler Fig Sample in Serverless Stack | by Julien Bras | Jan, 2023

Find out how to Use the Strangler Fig Sample in Serverless Stack | by Julien Bras | Jan, 2023

by Icecream
0 comment

A Strangler Fig
Picture by David Clode on Unsplash

I’m presently engaged on the structure of a brand new challenge for my firm. This new challenge have to be suitable with a historic monolith, then prolong it. It’s a typical case to rewrite an present software with the fashionable toolkit.

Martin Fowler was describing in an article again in 2004 a solution to slowly change a monolith by a brand new product: the Strangler Fig Sample. The primary benefit: a gradual migration, one endpoint by one endpoint, not a bigbang. This sample is definitely extensively used when refactoring an software to micro-services for instance.

From Microsoft Study

SST is a serverless framework that helps construct fullstacks purposes. On my new challenge, I wish to make the most of this framework (it’s a basic piece of our toolkit these days!), however I wish to change an software, not create a brand new one. So the Strangler Match Sample appears fairly enticing.

Based mostly on AWS reInvent presentation (Youtube video hyperlink right here), I used to be satisfied to make use of an API Gateway with the ANY /{proxy+} to facade the applying:

From AWS Presentation, Migrating monolithic purposes with the strangler sample

Ranging from there I’ve tried to simulate a monolith software (represented by a ApplicationLoadBalancedFargateService CDK assemble in my challenge). The implementation of the monolith shouldn’t be essential, I simply depend on the Software Load Balancer (there’s a 99% probability you will have such a service in case your monolith is hosted on AWS, both on EC2 or ECS!).

Right here is my monolith in CDK:

const loadBalancedFargateService = new ApplicationLoadBalancedFargateService(
stack,ty
"Service",
{
propagateTags: PropagatedTagSource.SERVICE,
memoryLimitMiB: 1024,
desiredCount: 1,
cpu: 512,
taskImageOptions: {
picture: ContainerImage.fromRegistry("nginxdemos/howdy"),
},
publicLoadBalancer: false,
}
);

The demo, it’s utilizing a quite simple docker picture, nginxdemos/howdy .

Then SST is permitting me to make use of the identical {proxy+} within the API routes:

const api = new Api(stack, "api", {
routes: {
"GET /": "capabilities/lambda.handler",
"ANY /{proxy+}": {
sort: "alb",
cdk: {
albListener: loadBalancedFargateService.listener,
},
},
},
});

And voilà, I can construct new routes with SST, and all routes not specified within the routes prop might be dealt with by the previous software declared within the ApplicationLoadBalancedFargateService.

The route / is answered by my lambda.handler perform:

Some other routes are answered by my monolith:

You may also like

Leave a Comment