A minimal AWS Lambda example in Rust that responds with "Hello, world!" via API Gateway, with developer-friendly Devcontainer setup.
- Docker Desktop
- VS Code with Dev Containers extension
- AWS CLI configured with appropriate credentials
- Clone this repository
- Open in VS Code
- When prompted, click "Reopen in Container"
- Wait for the container to build and install dependencies
# Watch for changes and run locally
cargo lambda watch
# In another terminal, test locally
curl http://localhost:9000/
# Response: {"message":"Hello, world!"}# Build ARM64 binary for AWS Lambda
cargo lambda build --release --arm64
# The binary will be created at:
# target/lambda/lambda-rust-http/bootstrap# Navigate to infrastructure directory
cd infra
# Initialize Terraform
terraform init
# Plan deployment
terraform plan
# Deploy infrastructure
terraform apply
# Get the API Gateway URL
terraform output api_gateway_url# Test with the URL from terraform output
curl https://<api-id>.execute-api.<region>.amazonaws.com/prod/
# Response: {"message":"Hello, world!"}lambda-rust-http/
├── .devcontainer/ # VS Code Dev Container config
│ ├── devcontainer.json # Container settings
│ └── Dockerfile # Container image
├── src/
│ └── main.rs # Lambda function code
├── infra/ # Terraform infrastructure
│ ├── main.tf # Main infrastructure config
│ ├── variables.tf # Variable definitions
│ └── outputs.tf # Output values
├── Cargo.toml # Rust dependencies
└── README.md # This file
- Local Development: Use
cargo lambda watchfor hot reloading - Testing: Test locally before deploying
- Build: Use
cargo lambda build --release --arm64for production - Deploy: Use Terraform to deploy infrastructure
- Test: Verify the deployed function works
The build process creates:
- Binary:
target/lambda/lambda-rust-http/bootstrap(ARM64) - Package:
target/lambda/lambda-rust-http.zip(for Terraform)
- Root:
GET /→ Returns{"message":"Hello, world!"} - Any Path:
ANY /{proxy+}→ Same response (handles all routes)
- Rust: Programming language
- lambda_http: AWS Lambda HTTP runtime
- cargo-lambda: Build tool for Rust Lambda functions
- Terraform: Infrastructure as Code
- Dev Containers: Consistent development environment
This implementation is based on the official AWS sample template: 👉 basic-http-function example in aws-lambda-rust-runtime
- Build fails: Ensure you're using the Dev Container with Rust 1.70+
- Terraform errors: Check AWS credentials and region configuration
- Lambda cold start: First invocation may be slower
# Check Rust version
rustc --version
# Check cargo-lambda installation
cargo lambda --version
# Check AWS CLI
aws --version
# Check Terraform
terraform --versionThis project is licensed under the MIT License - see the LICENSE file for details.