Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Lambda Rust HTTP",
"image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye",
"features": {
"ghcr.io/devcontainers/features/aws-cli:1": {},
"ghcr.io/devcontainers/features/terraform:1": {},
"ghcr.io/jajera/features/zip:1": {},
"ghcr.io/devcontainers-extra/features/zig:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"ms-vscode.vscode-json",
"hashicorp.terraform"
]
}
},
"postCreateCommand": "cargo install cargo-lambda",
"remoteUser": "vscode"
}
11 changes: 11 additions & 0 deletions .github/workflows/commitmsg-conform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: commit-message-conformance
on:
pull_request: {}
permissions:
statuses: write
checks: write
contents: read
pull-requests: read
jobs:
commitmsg-conform:
uses: actionsforge/actions/.github/workflows/commitmsg-conform.yml@main
177 changes: 177 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
name: Build and Deploy Rust Lambda

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]

# Cancel in-progress jobs when new commits are pushed
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
FUNCTION_NAME: lambda-rust-http
RUNTIME: provided.al2023
ARCHITECTURE: arm64

permissions:
contents: write
packages: write

jobs:
validate:
name: Validate and Test
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: aarch64-unknown-linux-gnu
override: true

- name: Cache Zig
uses: actions/cache@v4
with:
path: |
~/.zig
zig-linux-x86_64-0.13.0
key: ${{ runner.os }}-zig-0.13.0

- name: Install Zig
run: |
if [ ! -d "zig-linux-x86_64-0.13.0" ]; then
curl -L https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz | tar -xJ
fi
echo "$PWD/zig-linux-x86_64-0.13.0" >> $GITHUB_PATH

- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
~/.cargo/bin
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Install cargo-lambda
run: |
cargo install cargo-lambda

- name: Run clippy
run: |
cargo clippy --all-targets --all-features -- -D warnings

- name: Run tests
run: |
cargo test

- name: Build Lambda function
run: |
cargo lambda build --release --arm64

- name: Verify binary
run: |
if [ ! -f "target/lambda/bootstrap/bootstrap" ]; then
echo "❌ Binary not found at target/lambda/bootstrap/bootstrap"
exit 1
fi
echo "✅ Binary created successfully"
ls -la target/lambda/bootstrap/bootstrap
file target/lambda/bootstrap/bootstrap

release:
name: Create Release
runs-on: ubuntu-latest
needs: validate
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: aarch64-unknown-linux-gnu
override: true

- name: Cache Zig
uses: actions/cache@v4
with:
path: |
~/.zig
zig-linux-x86_64-0.13.0
key: ${{ runner.os }}-zig-0.13.0

- name: Install Zig
run: |
if [ ! -d "zig-linux-x86_64-0.13.0" ]; then
curl -L https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz | tar -xJ
fi
echo "$PWD/zig-linux-x86_64-0.13.0" >> $GITHUB_PATH

- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
~/.cargo/bin
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Install cargo-lambda
run: |
cargo install cargo-lambda

- name: Build Lambda function
run: |
cargo lambda build --release --arm64

- name: Create deployment package
run: |
cd target/lambda/bootstrap
zip -r lambda-rust-http.zip bootstrap
cd ../../..

- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: target/lambda/bootstrap/lambda-rust-http.zip
tag_name: v${{ github.run_number }}
name: Release v${{ github.run_number }}
body: |
## Rust Lambda Function Release

**Function:** ${{ env.FUNCTION_NAME }}
**Runtime:** ${{ env.RUNTIME }}
**Architecture:** ${{ env.ARCHITECTURE }}

### Installation
1. Download the `lambda-rust-http.zip` file
2. Upload to AWS Lambda console or use AWS CLI
3. Set handler to: `bootstrap`
4. Set runtime to: `provided.al2023`
5. Set architecture to: `arm64`
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Tag Latest
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -f latest
git push origin latest --force
11 changes: 11 additions & 0 deletions .github/workflows/markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: markdown-lint
on:
pull_request: {}
permissions:
statuses: write
checks: write
contents: read
pull-requests: read
jobs:
markdown-lint:
uses: actionsforge/actions/.github/workflows/markdown-lint.yml@main
51 changes: 34 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
# Generated by Cargo
# will have compiled files and executables
debug
target

# These are backup files generated by rustfmt
# Rust
/target/
**/*.rs.bk
Cargo.lock

# Lambda build artifacts
target/lambda/
*.zip
bootstrap
target/lambda/bootstrap/
target/lambda/lambda-rust-http/

# Terraform
*.tfstate
*.tfstate.*
.terraform/
.terraform.lock.hcl

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# Logs
*.log

# Generated by cargo mutants
# Contains mutation testing data
**/mutants.out*/
# Environment variables
.env
.env.local
.env.*.local

# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# AWS
.aws/
20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "lambda-rust-http"
version = "0.1.0"
edition = "2021"

[dependencies]
lambda_http = "0.16"
lambda_runtime = "0.14"
tokio = { version = "1.47", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tracing = "0.1"
tracing-subscriber = "0.3"

[dev-dependencies]
cargo-lambda = "1.8.6"

[[bin]]
name = "bootstrap"
path = "src/main.rs"
54 changes: 54 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.PHONY: help build clean watch deploy destroy test

help: ## Show this help message
@echo "Available commands:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

build: ## Build the Lambda function for production
@echo "🔨 Building Lambda function..."
cargo lambda build --release --arm64
@echo "✅ Build complete!"

clean: ## Clean build artifacts
@echo "🧹 Cleaning build artifacts..."
cargo clean
@echo "✅ Clean complete!"

watch: ## Watch for changes and run locally
@echo "👀 Starting cargo lambda watch..."
cargo lambda watch

deploy: build ## Build and deploy to AWS
@echo "🚀 Deploying to AWS..."
cd infra && terraform init && terraform apply -auto-approve
@echo "✅ Deployment complete!"

destroy: ## Destroy AWS infrastructure
@echo "🗑️ Destroying AWS infrastructure..."
cd infra && terraform destroy -auto-approve
@echo "✅ Destruction complete!"

test: ## Test the deployed function
@echo "🧪 Testing deployed function..."
@cd infra && terraform output -raw api_gateway_url | xargs -I {} curl -s {} | jq .

plan: ## Plan Terraform changes
@echo "📋 Planning Terraform changes..."
cd infra && terraform plan

fmt: ## Format Rust code
@echo "🎨 Formatting Rust code..."
cargo fmt

check: ## Check Rust code
@echo "🔍 Checking Rust code..."
cargo check

clippy: ## Run Clippy linter
@echo "🔍 Running Clippy..."
cargo clippy

install-deps: ## Install development dependencies
@echo "📦 Installing development dependencies..."
cargo install cargo-lambda
@echo "✅ Dependencies installed!"
Loading
Loading