Recipe: Load Rules, Lookups, and Models from S3

Use exact-object s3:// URIs for rules YAML, lookup CSVs, ONNX models, and NDJSON files.

BlazeRules resolves exact-object s3://bucket/key URIs through the AWS CLI cache path. Use a named profile when possible.

import blazerules

blazerules.set_aws_profile("personal")
blazerules.set_aws_region("us-east-1")

engine = blazerules.RuleEngine()
engine.register_model("fraud_logreg", "s3://my-bucket/models/fraud_logreg.onnx")
engine.load_rules("s3://my-bucket/rules/rules.yaml")
CLI equivalent: use the same S3 paths with the agent
export BLAZERULES_AWS_PROFILE=personal
export BLAZERULES_AWS_REGION=us-east-1

blazerules_agent \
  --rules s3://my-bucket/rules/rules.yaml \
  --input stdin \
  --output stdout

For MinIO, LocalStack, Cloudflare R2, or another S3-compatible endpoint:

blazerules.set_aws_endpoint_url("http://127.0.0.1:9000")
CLI equivalent: configure a custom S3 endpoint
export BLAZERULES_AWS_ENDPOINT_URL=http://127.0.0.1:9000
blazerules_agent --rules s3://local-bucket/rules/rules.yaml --input stdin --output stdout

Environment variables are also supported:

export BLAZERULES_AWS_PROFILE=personal
export BLAZERULES_AWS_REGION=us-east-1
export BLAZERULES_AWS_ENDPOINT_URL=http://127.0.0.1:9000
Python equivalent: set the same values in-process
import blazerules

blazerules.set_aws_profile("personal")
blazerules.set_aws_region("us-east-1")
blazerules.set_aws_endpoint_url("http://127.0.0.1:9000")

Avoid embedding credentials in rules, source code, or docs. If you must set credentials from Python in a short-lived local process:

blazerules.set_aws_credentials(
    access_key_id="...",
    secret_access_key="...",
    session_token="",
    region="us-east-1",
)
CLI equivalent: pass credentials through environment
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export AWS_SESSION_TOKEN=...
export AWS_REGION=us-east-1

Relative lookup paths in a rules file resolve relative to that rules file. For S3-hosted rules, keep lookup CSV paths either absolute s3://... URIs or relative keys under the same prefix.