{"record":{"id":"e49eef0b7afe46a9","repo":"JuliusBrussee/caveman","slug":"awssig-signer-requires-region-and-service","errorCode":null,"errorMessage":"awssig: signer requires region and service","messagePattern":"awssig: signer requires region and service","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/awssig/awssig.go","lineNumber":68,"sourceCode":"type Signer struct {\n\tRegion  string\n\tService string\n}\n\n// Sign computes the SigV4 signature for req against the given payload and sets\n// the Authorization, X-Amz-Date, X-Amz-Content-Sha256 (and, when present,\n// X-Amz-Security-Token) headers on req. The Host header is derived from req.URL.\n//\n// payloadHash is the lowercase hex SHA-256 of the request body; pass\n// HashPayload(body) for the common case, or UnsignedPayload() for streaming\n// bodies that must not be buffered. now fixes the signing instant (use\n// time.Now().UTC()); it is a parameter so tests are deterministic.\n//\n// Sign returns an error only for malformed inputs (no region/service, missing\n// credentials, unparseable URL). It never returns the secret in the error.\nfunc (s Signer) Sign(req *http.Request, creds Credentials, payloadHash string, now time.Time) error {\n\tif s.Region == \"\" || s.Service == \"\" {\n\t\treturn fmt.Errorf(\"awssig: signer requires region and service\")\n\t}\n\tif !creds.Valid() {\n\t\treturn fmt.Errorf(\"awssig: incomplete AWS credentials\")\n\t}\n\tif req.URL == nil {\n\t\treturn fmt.Errorf(\"awssig: request has no URL\")\n\t}\n\tnow = now.UTC()\n\tamzDate := now.Format(\"20060102T150405Z\")\n\tdateStamp := now.Format(\"20060102\")\n\n\thost := req.URL.Host\n\tif req.Host != \"\" {\n\t\thost = req.Host\n\t}\n\treq.Header.Set(\"Host\", host)\n\treq.Header.Set(\"X-Amz-Date\", amzDate)\n\treq.Header.Set(\"X-Amz-Content-Sha256\", payloadHash)","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/awssig/awssig.go#L50-L86","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set both Region and Service when constructing Signer, e.g. awssig.Signer{Region: \"us-east-1\", Service: \"s3\"}.","Check where the signer is built and confirm the region/service config values are loaded before construction.","Add a startup validation that fails fast if region or service config is empty."],"exampleFix":"// before\nsigner := awssig.Signer{Region: cfg.Region}\n// after\nsigner := awssig.Signer{Region: cfg.Region, Service: \"s3\"}","handlingStrategy":"validation","validationCode":"func signerReady(s awssig.Signer) bool { return s.Region != \"\" && s.Service != \"\" }\nif !signerReady(signer) {\n    return errors.New(\"awssig signer misconfigured: region and service are required\")\n}","typeGuard":null,"tryCatchPattern":"if err := signer.Sign(req, creds, hash, now); err != nil {\n    if strings.Contains(err.Error(), \"requires region and service\") {\n        return fmt.Errorf(\"signer construction bug: %w\", err)\n    }\n    return err\n}","preventionTips":["Always construct Signer with both Region and Service via a single helper/constructor.","Fail at config-load time if AWS_REGION (or equivalent) is empty.","Add a unit test that builds the production signer and asserts signerReady."],"tags":["aws","sigv4","configuration","signing"],"backgroundTag":"missing-required-config-field","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}