2025-03-09 17:07:42 -07:00
2025-03-09 17:07:42 -07:00
2025-03-09 17:07:42 -07:00
2025-03-09 17:07:42 -07:00
2025-03-09 17:07:42 -07:00
2025-03-09 17:07:42 -07:00
2025-03-09 17:07:42 -07:00
2025-03-09 17:07:42 -07:00
2025-03-09 17:07:42 -07:00

Fetch Helper

A serverless AWS Lambda function written in Rust that acts as a proxy for making HTTP requests.

Overview

Fetch Helper is a simple AWS Lambda function that accepts HTTP request details via JSON and makes the corresponding HTTP request on behalf of the caller. It returns the response status, headers, and body back to the client.

This service is part of the Troop 618 email system, designed to help with making HTTP requests from environments where direct requests might not be possible.

Features

  • Supports various HTTP methods (GET, POST, etc.)
  • Allows custom headers to be set
  • Handles request payloads
  • Returns complete response information (status, headers, body)

Technical Details

  • Written in Rust
  • Deployed as an AWS Lambda function
  • Uses the lambda_http crate for handling Lambda events
  • Uses reqwest for making HTTP requests

Request Format

The Lambda function expects a JSON payload with the following structure:

{
  "url": "https://example.com/api",
  "method": "GET",  // Optional, defaults to "GET"
  "headers": [      // Optional
    {
      "name": "Content-Type",
      "value": "application/json"
    }
  ],
  "payload": ""     // Optional, request body
}

Response Format

The function returns a JSON response with:

{
  "status": "200 OK",
  "headers": [
    {
      "name": "content-type",
      "value": "application/json"
    }
  ],
  "body": "Response content here"
}

Development

Prerequisites

If using direnv, direnv/nix will install everything needed, including for cross compilation to ARM64

  • Rust toolchain
  • AWS CLI configured with appropriate permissions
  • nix-direnv (optional, for development environment)
  • cargo lambda

Local Development

This project uses nix-direnv for managing development dependencies. If you have nix-direnv installed:

# The .envrc file will automatically set up the environment
cd fetch-helper
direnv allow

Building

cargo lambda build --release [--arm64]

Deployment

The function can be deployed to AWS Lambda using cargo lambda

cargo lambda deploy [function name]

More information on deployments can be found here: https://github.com/awslabs/aws-lambda-rust-runtime?tab=readme-ov-file

License

MIT

Description
AWS Lambda workaround to Javascript fetch function inability to work with headers
Readme 42 KiB
Languages
Nix 50.3%
Rust 49.7%