### Start Express.js Server Locally Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/sqs-expressjs/README.md Navigate to the application's source directory, install dependencies, and start the Express.js server locally for testing. ```shell cd app/src npm install node index.js ``` -------------------------------- ### Run Unit Tests with NPM Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/nextjs-zip/README.md Install dependencies and run unit tests using NPM. This example assumes tests are defined in the 'hello-world/tests' folder and uses the Mocha test framework. ```bash nextjs-zip$ cd hello-world hello-world$ npm install hello-world$ npm run test ``` -------------------------------- ### Install Dependencies and Activate Virtual Environment Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/bedrock-agent-fastapi/README.md Sets up a Python virtual environment, activates it, and installs project dependencies from requirements.txt. ```shell python3 -m venv .venv source .venv/bin/activate pip install -r app/requirements.txt cd app/ ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/sls/nestjs/README.md Install the project dependencies using pnpm or npm. ```bash pnpm install ``` -------------------------------- ### Start Local API with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/nextjs-zip/README.md Emulate your application's API locally by running the 'sam local start-api' command. This command starts the API on port 3000 and reads the application template for routes. ```bash nextjs-zip$ sam local start-api --region us-west-2 nextjs-zip$ curl http://localhost:3000/ ``` -------------------------------- ### Node.js Express App Dockerfile Example Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/guide/src/getting-started/docker-images.md An example Dockerfile for a Node.js Express application using the Lambda Web Adapter. It includes installing dependencies and setting the working directory. ```dockerfile FROM public.ecr.aws/docker/library/node:20-slim COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 /lambda-adapter /opt/extensions/lambda-adapter ENV PORT=7000 WORKDIR "/var/task" ADD src/package.json /var/task/package.json ADD src/package-lock.json /var/task/package-lock.json RUN npm install --omit=dev ADD src/ /var/task CMD ["node", "index.js"] ``` -------------------------------- ### Dockerfile for Lambda Web Adapter Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/fastapi-backend-only-response-streaming/README.md This Dockerfile sets up a Python environment and installs the Lambda Web Adapter. It configures the working directory and installs dependencies from requirements.txt. ```dockerfile FROM public.ecr.aws/docker/library/python:3.12.0-slim-bullseye COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 /lambda-adapter /opt/extensions/lambda-adapter WORKDIR /app ADD . . RUN pip install -r requirements.txt CMD ["python", "main.py"] ``` -------------------------------- ### Run Next.js Development Server Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/nextjs/app/README.md Commands to start the Next.js development server using different package managers. ```bash npm run dev # or yarn dev # or pnpm dev # or bun dev ``` -------------------------------- ### Start API Simulation with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/guide/src/development/local-debugging.md Use AWS SAM CLI to start a local API simulation, which includes a Lambda Runtime Interface Emulator. ```bash sam local start-api ``` -------------------------------- ### Run Remix Development Server Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/remix-zip/remix-app/README.md Starts the development server for local testing and development. Use this command during the development phase. ```shellscript npm run dev ``` -------------------------------- ### Run Remix App in Production Mode Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/remix-zip/remix-app/README.md Starts the production-ready Remix application server. This command should be used after building the app for deployment. ```shell npm start ``` -------------------------------- ### Run Svelte Development Server Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/sveltekit-ssr-zip/app/README.md Start the development server with 'npm run dev'. Use the '-- --open' flag to automatically open the application in your browser. ```bash npm run dev # or start the server and open the app in a new browser tab npm run dev -- --open ``` -------------------------------- ### Build Serverless Application Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/nextjs/README.md Build your serverless application using the SAM CLI. This command installs dependencies, creates a deployment package, and saves it to the build folder. ```bash serverless-nextjs-demo$ sam build ``` -------------------------------- ### Build and Deploy with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/bun-graphql-zip/README.md Use the AWS SAM CLI to build and deploy the Bun application to Lambda. Follow the guided deployment prompts. ```bash sam build sam deploy --guided ``` -------------------------------- ### Installing Lambda Web Adapter in Dockerfile Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/fastapi-response-streaming/README.md A specific instruction within the Dockerfile to copy the Lambda Web Adapter binary into the Lambda extensions directory. ```dockerfile COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 /lambda-adapter /opt/extensions/ ``` -------------------------------- ### Install Dependencies and Generate OpenAPI Schema Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/bedrock-agent-fastapi-zip/README.md Installs required Python dependencies in a virtual environment and then generates the OpenAPI schema for the FastAPI application, saving it to 'openapi.json'. ```shell python3 -m venv .venv source .venv/bin/activate pip install -r app/requirements.txt pip install boto3 cd app/ python -c "import main;import json; print(json.dumps(main.app.openapi()))" > openapi.json ``` -------------------------------- ### Install CDK Dependencies Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/datadog/README.md Installs the necessary AWS CDK dependencies for the project. Navigate to the cdk directory before running. ```sh cd expressjs/cdk npm i cd - ``` -------------------------------- ### SAM Template Example for Lambda Function Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/guide/src/getting-started/zip-packages.md Example AWS SAM template demonstrating the configuration of a Lambda function with the AWS Lambda Web Adapter layer and environment variables. ```yaml Resources: MyFunction: Type: AWS::Serverless::Function Properties: Runtime: nodejs20.x Handler: run.sh Layers: - !Sub arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerX86:27 Environment: Variables: AWS_LAMBDA_EXEC_WRAPPER: /opt/bootstrap AWS_LWA_PORT: 7000 ``` -------------------------------- ### Install Datadog Dependencies Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/datadog/README.md Installs Datadog specific npm dependencies for the Lambda function. Ensure you are in the lambda-asset/src directory. ```sh cd expressjs/lambda-asset/src npm i cd - ``` -------------------------------- ### Build and Deploy with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/bedrock-agent-fastapi-zip/README.md Builds the application using the SAM CLI, preparing it for deployment. Then, it deploys the application to AWS using the guided deployment process, requiring IAM capabilities. ```shell sam build --use-container sam deploy --guided --capabilities CAPABILITY_NAMED_IAM ``` -------------------------------- ### Create Wrapper Script for SvelteKit SSR Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/sveltekit-ssr-zip/README.md Creates a 'run.sh' script to execute the SvelteKit application using Node.js. This script is essential for the Lambda wrapper to start the server. ```sh #!/bin/bash node index.js ``` -------------------------------- ### Install macOS Cross-Compiler Toolchains via Homebrew Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/development.md Install the required cross-compiler toolchains for macOS using Homebrew. This step is necessary for building Linux binaries on macOS. ```shell $ brew tap messense/macos-cross-toolchains $ brew install x86_64-unknown-linux-musl $ brew install aarch64-unknown-linux-musl ``` -------------------------------- ### Build Application with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/nextjs-zip/README.md Build your application using the 'sam build' command. This command installs dependencies, creates a deployment package, and saves it to the .aws-sam/build folder. ```bash nextjs-zip$ sam build ``` -------------------------------- ### Run Python App Locally with Uvicorn Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/guide/src/development/local-debugging.md Start your Python web application using Uvicorn, specifying a port. ```bash uvicorn main:app --port 8080 ``` -------------------------------- ### GraphQL Query Example Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/bun-graphql-zip/README.md A sample GraphQL query to test the feed endpoint. This query retrieves the id, description, and url for each item in the feed. ```graphql query { feed { id description url } } ``` -------------------------------- ### Dockerfile for Remix Application Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/remix/README.md This Dockerfile defines the build and runtime stages for a Remix application, including installing dependencies, building the application, and setting up the Lambda Web Adapter. ```dockerfile FROM public.ecr.aws/docker/library/node:20-bookworm-slim as builder WORKDIR "/var/task" ADD . . RUN cd remix-app && npm install && npm run build && npm prune --omit=dev FROM public.ecr.aws/docker/library/node:20-bookworm-slim COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 /lambda-adapter /opt/extensions/lambda-adapter WORKDIR "/var/task" COPY --from=builder /var/task/remix-app/build /var/task/build COPY --from=builder /var/task/remix-app/node_modules /var/task/node_modules COPY --from=builder /var/task/remix-app/server.js /var/task/server.js COPY --from=builder /var/task/remix-app/package.json /var/task/package.json ENV NODE_ENV=production PORT=3000 CMD ["node", "server.js"] ``` -------------------------------- ### Build and Deploy Deno App with SAM Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/deno-zip/README.md Commands to build and deploy the Deno application using the AWS Serverless Application Model (SAM) CLI. Ensure Deno is installed and you are on an x86_64 machine before running these commands. ```shell sam build sam deploy -g ``` -------------------------------- ### Deploy ASP.NET Application with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/aspnet-mvc/README.md Deploy the built ASP.NET application to AWS using the SAM CLI's guided deployment process. Follow the on-screen prompts for configuration. ```shell $ sam deploy --guided ``` -------------------------------- ### Dockerfile for Sinatra Application Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/sinatra/README.md This Dockerfile sets up a Ruby environment, installs dependencies, copies the Sinatra application code, and configures the AWS Lambda Adapter for deployment. ```dockerfile FROM public.ecr.aws/docker/library/ruby:3.3 COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 /lambda-adapter /opt/extensions/lambda-adapter WORKDIR /var/task COPY Gemfile Gemfile.lock ./ RUN bundle install COPY . . CMD ["bundle", "exec", "ruby", "app.rb", "-o", "0.0.0.0", "-p", "8080"] ``` -------------------------------- ### Dockerfile for PHP Application Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/php/README.md This Dockerfile sets up a PHP environment for AWS Lambda, including installing Composer dependencies and copying the application code and adapter. ```dockerfile FROM public.ecr.aws/awsguru/php:82.2023.3.11.1 AS builder COPY --from=composer /usr/bin/composer /usr/local/bin/composer COPY app /var/task/app WORKDIR /var/task/app RUN composer install --prefer-dist --optimize-autoloader --no-dev --no-interaction FROM public.ecr.aws/awsguru/php:82.2023.3.11.1 COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 /lambda-adapter /opt/extensions/lambda-adapter COPY --from=builder /var/task /var/task # config files ADD nginx/conf/nginx.conf /opt/nginx/conf/nginx.conf ADD php/php.ini /opt/php/php.ini ADD php/etc/php-fpm.conf /opt/php/etc/php-fpm.conf ADD php/php.d/extensions.ini /opt/php/php.d/extensions.ini ``` -------------------------------- ### Deploy Application with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/bedrock-agent-fastapi/README.md Deploys the application to AWS using the SAM CLI's guided deployment process. It requires IAM capabilities for deployment. ```shell sam deploy --guided --capabilities CAPABILITY_NAMED_IAM ``` -------------------------------- ### Deploy Next.js App with SAM Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/nextjs-response-streaming/README.md Deploys the Next.js application to AWS Lambda using the AWS Serverless Application Model (SAM) with guided configuration. ```bash sam deploy --guided ``` -------------------------------- ### Build and Deploy ASP.NET Application with SAM Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/aspnet-mvc-zip/README.md Commands to build the .NET 8 application for deployment using AWS SAM and then deploy it. Ensure .NET 8 is installed and run these commands on an x86_64 machine. ```shell sam build --use-container sam deploy -g ``` -------------------------------- ### Build and Deploy Express.js App with SAM Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/expressjs-zip/README.md Use AWS SAM CLI to build and deploy your Express.js application to Lambda. Ensure you have the AWS SAM CLI installed and configured. ```bash sam build sam deploy --guided ``` -------------------------------- ### Curl Request to Stream Dummy File Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/springboot-response-streaming-zip/README.md Example cURL command to request a dummy file stream from the deployed Lambda function. The 'size' parameter specifies the file size in MB. ```shell $ curl https://abcdxxxxxxxxxxxx.lambda-url.us-west-2.on.aws/stream-dummy?size=15 ``` -------------------------------- ### Readiness Check Health Status Example Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/README.md This bash snippet demonstrates how to configure the readiness check healthy status using environment variables. It shows the transition from the deprecated `AWS_LWA_READINESS_CHECK_MIN_UNHEALTHY_STATUS` to the current `AWS_LWA_READINESS_CHECK_HEALTHY_STATUS`. ```bash # Old AWS_LWA_READINESS_CHECK_MIN_UNHEALTHY_STATUS=400 # New (equivalent) AWS_LWA_READINESS_CHECK_HEALTHY_STATUS=100-399 ``` -------------------------------- ### Test Deployed API with Curl Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/javalin-zip/README.md Example of how to test the deployed Javalin API using curl. Replace the placeholder URL with the actual API endpoint provided after deployment. ```shell $ curl https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/v1/pets ``` -------------------------------- ### Dockerfile for FastAPI Application Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/fastapi-background-tasks/README.md This Dockerfile sets up a Python 3.12 environment, copies the AWS Lambda Web Adapter extension, installs dependencies, and configures uvicorn to run the FastAPI application. ```dockerfile FROM public.ecr.aws/docker/library/python:3.12-slim COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 /lambda-adapter /opt/extensions/lambda-adapter ENV PORT=8000 WORKDIR /var/task COPY requirements.txt ./ RUN python -m pip install -r requirements.txt COPY *.py ./ CMD exec uvicorn --port=$PORT main:app ``` -------------------------------- ### Local Test with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/remix/README.md Simulate AWS Lambda and API Gateway locally using the SAM CLI to test your web application. This command starts a local HTTP endpoint and a Docker container. ```shell sam local start-api --warm-containers EAGER ``` -------------------------------- ### Shell Script Handler for ASP.NET Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/aspnet-webapi-zip/README.md A simple bash script used as the handler to start the ASP.NET web application within the Lambda environment. Ensure the executable name matches your compiled application. ```shell #!/bin/bash ./AspNetLambdaZipWebAdapter ``` -------------------------------- ### Local Test with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/remix-zip/README.md Simulate API Gateway and Lambda locally using SAM CLI. This command starts a local HTTP endpoint and a Docker container. Modify the region to match your AWS region. ```shell sam local start-api --warm-containers EAGER --region us-west-2 ``` -------------------------------- ### Dockerfile for FastMCP Server Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/fastmcp/README.md This Dockerfile sets up a Python environment, installs dependencies, copies the FastMCP application code, and configures the AWS Lambda Web Adapter for deployment. It specifies the Python version, working directory, and command to run the uvicorn server. ```dockerfile FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.14-slim AS builder WORKDIR /var/task COPY requirements.txt ./ RUN pip install --no-cache-dir --target=/var/task/deps -r requirements.txt FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.14-slim COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 /lambda-adapter /opt/extensions/lambda-adapter ENV PORT=8000 PYTHONPATH=/var/task/deps ENV AWS_LWA_READINESS_CHECK_PATH=/healthz ENV AWS_LWA_READINESS_CHECK_HEALTHY_STATUS=100-499 WORKDIR /var/task COPY --from=builder /var/task/deps ./ COPY *.py ./ CMD exec python -m uvicorn --port=$PORT app:app ``` -------------------------------- ### Build AWS Lambda Web Adapter with Docker Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/development.md Compile the Lambda Web Adapter using Docker. This command requires AWS CLI v2 to be installed and configured. It produces Docker images for x86_64 and aarch64 architectures. ```shell $ make build ``` -------------------------------- ### Build the Project Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/AGENTS.md Compiles the project using Cargo. ```bash cargo build ``` -------------------------------- ### Build and Deploy Application Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/rust-axum-zip/README.md Build the source code and deploy the application to AWS using SAM CLI. The deploy command prompts for configuration and can save arguments to samconfig.toml. ```bash make build sam deploy --guided ``` -------------------------------- ### Express.js Event Handler Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/guide/src/features/non-http-events.md Example of an Express.js route to handle incoming non-HTTP events. The event body is accessed and processed. ```javascript // Express.js app.post('/events', (req, res) => { const event = req.body; // Process the event res.json({ statusCode: 200, body: 'processed' }); }); ``` -------------------------------- ### FastAPI Event Handler Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/guide/src/features/non-http-events.md Example of a FastAPI route to handle incoming non-HTTP events. The event payload is parsed as JSON and processed. ```python # FastAPI @app.post("/events") async def handle_event(request: Request): event = await request.json() # Process SQS, SNS, S3, etc. return {"statusCode": 200, "body": "processed"} ``` -------------------------------- ### Package x86_64 Lambda Extension as Docker Image Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/guide/src/development/building.md Create a minimal Docker image for the x86_64 Lambda extension using the compiled binary. This uses a scratch base image for maximum efficiency. ```bash printf 'FROM scratch ADD target/lambda/extensions/. / ' | docker build --platform=linux/amd64 -t aws-lambda-adapter:latest-x86_64 -f- . ``` -------------------------------- ### Add Rust Cross-Compilation Targets for macOS Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/development.md Install the necessary Rust toolchain targets for cross-compiling on macOS for both x86_64 and aarch64 Linux environments. ```shell $ rustup target add x86_64-unknown-linux-musl $ rustup target add aarch64-unknown-linux-musl ``` -------------------------------- ### Test Locally with Sample Event Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/bedrock-agent-fastapi-zip/README.md Invokes the deployed application locally using the SAM CLI, providing a sample event from the 'events' directory to test the agent's functionality. ```shell sam local invoke --event events/s3_bucket_count.json ``` -------------------------------- ### Get VPC Subnet and Security Group IDs Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/fastapi-response-streaming-lmi/README.md Lists available subnets and security groups within your default VPC to configure LMI. ```bash # List subnets in your default VPC aws ec2 describe-subnets --filters "Name=default-for-az,Values=true" \ --query 'Subnets[*].[SubnetId,AvailabilityZone]' --output table # List security groups aws ec2 describe-security-groups --filters "Name=group-name,Values=default" \ --query 'SecurityGroups[*].[GroupId,GroupName]' --output table ``` -------------------------------- ### Package arm64 Lambda Extension as Docker Image Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/guide/src/development/building.md Create a minimal Docker image for the arm64 Lambda extension using the compiled binary. This uses a scratch base image for maximum efficiency. ```bash printf 'FROM scratch ADD target/lambda/extensions/. / ' | docker build --platform=linux/arm64 -t aws-lambda-adapter:latest-aarch64 -f- . ``` -------------------------------- ### Build and Deploy ASP.NET App with SAM Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/aspnet-webapi-zip/README.md Commands to build and deploy an ASP.NET application using the AWS Serverless Application Model (SAM) CLI. Requires .NET 8 and a x86_64 machine. ```shell sam build --use-container sam deploy -g ``` -------------------------------- ### Build and Deploy Commands Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/fastapi-backend-only-response-streaming/README.md These commands are used to build the Docker image for the Lambda function and deploy the application using AWS SAM. ```bash sam build --use-container sam deploy --guided ``` -------------------------------- ### Dockerfile for FastAPI on Lambda Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/bedrock-agent-fastapi/README.md This Dockerfile sets up a Python 3.12 environment, installs the AWS Lambda Adapter, and configures FastAPI to run with uvicorn on Lambda. ```dockerfile FROM public.ecr.aws/docker/library/python:3.12.0-slim COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 /lambda-adapter /opt/extensions/lambda-adapter ENV PORT=8000 AWS_LWA_READINESS_CHECK_PROTOCOL=tcp WORKDIR /var/task COPY requirements.txt ./ RUN python -m pip install -r requirements.txt COPY *.py ./ CMD exec uvicorn --port=$PORT main:app ``` -------------------------------- ### Curl Request to Stream Pre-existing MP4 File Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/springboot-response-streaming-zip/README.md Example cURL command to request streaming of a pre-existing MP4 file from the deployed Lambda function. ```shell $ curl https://abcdxxxxxxxxxxxx.lambda-url.us-west-2.on.aws/stream ``` -------------------------------- ### Deploy Application with Serverless Framework Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/sls/nestjs/README.md Deploy the application to your AWS account using the Serverless Framework. This command will create the necessary AWS Lambda function. ```bash serverless deploy ``` -------------------------------- ### Build ASP.NET Application with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/aspnet-mvc/README.md Use the SAM CLI to build the container image for your ASP.NET application, preparing it for deployment to AWS Lambda. ```shell $ sam build ``` -------------------------------- ### Build Docker Images using Makefile Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/guide/src/development/building.md Utilize Makefile targets to conveniently build Docker images for both x86_64 and arm64 architectures, combining build and packaging steps. ```bash make build-image-x86 ``` ```bash make build-image-arm64 ``` -------------------------------- ### Clone the AWS Lambda Web Adapter Repository Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/guide/src/development/building.md Clone the official repository to your local machine to begin building from source. Navigate into the cloned directory to proceed with the build steps. ```bash git clone https://github.com/awslabs/aws-lambda-web-adapter.git cd aws-lambda-web-adapter ``` -------------------------------- ### SAM Template API Event Configuration Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/nextjs-zip/README.md Example of how API Gateway events are configured within a SAM template. This defines the path and method for an API route. ```yaml Events: HelloWorld: Type: Api Properties: Path: /hello Method: get ``` -------------------------------- ### Run Testing Commands for AWS Lambda Web Adapter Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/development.md Execute the specified commands to format code, check for clippy warnings, and run tests before submitting a pull request. These commands ensure code quality and correctness. ```shell cargo fmt -- --check cargo clippy -- -Dwarnings cargo nextest run ``` -------------------------------- ### Dockerfile for ASP.NET Application Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/aspnet-mvc/README.md This Dockerfile sets up an ASP.NET 8.0 preview environment, copies the application code, builds and publishes it, and integrates the AWS Lambda Adapter for deployment on Lambda. ```dockerfile FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview as base WORKDIR /app FROM mcr.microsoft.com/dotnet/sdk:8.0-preview AS build COPY . ./src WORKDIR /src RUN ls RUN dotnet build "AspNetLambdaWebAdapter.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "AspNetLambdaWebAdapter.csproj" -c Release -o /app/publish FROM base AS final ENV ASPNETCORE_URLS=http://+:8080 COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 /lambda-adapter /opt/extensions/lambda-adapter WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "AspNetLambdaWebAdapter.dll"] ``` -------------------------------- ### Create New Svelte Project Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/sveltekit-ssr-zip/app/README.md Use 'npx sv create' to initialize a new Svelte project. You can create it in the current directory or specify a project name. ```bash npx sv create # create a new project in my-app npx sv create my-app ``` -------------------------------- ### Build Application with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/bedrock-agent-fastapi/README.md Builds the application using AWS SAM CLI, preparing a deployment package in the .aws-sam directory. This command is necessary before deploying the application. ```shell sam build ``` -------------------------------- ### Build and Deploy Express.js App with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/expressjs/README.md Commands to log in to ECR, build the application using SAM CLI, and deploy it to AWS. ```shell $ aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws $ sam build $ sam deploy --guided ``` -------------------------------- ### Minimal Dockerfile for Lambda Web Adapter Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/guide/src/getting-started/quick-start.md Add this line to your Dockerfile to include the Lambda Web Adapter. This allows your web app to run on Lambda. ```dockerfile COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 /lambda-adapter /opt/extensions/lambda-adapter ``` -------------------------------- ### Configure Cargo for Cross-Compilation Linkers on macOS Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/development.md Create a .cargo/config file to specify the correct linker for the x86_64 and aarch64 unknown-linux-musl targets. This ensures Cargo uses the newly installed cross-compilers. ```shell $ mkdir .cargo $ echo '[target.x86_64-unknown-linux-musl] linker = "x86_64-unknown-linux-musl-gcc" [target.aarch64-unknown-linux-musl] linker = "aarch64-unknown-linux-musl-gcc"'> .cargo/config ``` -------------------------------- ### Python Client for Streaming API Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/fastapi-backend-only-response-streaming/README.md This Python script demonstrates how to send a GET request to the deployed streaming API endpoint. It uses SigV4 authentication and streams the response chunk by chunk. ```python import requests from botocore.auth import SigV4Auth from botocore.awsrequest import AWSRequest import boto3 import json import time session = boto3.Session() credentials = session.get_credentials() region = 'us-east-1' payload = {"query": query} request = AWSRequest( method='GET', url=f'{func_url}/api/stream', data=json.dumps(payload), headers={'Content-Type': 'application/json'} ) SigV4Auth(credentials, "lambda", region).add_auth(request) buffer = "" response= requests.get( request.url, data=request.data, headers=dict(request.headers), stream=True ) for chunk in response.iter_content(chunk_size=64): print(chunk.decode('utf-8'), end='', flush=True) ``` -------------------------------- ### Create Remix App with Express Template Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/remix-zip/README.md Use this command to scaffold a new Remix application with an Express.js backend template. ```bash npx create-remix@latest --template remix-run/remix/templates/express ``` -------------------------------- ### Build and Deploy Spring Boot App with SAM CLI Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/springboot/README.md Commands to authenticate Docker with ECR Public, build the Spring Boot application using SAM CLI, and deploy it to AWS. ```shell aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws sam build ``` ```shell sam deploy --guided ``` -------------------------------- ### SAM Template Configuration for Lambda Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/springboot-response-streaming-zip/README.md This YAML configuration defines a Lambda function using SAM. It specifies runtime, handler, environment variables, layers, and enables SnapStart for reduced cold starts. ```yaml Properties: MemorySize: 512 Handler: run.sh CodeUri: app/ Runtime: java11 AutoPublishAlias: live SnapStart: ApplyOn: PublishedVersions Environment: Variables: RUST_LOG: info READINESS_CHECK_PATH: /healthz REMOVE_BASE_PATH: /v1 AWS_LAMBDA_EXEC_WRAPPER: /opt/bootstrap AWS_LWA_INVOKE_MODE: response_stream Layers: - !Sub arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerX86:27 ``` -------------------------------- ### Configure TCP Readiness Check Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/docs/guide/src/configuration/readiness-check.md Use TCP-based readiness checking when your application does not have an HTTP health endpoint ready at startup. This ensures the port is accepting TCP connections. ```bash AWS_LWA_READINESS_CHECK_PROTOCOL=tcp ``` -------------------------------- ### Build Remix App for Production Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/remix-zip/remix-app/README.md Builds the Remix application for production deployment. This command generates optimized assets and server code. ```shell npm run build ``` -------------------------------- ### Generate Documentation Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/AGENTS.md Generates documentation for the project, excluding dependencies, using Cargo. ```bash cargo doc --no-deps ``` -------------------------------- ### Test Deployed Application URL Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/aspnet-mvc/README.md After deployment, use `curl` or a web browser to access the application's URL provided by the SAM CLI outputs to verify it's running correctly. ```shell $ curl https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/ ``` -------------------------------- ### Deploy with AWS CDK Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/datadog/README.md Deploys the application using AWS CDK. Run this command from the cdk directory. ```sh cd expressjs/cdk cdk deploy cd - ``` -------------------------------- ### Dockerfile for FastAPI Application Source: https://github.com/aws/aws-lambda-web-adapter/blob/main/examples/fastapi/README.md This Dockerfile configures a Python 3.8 environment, installs dependencies, copies the FastAPI application code, and sets up the AWS Lambda Web Adapter for deployment on Lambda. It uses uvicorn to run the application. ```dockerfile FROM public.ecr.aws/docker/library/python:3.8.12-slim-buster COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 /lambda-adapter /opt/extensions/lambda-adapter ENV PORT=8000 WORKDIR /var/task COPY requirements.txt ./ RUN python -m pip install -r requirements.txt COPY *.py ./ CMD exec uvicorn --port=$PORT main:app ```