Skip to content

Commit

Permalink
fix(prometheus-scaler): AWS signv4 parses region if provided (#5421)
Browse files Browse the repository at this point in the history
Signed-off-by: Siva Guruvareddiar <[email protected]>
Co-authored-by: Jorge Turrado Ferrero <[email protected]>
  • Loading branch information
sguruvar and JorTurFer authored Jan 20, 2024
1 parent 072fcf0 commit a815f06
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Here is an overview of all new **experimental** features:

### Fixes

- **General**: TODO ([#XXX](https://github.com/kedacore/keda/issues/XXX))
- **Prometheus Scaler**: Fix for missing AWS region from metadata ([#5419](https://github.com/kedacore/keda/issues/5419))

### Deprecations

Expand Down
8 changes: 5 additions & 3 deletions pkg/scalers/aws/aws_sigv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
// roundTripper adds custom round tripper to sign requests
type roundTripper struct {
client *amp.Client
region string
}

var (
Expand All @@ -60,7 +59,7 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
// "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" is the sha256 of ""
const reqHash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"

err = rt.client.Options().HTTPSignerV4.SignHTTP(req.Context(), cred, req, reqHash, "aps", rt.region, time.Now())
err = rt.client.Options().HTTPSignerV4.SignHTTP(req.Context(), cred, req, reqHash, "aps", rt.client.Options().Region, time.Now())
if err != nil {
return nil, err
}
Expand All @@ -75,6 +74,10 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
func parseAwsAMPMetadata(config *scalersconfig.ScalerConfig) (*awsConfigMetadata, error) {
meta := awsConfigMetadata{}

if val, ok := config.TriggerMetadata["awsRegion"]; ok && val != "" {
meta.awsRegion = val
}

auth, err := GetAwsAuthorization(config.TriggerUniqueKey, config.PodIdentity, config.TriggerMetadata, config.AuthParams, config.ResolvedEnv)
if err != nil {
return nil, err
Expand Down Expand Up @@ -109,7 +112,6 @@ func NewSigV4RoundTripper(config *scalersconfig.ScalerConfig) (http.RoundTripper
client := amp.NewFromConfig(*awsCfg, func(o *amp.Options) {})
rt := &roundTripper{
client: client,
region: metadata.awsRegion,
}

return rt, nil
Expand Down

0 comments on commit a815f06

Please sign in to comment.