JuliusBrussee/caveman · error

awssig: signer requires region and service

Error message

awssig: signer requires region and service

What it means

Signer.Sign validates its inputs before computing an AWS SigV4 signature; the very first check requires the signer to have both Region and Service set. This error means the Signer value was constructed without the AWS region and/or the service name (e.g. "s3", "execute-api") needed to build the credential scope. It is a malformed-input guard and never involves the request or credentials themselves.

Solutions

  1. Set both Region and Service when constructing Signer, e.g. awssig.Signer{Region: "us-east-1", Service: "s3"}.
  2. Check where the signer is built and confirm the region/service config values are loaded before construction.
  3. Add a startup validation that fails fast if region or service config is empty.

Example fix

// before
signer := awssig.Signer{Region: cfg.Region}
// after
signer := awssig.Signer{Region: cfg.Region, Service: "s3"}
Defensive patterns

Strategy: validation

Validate before calling

func signerReady(s awssig.Signer) bool { return s.Region != "" && s.Service != "" }
if !signerReady(signer) {
    return errors.New("awssig signer misconfigured: region and service are required")
}

Try / catch

if err := signer.Sign(req, creds, hash, now); err != nil {
    if strings.Contains(err.Error(), "requires region and service") {
        return fmt.Errorf("signer construction bug: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling Sign on a Signer created as awssig.Signer{} or with only Region or only Service populated; a config struct that forgot to propagate region/service into the signer.

Common situations: Config where AWS_REGION is unset so Region stays empty; hardcoding Service only for S3 then reusing the signer for another service; constructing the signer before configuration loading completes.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/e49eef0b7afe46a9. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/awssig/awssig.go:68

type Signer struct {
	Region  string
	Service string
}

// Sign computes the SigV4 signature for req against the given payload and sets
// the Authorization, X-Amz-Date, X-Amz-Content-Sha256 (and, when present,
// X-Amz-Security-Token) headers on req. The Host header is derived from req.URL.
//
// payloadHash is the lowercase hex SHA-256 of the request body; pass
// HashPayload(body) for the common case, or UnsignedPayload() for streaming
// bodies that must not be buffered. now fixes the signing instant (use
// time.Now().UTC()); it is a parameter so tests are deterministic.
//
// Sign returns an error only for malformed inputs (no region/service, missing
// credentials, unparseable URL). It never returns the secret in the error.
func (s Signer) Sign(req *http.Request, creds Credentials, payloadHash string, now time.Time) error {
	if s.Region == "" || s.Service == "" {
		return fmt.Errorf("awssig: signer requires region and service")
	}
	if !creds.Valid() {
		return fmt.Errorf("awssig: incomplete AWS credentials")
	}
	if req.URL == nil {
		return fmt.Errorf("awssig: request has no URL")
	}
	now = now.UTC()
	amzDate := now.Format("20060102T150405Z")
	dateStamp := now.Format("20060102")

	host := req.URL.Host
	if req.Host != "" {
		host = req.Host
	}
	req.Header.Set("Host", host)
	req.Header.Set("X-Amz-Date", amzDate)
	req.Header.Set("X-Amz-Content-Sha256", payloadHash)

View on GitHub (pinned to 3ee70a1026)