Skip to content

Commit b0c1cfd

Browse files
committed
Add properties to make the SSM client endpoint configurable (#4)
Add configuration properties to make the SSM client endpoint configurable. Update documentation accordingly and bump the library version.
1 parent ca5eb80 commit b0c1cfd

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.coveo</groupId>
77
<artifactId>spring-boot-parameter-store-integration</artifactId>
8-
<version>1.0.1</version>
8+
<version>1.1.0</version>
99

1010
<name>Spring Boot Parameter Store Integration</name>
1111
<description>An integration of Amazon Web Services' Systems Manager Parameter Store for Spring Boot's properties injection.</description>

readme.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The library was tested and worked properly with:
2626
<dependency>
2727
<groupId>com.coveo</groupId>
2828
<artifactId>spring-boot-parameter-store-integration</artifactId>
29-
<version>1.0.0</version>
29+
<version>1.1.0</version>
3030
</dependency>
3131
```
3232

@@ -44,11 +44,13 @@ String value;
4444
```
4545

4646
#### You might be wondering why use slashes (`/`)?
47-
The AWS Parameter Store already uses this naming pattern to classify your properties as you would do with folders. Using this prefix to limit the number of calls to AWS at boot seemed natural. This means properties not prefixed with `/` can't yet be fetched in the AWS Parameter Store using this lib.
47+
The AWS Parameter Store already uses this naming pattern to classify your properties as you would do with folders. Using this prefix to limit the number of calls to AWS at boot seemed natural. This means that properties not prefixed with `/` can't yet be fetched in the AWS Parameter Store using this lib.
4848

49-
## AWS Credentials
49+
## AWS Client
5050

51-
The lib uses the [DefaultAWSCredentialProviderChain](https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html). This means if your code is running on an EC2 instance that has access to a Parameter Store property and its associated KMS key, the library should be able to fetch it without any configuration.
51+
The lib uses the [DefaultAWSCredentialProviderChain](https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html) and the [DefaultAWSRegionProviderChain](https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/regions/DefaultAwsRegionProviderChain.html). This means that if your code is running on an EC2 instance that has access to a Parameter Store property and its associated KMS key, the library should be able to fetch it without any configuration.
52+
53+
If you need to use a custom endpoint for the AWS Simple Systems Management client, you can set the property `awsParameterStoreSource.ssmClient.endpointConfiguration.endpoint`. For more details, see the [AWSClientBuilder.EndpointConfiguration](https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/client/builder/AwsClientBuilder.EndpointConfiguration.html) class, which is used to configure the client. By default, the associated signing region is fetched from [DefaultAWSRegionProviderChain](https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/regions/DefaultAwsRegionProviderChain.html), but if you need to specify a different one, you can use the property `awsParameterStoreSource.ssmClient.endpointConfiguration.signingRegion`. Note that this only sets the `signingRegion` for the endpoint and not the aws client region. Region configuration should be done using the providers available from the [DefaultAWSRegionProviderChain](https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/regions/DefaultAwsRegionProviderChain.html).
5254

5355
## Using Spring Boot's Placeholder Properties
5456

src/main/java/com/coveo/configuration/parameterstore/ParameterStorePropertySourceEnvironmentPostProcessor.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import org.springframework.core.env.ConfigurableEnvironment;
66
import org.springframework.util.ObjectUtils;
77

8+
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
9+
import com.amazonaws.regions.DefaultAwsRegionProviderChain;
10+
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
811
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder;
912

1013
public class ParameterStorePropertySourceEnvironmentPostProcessor implements EnvironmentPostProcessor
@@ -14,6 +17,8 @@ public class ParameterStorePropertySourceEnvironmentPostProcessor implements Env
1417
static final String PARAMETER_STORE_ACCEPTED_PROFILES_CONFIGURATION_PROPERTY = "awsParameterStorePropertySource.enabledProfiles";
1518
static final String PARAMETER_STORE_ENABLED_CONFIGURATION_PROPERTY = "awsParameterStorePropertySource.enabled";
1619
static final String PARAMETER_STORE_HALT_BOOT_CONFIGURATION_PROPERTY = "awsParameterStorePropertySource.haltBoot";
20+
static final String PARAMETER_STORE_CLIENT_ENDPOINT_CONFIGURATION_PROPERTY = "awsParameterStoreSource.ssmClient.endpointConfiguration.endpoint";
21+
static final String PARAMETER_STORE_CLIENT_ENDPOINT_SIGNING_REGION_CONFIGURATION_PROPERTY = "awsParameterStoreSource.ssmClient.endpointConfiguration.signingRegion";
1722

1823
private static final String PARAMETER_STORE_PROPERTY_SOURCE_NAME = "AWSParameterStorePropertySource";
1924

@@ -25,7 +30,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp
2530
if (!initialized && isParameterStorePropertySourceEnabled(environment)) {
2631
environment.getPropertySources()
2732
.addFirst(new ParameterStorePropertySource(PARAMETER_STORE_PROPERTY_SOURCE_NAME,
28-
new ParameterStoreSource(AWSSimpleSystemsManagementClientBuilder.defaultClient(),
33+
new ParameterStoreSource(buildAWSSimpleSystemsManagementClient(environment),
2934
environment.getProperty(PARAMETER_STORE_HALT_BOOT_CONFIGURATION_PROPERTY,
3035
Boolean.class,
3136
Boolean.FALSE))));
@@ -42,4 +47,16 @@ private boolean isParameterStorePropertySourceEnabled(ConfigurableEnvironment en
4247
|| (!ObjectUtils.isEmpty(userDefinedEnabledProfiles)
4348
&& environment.acceptsProfiles(userDefinedEnabledProfiles));
4449
}
50+
51+
private AWSSimpleSystemsManagement buildAWSSimpleSystemsManagementClient(ConfigurableEnvironment environment)
52+
{
53+
if (environment.containsProperty(PARAMETER_STORE_CLIENT_ENDPOINT_CONFIGURATION_PROPERTY)) {
54+
return AWSSimpleSystemsManagementClientBuilder.standard()
55+
.withEndpointConfiguration(new EndpointConfiguration(environment.getProperty(PARAMETER_STORE_CLIENT_ENDPOINT_CONFIGURATION_PROPERTY),
56+
environment.getProperty(PARAMETER_STORE_CLIENT_ENDPOINT_SIGNING_REGION_CONFIGURATION_PROPERTY,
57+
new DefaultAwsRegionProviderChain().getRegion())))
58+
.build();
59+
}
60+
return AWSSimpleSystemsManagementClientBuilder.defaultClient();
61+
}
4562
}

0 commit comments

Comments
 (0)