Conjure.Storage.AwsSigV4 (Conjure v0.1.1-alpha)

View Source

AWS Signature Version 4 signing for S3 requests.

This module implements the AWS Signature Version 4 algorithm for authenticating requests to S3-compatible services including:

  • AWS S3
  • Tigris (Fly.io)
  • MinIO
  • LocalStack

Usage

headers = Conjure.Storage.AwsSigV4.sign(
  method: :put,
  host: "s3.us-east-1.amazonaws.com",
  path: "/my-bucket/my-key",
  payload: "file content",
  region: "us-east-1",
  access_key: "AKIAIOSFODNN7EXAMPLE",
  secret_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
)

See Also

Summary

Functions

Create presigned URL for S3 object.

Sign an HTTP request for AWS S3-compatible services.

Functions

presign_url(opts)

@spec presign_url(keyword()) :: String.t()

Create presigned URL for S3 object.

Options

Same as sign/1 plus:

  • :expires_in - URL expiration in seconds (default: 3600)

Returns

Presigned URL string.

sign(opts)

@spec sign(keyword()) :: [{String.t(), String.t()}]

Sign an HTTP request for AWS S3-compatible services.

Options

  • :method - HTTP method atom (required): :get, :put, :delete, :head
  • :host - Target host (required): e.g., "s3.us-east-1.amazonaws.com"
  • :path - Request path (required): e.g., "/bucket/key"
  • :query - Query string (optional): e.g., "list-type=2"
  • :payload - Request body (optional): defaults to ""
  • :region - AWS region (required): e.g., "us-east-1"
  • :access_key - AWS access key ID (required)
  • :secret_key - AWS secret access key (required)
  • :service - AWS service (optional): defaults to "s3"

Returns

List of headers to include in the request:

  • Authorization - AWS4-HMAC-SHA256 signature
  • x-amz-date - Request timestamp
  • x-amz-content-sha256 - Payload hash
  • Host - Target host

Example

headers = Conjure.Storage.AwsSigV4.sign(
  method: :put,
  host: "s3.us-east-1.amazonaws.com",
  path: "/my-bucket/my-key",
  payload: "Hello, World!",
  region: "us-east-1",
  access_key: System.get_env("AWS_ACCESS_KEY_ID"),
  secret_key: System.get_env("AWS_SECRET_ACCESS_KEY")
)

Req.put("https://s3.us-east-1.amazonaws.com/my-bucket/my-key",
  body: "Hello, World!",
  headers: headers
)