Req plugin for AWS Signature V4 authentication.
This module provides seamless integration between ex_aws_auth and the
Req HTTP client library. It automatically signs requests with AWS Signature V4
without requiring manual header manipulation.
Usage
# Load credentials from environment
creds = AWSAuth.Credentials.from_env()
# Attach to a Req request
Req.new(url: url, method: :post, body: body)
|> AWSAuth.Req.attach(credentials: creds, service: "bedrock")
|> Req.request()
# Or create a reusable client
client =
Req.new(base_url: "https://bedrock-runtime.us-east-1.amazonaws.com")
|> AWSAuth.Req.attach(credentials: creds, service: "bedrock")
# Make multiple requests
Req.post!(client, url: "/model/my-model/invoke", json: params)Options
:credentials- (required)AWSAuth.Credentialsstruct or keyword list/map with::access_key_id- AWS Access Key ID:secret_access_key- AWS Secret Access Key:session_token- AWS Session Token (optional):region- AWS region (optional, fallback when URL has no region)
:service- (required) AWS service name (e.g., "s3", "bedrock", "lambda"):region- AWS region (optional; overrides URL and credentials region):unsigned_headers- List of header names to exclude from signing (optional):uri_escape_path- Override URI path escaping (optional):apply_checksum_header- Includex-amz-content-sha256header (optional, default:true):payload- Force:unsignedor:streaming_eventspayload mode (optional):auth_scheme- Authentication scheme (:sigv4or:s3express_session; when:s3express_session, emitsx-amz-s3session-tokeninstead ofx-amz-security-token, optional, default::sigv4)
How it Works
The plugin adds a request step that:
- Resolves the signing region (
explicit :region> URL >credentials.region>"us-east-1") - Signs the request using AWS Signature V4
- Tracks generated headers (
authorization,x-amz-date,x-amz-content-sha256,x-amz-security-token, andhostwhen not caller-supplied) so retries and trusted redirects re-sign cleanly - Strips generated signing headers on untrusted cross-origin redirects unless
redirect_trusted: trueis set on the request
Attach this plugin after any custom plugin that changes the request URL, body, or headers. Request steps appended after AWS signing may make the signature stale.
Summary
Functions
Attaches AWS Signature V4 signing to a Req request.
Functions
@spec attach(Req.Request.t(), keyword()) :: Req.Request.t()
Attaches AWS Signature V4 signing to a Req request.
Parameters
request- AReq.Requeststructopts- Keyword list of options (see module docs for details)
Returns
A Req.Request with the AWS signing step appended after Req prepares the URL and body.