amazon-web-servicesamazon-s3lifecycleaws-sdk-net

AWS S3 PutLifecycleConfigurationAsync throws AmazonS3Exception


I'm using the AWS C# SDK. After getting the Lifecycle configuration of a bucket using the GetLifecycleConfigurationAsync(bucketName) method, I'm trying to save this configuartion (even without any change):

var result = await _client.PutLifecycleConfigurationAsync(new PutLifecycleConfigurationRequest()
            {
                BucketName = bucketName,
                Configuration = bucketLCConfiguration
            });

This throws AmazonS3Exception:

The XML you provided was not well-formed or did not validate against our published schema


Solution

  • Rules created manually in the AWS console with scope of "Entire bucket" can contain configuration which include Filter = null. This will cause an exception when trying to save this configuration. One way to "fix" it is before saving set the null filter to empty one:

    rule.Filter = new LifecycleFilter
                {
                    LifecycleFilterPredicate = new LifecyclePrefixPredicate
                    {
                        Prefix = string.Empty
                    }
                };