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
185 changes: 185 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
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_http_geolocation
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: |
if ! command -v cargo-lambda &> /dev/null; then
cargo install cargo-lambda
else
echo "✅ cargo-lambda already installed"
fi

- 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/lambda_http_geolocation/bootstrap" ]; then
echo "❌ Binary not found at target/lambda/lambda_http_geolocation/bootstrap"
exit 1
fi
echo "✅ Binary created successfully"
ls -la target/lambda/lambda_http_geolocation/bootstrap
file target/lambda/lambda_http_geolocation/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: |
if ! command -v cargo-lambda &> /dev/null; then
cargo install cargo-lambda
else
echo "✅ cargo-lambda already installed"
fi

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

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

- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: target/lambda/lambda_http_geolocation/lambda_http_geolocation.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_http_geolocation.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
52 changes: 35 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
# 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
*.zip
target/lambda/

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

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

# OS
.DS_Store
Thumbs.db

# Logs
*.log

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# Environment variables
.env
.env.local

# Generated by cargo mutants
# Contains mutation testing data
**/mutants.out*/
# AWS
.aws/

# 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/
# Temporary files
*.tmp
*.temp
34 changes: 34 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "lambda_http_geolocation"
version = "0.1.0"
edition = "2021"

[package.metadata.lambda]
runtime = "provided.al2023"
architecture = "arm64"

[dependencies]
lambda_http = "0.9"
tokio = { version = "1.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11", features = ["json", "rustls-tls"], default-features = false }
tracing = "0.1"
tracing-subscriber = { version = "0.3", optional = true }

[features]
default = ["dev-tracing"]
dev-tracing = ["tracing-subscriber"]

[dev-dependencies]

[profile.release]
opt-level = 3
lto = true
codegen-units = 1
panic = "abort"
strip = true

[profile.dev]
opt-level = 0
debug = true
Loading
Loading