July 06, 2019 / 4 minutes / #AWS #Serverless #ELB #EC2 #ALB
With this particular PR included in version
1.45, the Serverless Framework team has finally enabled a possibility of using Application Load Balancers as event source instead of using API Gateway.
We've heard few of stories where replacing costful API Gateway with ALB has saved thousands of dollars and it's really awesome but here I'd like to talk about another aspect which might be really helpful in migrations:
Imagine following scenario: your company wants to migrate from ECS/EC2 to Lambda by stripping monolith web server route by route. It appears that such thing can be achieved easily with multiple target groups associated with Load Balancer. Instead of just one, you can specify many of them and basing on request paths (or whatever you like) route requests to EC2/ECS or to Lambda.
Reference supplement CloudFormation files in main
http event with
alb where you specify which Load Balancer, Condition and Priority. In this case all requests to path
/lambda will be routed to Serverless solution. Rest of them will be routed to the EC2 based on rule specified here
One thing worth noting here is that Lambda priority should be bigger than server's, so it should look something like this:
If you want to check fully working example, the source code can be found here
Just run it with: