Repository: awspring/spring-cloud-aws (Java)

Issue:
S3 KMS condition has incorrect capitalization
**Type**: Bug

**Component**:
S3

**Describe the bug**
`S3EncryptionConditional` has a nested condition `KmsKeyProperty` which is conditional on property `spring.cloud.aws.s3.encryption.keyId`. According to property binding rules, `keyId` should be `key-id`. This is also reflected in the following section of the autogenerated `spring-configuration-metadata.json`:

```json
{
  "name": "spring.cloud.aws.s3.encryption.key-id",
  "type": "java.lang.String",
  "sourceType": "io.awspring.cloud.autoconfigure.s3.properties.S3EncryptionProperties"
}
```

which is the property name suggested by the IDE. Unfortunately this causes the condition not to match, leading to the creation of an S3Client *without* client-side encryption enabled. To match the condition, `keyId` must be used in the application.yaml instead of `key-id`.

**Sample**

```yaml
spring:
  cloud:
    aws:
      credentials:
        ...
      s3:
        encryption:
          key-id: aaaaaaaa-bbbb-4444-cccc-dddddddddddd
```

```java
@Autowired
S3Client s3Client;

assert s3Client instanceof S3EncryptionClient; // fails
```


Discussion:
@gbaso would you like to contribute a fix?
@maciejwalkowiak yes, I will submit a PR in the following days



Patch:
diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/s3/S3EncryptionConditional.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/s3/S3EncryptionConditional.java
index f49d0e4ad..0cb1d9b0d 100644
--- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/s3/S3EncryptionConditional.java
+++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/s3/S3EncryptionConditional.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013-2024 the original author or authors.
+ * Copyright 2013-2025 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
  * Conditional for creating {@link software.amazon.encryption.s3.S3EncryptionClient}. Will only create
  * S3EncryptionClient if one of following is true.
  * @author Matej Nedic
+ * @author Giacomo Baso
  * @since 3.3.0
  */
 public class S3EncryptionConditional extends AnyNestedCondition {
@@ -38,7 +39,7 @@ static class RSAProviderCondition {
 	static class AESProviderCondition {
 	}
 
-	@ConditionalOnProperty(name = "spring.cloud.aws.s3.encryption.keyId")
+	@ConditionalOnProperty(name = "spring.cloud.aws.s3.encryption.key-id")
 	static class KmsKeyProperty {
 	}
 }


Test patch:
diff --git a/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/s3/S3AutoConfigurationTests.java b/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/s3/S3AutoConfigurationTests.java
index a00c90c1f..2d3b060e3 100644
--- a/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/s3/S3AutoConfigurationTests.java
+++ b/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/s3/S3AutoConfigurationTests.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2025 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -66,6 +66,7 @@
  *
  * @author Maciej Walkowiak
  * @author Matej Nedic
+ * @author Giacomo Baso
  */
 class S3AutoConfigurationTests {
 
@@ -138,7 +139,7 @@ class S3ClientTests {
 		@Test
 		void s3ClientCanBeOverwritten() {
 			contextRunnerEncryption
-					.withPropertyValues("spring.cloud.aws.s3.encryption.keyId:234abcd-12ab-34cd-56ef-1234567890ab")
+					.withPropertyValues("spring.cloud.aws.s3.encryption.key-id:234abcd-12ab-34cd-56ef-1234567890ab")
 					.withUserConfiguration(CustomS3ClientConfiguration.class).run(context -> {
 						assertThat(context).hasSingleBean(S3Client.class);
 					});
@@ -167,6 +168,15 @@ void createsEncryptionClientBackedByAes() {
 				assertThat(context).hasSingleBean(S3AesProvider.class);
 			});
 		}
+
+		@Test
+		void createsEncryptionClientBackedByKms() {
+			contextRunnerEncryption
+					.withPropertyValues("spring.cloud.aws.s3.encryption.key-id:234abcd-12ab-34cd-56ef-1234567890ab")
+					.run(context -> {
+						assertThat(context).hasSingleBean(S3EncryptionClient.class);
+					});
+		}
 	}
 
 	@Nested