This repository demonstrates how to move legacy applications to the cloud using cloud-native tools, showcasing multiple deployment options for a Node.js Express application.
Related blog post (in Hebrew) - https://pashut.cloud/lift-and-shift-app-runner-part-1
-
legacy-app/ - Contains the Express application that lists AWS Lambda functions
index.mjs
- Main application codeDockerfile
- Container definition for the applicationpackage.json
- Node.js dependencies and scripts
-
apprunner/ - Contains AWS App Runner deployment configuration
app-runner-service.yaml
- CloudFormation template for deploying to App Runnercreate-role.yaml
- CloudFormation template for creating necessary IAM roles
-
lwa/ - Contains AWS Lambda Web Adapter configuration
Dockerfile
- Extends the legacy app image and adds Lambda Web Adaptertemplate.yaml
- SAM template for deploying as a Lambda function
- Node.js (v20 or later)
- Docker
- AWS CLI configured with appropriate credentials
- AWS SAM CLI (for Lambda deployment)
- AWS account with permissions to:
- Create and push to ECR repositories
- Deploy CloudFormation stacks
- Create App Runner services and Lambda functions
- List Lambda functions
-
Navigate to the legacy app directory:
cd legacy-app
-
Install dependencies:
npm ci
-
Start the application:
npm start
-
Access the application at http://localhost:3000/lambdas
-
Build the Docker image:
cd legacy-app npm run build
-
Run the Docker container:
npm run docker:start
-
Access the application at http://localhost:3000/lambdas
The application includes scripts to deploy to AWS App Runner using the CloudFormation templates in the apprunner/
directory.
-
First, create the ECR repository (if you haven't already):
aws cloudformation deploy --template-file legacy-app/template.yaml --stack-name lambda-list-app-ecr
-
Deploy the application to AWS:
cd legacy-app npm run aws:deploy
This command performs the following actions:
- Builds the Docker image (
npm run build
) - Authenticates with AWS ECR (
npm run aws:authenticate
) - Tags and pushes the image to ECR (
npm run aws:push
)
- Builds the Docker image (
-
Deploy the App Runner service:
aws cloudformation deploy --template-file apprunner/app-runner-service.yaml --stack-name lambda-list-app-apprunner --capabilities CAPABILITY_NAMED_IAM
After deployment, you can find the App Runner service URL in the AWS Console or by checking the CloudFormation stack outputs.
The application can also be deployed as an AWS Lambda function using the AWS Lambda Web Adapter.
- The Dockerfile in the
lwa
directory extends the existinglambda-list-app
Docker image and adds the Lambda Web Adapter. - The SAM template (
template.yaml
) defines an AWS Lambda function that uses this Docker image and configures a Lambda URL for HTTP access.
-
First, ensure the base Docker image is built:
cd legacy-app npm run build
-
Then deploy the Lambda function using SAM:
cd lwa sam build sam deploy --guided
During the guided deployment, you can set a stack name and choose your region. SAM will package and deploy the function to AWS Lambda and create a Lambda URL.
After deployment, SAM will output the Lambda Function URL. You can test the API endpoints using this URL:
- Health check:
<function-url>/health-check
- List Lambda functions:
<function-url>/lambdas
To remove the deployed Lambda resources:
sam delete
- The Lambda function is configured with 512MB of memory and a 30-second timeout. You can adjust these values in the template.yaml file if needed.
- The AWS Lambda Web Adapter automatically handles the translation between HTTP requests and Lambda invocations.