The strangler pattern is a technique for refactoring an application with new functionality by wrapping the old logic in new logic. In the modern era of web apps this technique has been adapted to intercept HTTP traffic in new application code, use feature flags to turn on and off new functionality and otherwise proxy everything back to the original domain. A few years back Ceej pulled off an impressive migration from monolith to microservices using this technique at npm Inc.
Strangler but serverlessly
By using AWS API Gateway we can do the same thing and even better setting this up takes roughly 30 seconds total. This enables your dev team to pick off routes one by one and make them stateless functions. Or maybe we want to host a static app elsewhere and build the dynamic backend with Lambda.
Whatever the use case OpenJS Architect makes configuring this setup completely painless. Create an app.arc
file with the following configuration:
@app
myapp
@proxy
testing https://testing.brian.io
staging https://staging.brian.io
production https://brian.io
@http
post /graphql
And run arc init
to generate the app. You can deploy it to your own AWS account with arc deploy
or setup Begin for CI/CD. This app will proxy all traffic to my brian.io domain except post /graphql
for my backend code. Eventually I will probably want to move the static assets onto S3 and manage my own CloudFront too …but this can now happen at any time!
Top comments (0)