[{"data":1,"prerenderedAt":137},["ShallowReactive",2],{"content-paved-path-lift-and-shift-a-web-app-to-serverless-5-backend-migration":3},{"markdown":4,"frontMatterAttributes":5,"bodyRaw":9,"contributorPaths":10,"menuType":12,"contentName":13,"slug":14,"readingTime":15,"menu":16,"nextDocItem":70,"previousDocItem":56},"\u003Cp>Migrating the Node.js\u002FExpress backend is the most challenging of the layers to migrate to a serverless environment, as the server layer is a Node.js application that runs in a server.\u003C\u002Fp>\n\u003Cp>One option for this migration is to use \u003Ca href=\"https:\u002F\u002Faws.amazon.com\u002Ffargate\u002F\">AWS Fargate\u003C\u002Fa>. Fargate is a serverless container service that allows you to scale automatically and you pay as you go. Another option is to use \u003Ca href=\"https:\u002F\u002Faws.amazon.com\u002Fapprunner\u002F\">AWS AppRunner\u003C\u002Fa>, a container service that auto scales and you also pay as you go. However, neither of these options aligns with our migration requirements, as they don’t scale to zero.\u003C\u002Fp>\n\u003Cp>Another option for the lift and shift migration of this Node.js application is to use AWS Lambda with \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fawslabs\u002Faws-lambda-web-adapter\">AWS Lambda Web Adapter\u003C\u002Fa>. AWS Lambda Web Adapter is an open-source project that allows a Lambda function to behave as a web server by listening for incoming HTTP\u002FS requests, enabling you to build web applications on Lambda with familiar frameworks, like Express.js, Flask, SpringBoot. You can learn more about this project in its \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fawslabs\u002Faws-lambda-web-adapter\">GitHub repository\u003C\u002Fa>.\u003C\u002Fp>\n\u003Cimg src=\"\u002Fassets\u002Fexternal\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002Fassets\u002Frequests-to-lambda.png\"\u002F>\n\n\u003Cp>Using this project, you can create a new Lambda function that has the Express\u002FNodeJS application as the function code. You can lift and shift all the code into the function. If you want a step-by-step tutorial on how to do this, check out this video.\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-js\">const lambdaAdapterFunction = new Function(this,`${props.stage}-LambdaAdapterFunction`,\n    {\n        runtime: Runtime.NODEJS_16_X,\n        code: Code.fromAsset(&#39;backend-app&#39;),\n        handler: &#39;run.sh&#39;,\n        environment: {\n            AWS_LAMBDA_EXEC_WRAPPER: &#39;\u002Fopt\u002Fbootstrap&#39;,\n            REGION: this.region,\n            ASYNC_INIT: &#39;true&#39;,\n        },\n        memorySize: 1024,\n        layers: [layerLambdaAdapter],\n        timeout: Duration.seconds(2),\n        tracing: Tracing.ACTIVE,\n    }\n);\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>The next step is to create an HTTP endpoint for the server application. There are three options for doing this: \u003Ca href=\"https:\u002F\u002Faws.amazon.com\u002Fapi-gateway\u002F\">API Gateway\u003C\u002Fa>, \u003Ca href=\"https:\u002F\u002Faws.amazon.com\u002Felasticloadbalancing\u002Fapplication-load-balancer\u002F\">Application Load Balancer (ALB)\u003C\u002Fa> , or to use \u003Ca href=\"https:\u002F\u002Fdocs.aws.amazon.com\u002Flambda\u002Flatest\u002Fdg\u002Flambda-urls.html\">Lambda Function URLs\u003C\u002Fa>. All the options are compatible with Lambda Web Adapter and can solve the challenge for you.\u003C\u002Fp>\n\u003Cp>For this demo, we will choose function URLs as they are simple to configure and one function URL forwards all routes to the Express server. API Gateway and ALB require more configuration and have separate costs, while the cost of function URLs is included in the Lambda function.\u003C\u002Fp>\n",{"title":6,"order":7,"youtubeVideoID":8},"Backend migration",5,"MvVaFPCdiZY","Migrating the Node.js\u002FExpress backend is the most challenging of the layers to migrate to a serverless environment, as the server layer is a Node.js application that runs in a server.\n\nOne option for this migration is to use [AWS Fargate](https:\u002F\u002Faws.amazon.com\u002Ffargate\u002F). Fargate is a serverless container service that allows you to scale automatically and you pay as you go. Another option is to use [AWS AppRunner](https:\u002F\u002Faws.amazon.com\u002Fapprunner\u002F), a container service that auto scales and you also pay as you go. However, neither of these options aligns with our migration requirements, as they don’t scale to zero.\n\nAnother option for the lift and shift migration of this Node.js application is to use AWS Lambda with [AWS Lambda Web Adapter](https:\u002F\u002Fgithub.com\u002Fawslabs\u002Faws-lambda-web-adapter). AWS Lambda Web Adapter is an open-source project that allows a Lambda function to behave as a web server by listening for incoming HTTP\u002FS requests, enabling you to build web applications on Lambda with familiar frameworks, like Express.js, Flask, SpringBoot. You can learn more about this project in its [GitHub repository](https:\u002F\u002Fgithub.com\u002Fawslabs\u002Faws-lambda-web-adapter).\n\n\u003Cimg src=\"\u002Fassets\u002Fexternal\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002Fassets\u002Frequests-to-lambda.png\"\u002F>\n\nUsing this project, you can create a new Lambda function that has the Express\u002FNodeJS application as the function code. You can lift and shift all the code into the function. If you want a step-by-step tutorial on how to do this, check out this video.\n\n```js\nconst lambdaAdapterFunction = new Function(this,`${props.stage}-LambdaAdapterFunction`,\n    {\n        runtime: Runtime.NODEJS_16_X,\n        code: Code.fromAsset('backend-app'),\n        handler: 'run.sh',\n        environment: {\n            AWS_LAMBDA_EXEC_WRAPPER: '\u002Fopt\u002Fbootstrap',\n            REGION: this.region,\n            ASYNC_INIT: 'true',\n        },\n        memorySize: 1024,\n        layers: [layerLambdaAdapter],\n        timeout: Duration.seconds(2),\n        tracing: Tracing.ACTIVE,\n    }\n);\n```\n\nThe next step is to create an HTTP endpoint for the server application. There are three options for doing this: [API Gateway](https:\u002F\u002Faws.amazon.com\u002Fapi-gateway\u002F), [Application Load Balancer (ALB)](https:\u002F\u002Faws.amazon.com\u002Felasticloadbalancing\u002Fapplication-load-balancer\u002F) , or to use [Lambda Function URLs](https:\u002F\u002Fdocs.aws.amazon.com\u002Flambda\u002Flatest\u002Fdg\u002Flambda-urls.html). All the options are compatible with Lambda Web Adapter and can solve the challenge for you.\n\nFor this demo, we will choose function URLs as they are simple to configure and one function URL forwards all routes to the Express server. API Gateway and ALB require more configuration and have separate costs, while the cost of function URLs is included in the Lambda function.\n\n",[11],"content\u002Fcontributors\u002Fmarcia-villalba.json","LESSON","Lift and shift a web app to serverless","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F5-backend-migration","2 min",[17,36,46,54,63,68,77,87,96,105,113,122,130],{"title":18,"content":19},"Introduction",[20],{"title":18,"order":21,"youtubeVideoID":22,"learningGoals":23,"resources":28,"time":15,"path":33,"id":34,"link":35},1,"O-hSs7aF7JE",[24,25,26,27],"Understand what lift and shift migrations are","Understand the benefits of serverless architecture","Learn how to migrate applications and databases from serverful to serverless","Learn patterns for migrating your services onto AWS.",[29],{"link":30,"text":31,"type":32},"https:\u002F\u002Fblog.marcia.dev\u002Flift-and-shift-a-web-app-to-serverless#heading-requirements-for-migration","Lift and shift to Serverless","text","1-introduction","1-introduction.md","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F1-introduction",{"title":37,"content":38},"Guide",[39],{"title":40,"order":41,"time":42,"path":43,"id":44,"link":45},"Requirements for migration",2,"1 min","2-requirements-for-migration","2-requirements-for-migration.md","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F2-requirements-for-migration",{"title":-1,"content":47},[48],{"title":49,"order":50,"time":42,"path":51,"id":52,"link":53},"Application overview",3,"3-application-overview","3-application-overview.md","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F3-application-overview",{"title":-1,"content":55},[56],{"title":57,"order":58,"youtubeVideoID":59,"time":42,"path":60,"id":61,"link":62},"Database migration",4,"Mic2TGzzVXk","4-database-migration","4-database-migration.md","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F4-database-migration",{"title":-1,"content":64},[65],{"title":6,"order":7,"youtubeVideoID":8,"time":15,"path":66,"id":67,"link":14},"5-backend-migration","5-backend-migration.md",{"title":-1,"content":69},[70],{"title":71,"order":72,"youtubeVideoID":73,"time":15,"path":74,"id":75,"link":76},"Web app migration",6,"gQn4XPfpdZE","6-webapp-migration","6-webapp-migration.md","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F6-webapp-migration",{"title":-1,"content":78},[79],{"title":80,"order":81,"youtubeVideoID":82,"time":83,"path":84,"id":85,"link":86},"Authentication and authorization migration",7,"KRnZvbVT7uk","3 min","7-authentication-and-authorization-migration","7-authentication-and-authorization-migration.md","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F7-authentication-and-authorization-migration",{"title":-1,"content":88},[89],{"title":90,"order":91,"youtubeVideoID":92,"time":15,"path":93,"id":94,"link":95},"Storage migration",9,"Z4frDpp4PcM","8-storage-migration","8-storage-migration.md","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F8-storage-migration",{"title":-1,"content":97},[98],{"title":99,"order":100,"youtubeVideoID":101,"time":42,"path":102,"id":103,"link":104},"Testing this application",11,"U_7xD-o5mCA","9-testing-this-application","9-testing-this-application.md","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F9-testing-this-application",{"title":-1,"content":106},[107],{"title":108,"order":109,"youtubeVideoID":101,"time":15,"path":110,"id":111,"link":112},"How much does this application cost?",12,"10-pricing-of-migrated-application","10-pricing-of-migrated-application.md","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F10-pricing-of-migrated-application",{"title":-1,"content":114},[115],{"title":116,"order":117,"youtubeVideoID":118,"time":83,"path":119,"id":120,"link":121},"Performance analysis",13,"B0pDPSQcAf4","11-performance-analysis","11-performance-analysis.md","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F11-performance-analysis",{"title":-1,"content":123},[124],{"title":125,"order":126,"time":42,"path":127,"id":128,"link":129},"Conclusion",14,"12-conclusion","12-conclusion.md","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F12-conclusion",{"title":-1,"content":131},[132],{"title":133,"order":117,"time":42,"path":134,"id":135,"link":136},"Extra resources","13-extra-resources","13-extra-resources.md","\u002Fcontent\u002Fpaved-path\u002Flift-and-shift-a-web-app-to-serverless\u002F13-extra-resources",1792665265252]