aws / aws-sdk-go-v2

AWS SDK for the Go programming language.
https://aws.github.io/aws-sdk-go-v2/docs/
Apache License 2.0
2.64k stars 638 forks source link

S3 Event Notification Filter Rule Names changing string value from case insensitive to case sensitive #2849

Open ge0Aja opened 1 week ago

ge0Aja commented 1 week ago

Describe the bug

I'm using FilterRuleNames to have a prefix filter when creating an event notification for an S3 bucket. I'm using the const enum values provided by the SDK to create the filter. However, when I query back the created event notification and match against the filter rule name I get empty values. I've checked on the created event notification and the rule seem to be there, but with a different name i.e. Prefix instead of prefix.

Regression Issue

Expected Behavior

I expect to find the created rule using the filter rule name consts provided by the SDK.

Current Behavior

If we iterate over the created filter names we won't be able to match any of the const names provided by the SDK

Reproduction Steps

Create an event notification on an S3 bucket with a filter rule to target a specific prefix for example

var itemId = "ID"
var lambdaArn = "arn"
var prefix = "prefix"

_, err = s3Client.PutBucketNotificationConfiguration(context.Background(), &s3.PutBucketNotificationConfigurationInput{
        Bucket: &bucketName,
        NotificationConfiguration: &types.NotificationConfiguration{
            LambdaFunctionConfigurations: []types.LambdaFunctionConfiguration{
                types.LambdaFunctionConfiguration{
                    Id:                &itemId,
                    LambdaFunctionArn: &lambdaArn,
                    Events:             []types.Event{types.EventS3ObjectCreated, types.EventS3ObjectRemoved},
                    Filter: &types.NotificationConfigurationFilter{
                        Key: &types.S3KeyFilter{
                            FilterRules: []types.FilterRule{
                                {
                                    Name:  types.FilterRuleNamePrefix,
                                    Value: &prefix,
                                },
                            },
                        },
                    },
                },
            },
        },
    })

Try to query it back again and switch case match using the prefix enum value

var prefix string
var suffix string

out, err := s3Client.GetBucketNotificationConfiguration(context.Background(), &s3.GetBucketNotificationConfigurationInput{
        Bucket: &bucketName,
})

if err != nil {
    return err
}

lfcs := out.LambdaFunctionConfigurations

for _, lfc := range lfcs.LambdaFunctionConfigurations {
    for _, rule := range lfc.Filter.Key.FilterRules {
        if rule.Value == nil {
            continue
        }

        switch rule.Name {
        case types.FilterRuleNamePrefix:
            prefix = *rule.Value
        default:
        }
    }
}

prefix will always be ""

Possible Solution

No response

Additional Information/Context

No response

SDK version used

v1.32.2

Environment details (Version of Go (go version)? OS name and version, etc.)

go 1.23.1 / ubuntu 22.04

lucix-aws commented 1 week ago

You appear to be using SDK v2 based on your code sample. Transferring.

RanVaknin commented 5 days ago

Hi @ge0Aja ,

Thanks for reaching out. If I understand you correctly, your concerns is that when creating an event notification filter the filter name is prefix but when you are getting the result back from S3 using GetBucketNotificationConfiguration you get the filter name as Prefix.

The AWS SDKs are code generated from the API model of each AWS service it interacts with. The reason why the SDK is generated with the Filter Rule names as prefix and suffix (lower cased) is because this is how they are modeled in the S3 API model:

      "com.amazonaws.s3#FilterRuleName": {
            "type": "enum",
            "members": {
                "prefix": {
                    "target": "smithy.api#Unit",
                    "traits": {
                        "smithy.api#enumValue": "prefix"
                    }
                },
                "suffix": {
                    "target": "smithy.api#Unit",
                    "traits": {
                        "smithy.api#enumValue": "suffix"
                    }
                }
            }
        },

In addition, the S3 docs also showcase that to create those filter rules those names should be lower cased.

While I agree that this is confusing, the SDK team cannot do anything to change it since model changes must be changed upstream with the S3 service team itself, not on the SDK side. Even if the service decides to change the casing here, from a backwards compatibility standpoint, we wont be able to roll out the change since code that is reliant on the lower cased value will start breaking.

Let me know if I understood your concern, and if you have any questions that we can further assist with.

Thanks, Ran~