This example shows how to use Lambda Adapter to run an Remix application on AWS Lambda.
The Remix application is created using the following command:
npx create-remix@latest --template remix-run/remix/templates/express
We add Lambda Adapter layer to the function and configure wrapper script.
- attach Lambda Adapter layer to your function. This layer containers Lambda Adapter binary and a wrapper script.
- x86_64:
arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerX86:23
- arm64:
arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerArm64:23
- x86_64:
- configure Lambda environment variable
AWS_LAMBDA_EXEC_WRAPPER
to/opt/bootstrap
. This is a wrapper script included in the layer. - set function handler to a startup command:
run.sh
. The wrapper script will execute this command to boot up your application.
To get more information of Wrapper script, please read Lambda documentation here.
Run the following commands to build and deploy the application to lambda. SAM CLI will use GNU Make to build the Remix application.
sam build
sam deploy --guided
When the deployment completes, take note of RemixFunctionApi's Value. It is the API Gateway endpoint URL.
Open RemixFunctionApi's URL in a browser, you should see the "Weclome to Remix" page.
In general, you can test your web app locally without simulating AWS Lambda execution environment. But if you want to simulate Lambda and API Gateway locally, you can use SAM CLI.
sam local start-api --warm-containers EAGER --region us-west-2
This command will start a local http endpoint and docker container to simulate API Gateway and Lambda. Please modify the region to match the actual region you are using. You can test it using curl
, postman
, and your web browser.