Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Add aws s3:// uri support #565

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/main/asciidoc/_configprops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
|cloud.aws.loader.queue-capacity | | The maximum queue capacity for backed up S3 requests. @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setQueueCapacity(int)
|cloud.aws.region.auto | true | Enables automatic region detection based on the EC2 meta data service.
|cloud.aws.region.static | |
|cloud.aws.region.use-default-aws-region-chain | false | Whether default AWS SDK region provider chain should be used when auto is set to true.
|cloud.aws.stack.auto | true | Enables the automatic stack name detection for the application.
|cloud.aws.stack.name | myStackName | The name of the manually configured stack name that will be used to retrieve the resources.

Expand Down
105 changes: 101 additions & 4 deletions docs/src/main/asciidoc/spring-cloud-aws.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ For milestones:
</repositories>
----

=== Amazon SDK dependency version management

Amazon SDK is released more frequently than Spring Cloud AWS. If you need to use newer version of AWS SDK than one configured by Spring Cloud AWS
add AWS SDK BOM to dependency management section making sure it is declared before any other BOM dependency that configures AWS SDK dependencies.

[source,xml,indent=0]
----
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>${aws-java-sdk.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
----

=== Amazon SDK configuration
The Spring Cloud AWS configuration is currently done using custom elements provided by Spring Cloud AWS namespaces.
JavaConfig will be supported soon. The configuration setup is done directly in Spring XML configuration files
Expand All @@ -108,6 +128,18 @@ use of the modules. A typical XML configuration to use Spring Cloud AWS is outli
</beans>
----

[TIP]
====
On application startup, for its internal purposes Spring Cloud AWS performs a check if application runs in AWS cloud environment
by using `EC2MetadataUtils` class provided by AWS SDK. Starting from version 1.11.678, AWS SDK logs a warning message with exception when this check is made outside of AWS environment.
This warning message can be hidden by setting `ERROR` logging level on `com.amazonaws.util.EC2MetadataUtils` class.

[source,indent=0]
----
logging.level.com.amazonaws.util.EC2MetadataUtils=error
----
====

==== SDK credentials configuration
In order to make calls to the Amazon Web Service the credentials must be configured for the the Amazon SDK. Spring Cloud AWS
provides support to configure an application context specific credentials that are used for _each_ service call for requests done
Expand Down Expand Up @@ -275,25 +307,40 @@ Spring Boot provides a standard way to define properties with property file or Y
AWS provides support to configure the credential information with the Spring Boot application configuration files.
Spring Cloud AWS provides the following properties to configure the credentials setup for the whole application.

Unless `cloud.aws.credentials.use-default-aws-credentials-chain` is set to `true`, Spring Cloud AWS configures following
credentials chain:

1. `AWSStaticCredentialsProvider` if `cloud.aws.credentials.access-key` is provided
2. `EC2ContainerCredentialsProviderWrapper` unless `cloud.aws.credentials.instance-profile` is set to `false`
3. `ProfileCredentialsProvider`

[cols="3*", options="header"]
|===
|property
|example
|description

|cloud.aws.credentials.accessKey
|cloud.aws.credentials.access-key
|AKIAIOSFODNN7EXAMPLE
|The access key to be used with a static provider

|cloud.aws.credentials.secretKey
|cloud.aws.credentials.secret-key
|wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
|The secret key to be used with a static provider

|cloud.aws.credentials.instanceProfile
|cloud.aws.credentials.instance-profile
|true
|Configures an instance profile credentials provider with no further configuration

|cloud.aws.credentials.useDefaultAwsCredentialsChain
|cloud.aws.credentials.profile-name
|default
|The name of a configuration profile in the specified configuration file

|cloud.aws.credentials.profile-path
|`~/.aws/credentials`
|The file path where the profile configuration file is located. Defaults to `~/.aws/credentials` if value is not provided

|cloud.aws.credentials.use-default-aws-credentials-chain
|true
|Use the DefaultAWSCredentials Chain instead of configuring a custom credentials chain
|===
Expand All @@ -315,6 +362,10 @@ The properties to configure the region are shown below
|true
|Enables automatic region detection based on the EC2 meta data service

|cloud.aws.region.use-default-aws-region-chain
|true
|Use the DefaultAWSRegion Chain instead of configuring a custom region chain

|cloud.aws.region.static
|eu-west-1
|Configures a static region for the application. Possible regions are (currently) us-east-1, us-west-1, us-west-2,
Expand Down Expand Up @@ -660,6 +711,17 @@ You can configure the following settings in a Spring Cloud `bootstrap.properties
|Can be used to disable the Parameter Store Configuration support even though the auto-configuration is on the classpath.
|===

[TIP]
====
In order to find out which properties are retrieved from AWS Parameter Store on application startup,
turn on `DEBUG` logging on `org.springframework.cloud.aws.paramstore.AwsParamStorePropertySource` class.

[source,indent=0]
----
logging.level.org.springframework.cloud.aws.paramstore.AwsParamStorePropertySource=debug
----
====

=== Integrating your Spring Cloud application with the AWS Secrets Manager

Spring Cloud provides support for centralized configuration, which can be read and made available as a regular Spring
Expand Down Expand Up @@ -2272,6 +2334,41 @@ public class SimpleResourceLoadingBean {
}
}
----
== CloudWatch Metrics
Spring Cloud AWS provides Spring Boot auto-configuration for Micrometer CloudWatch integration.
To send metrics to CloudWatch add a dependency to `spring-cloud-aws-actuator` module:

[source,xml,indent=0]
----
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-actuator</artifactId>
</dependency>
----

Additionally CloudWatch integration requires a value provided for `management.metrics.export.cloudwatch.namespace` configuration property.

Following configuration properties are available to configure CloudWatch integration:

[cols="3*", options="header"]
|===
|property
|default
|description

|management.metrics.export.cloudwatch.namespace
|
|The namespace which will be used when sending metrics to CloudWatch. This property is needed and must not be null.

|management.metrics.export.cloudwatch.enabled
|true
|If CloudWatch integration should be enabled. This property should be likely set to `false` for a local development profile.

|management.metrics.export.cloudwatch.step
|1m
|The interval at which metrics are sent to CloudWatch. The default is 1 minute.
|===

== Configuration properties

To see the list of all Spring Cloud AWS related configuration properties please check link:appendix.html[the Appendix page].
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
return;
}

Boolean useDefaultCredentialsChain = this.environment.getProperty(
AWS_CREDENTIALS_PROPERTY_PREFIX + ".use-default-aws-credentials-chain",
Boolean.class, false);
Boolean useDefaultCredentialsChain = this.environment
.getProperty(
AWS_CREDENTIALS_PROPERTY_PREFIX
+ ".use-default-aws-credentials-chain",
Boolean.class, false);
String accessKey = this.environment
.getProperty(AWS_CREDENTIALS_PROPERTY_PREFIX + ".access-key");
String secretKey = this.environment
Expand All @@ -99,7 +101,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
AWS_CREDENTIALS_PROPERTY_PREFIX + ".instance-profile",
Boolean.class, true)
&& !this.environment.containsProperty(
AWS_CREDENTIALS_PROPERTY_PREFIX + ".access-key"),
AWS_CREDENTIALS_PROPERTY_PREFIX + ".access-key"),
this.environment.getProperty(
AWS_CREDENTIALS_PROPERTY_PREFIX + ".profile-name",
DEFAULT_PROFILE_NAME),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,19 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
return;
}

registerRegionProvider(registry, this.environment.getProperty(
boolean useDefaultRegionChain = this.environment.getProperty(
AWS_REGION_PROPERTIES_PREFIX + ".use-default-aws-region-chain",
Boolean.class, false);

String staticRegion = this.environment
.getProperty(AWS_REGION_PROPERTIES_PREFIX + ".static");

boolean autoDetect = this.environment.getProperty(
AWS_REGION_PROPERTIES_PREFIX + ".auto", Boolean.class, true)
&& !StringUtils.hasText(this.environment
.getProperty(AWS_REGION_PROPERTIES_PREFIX + ".static")),
this.environment
.getProperty(AWS_REGION_PROPERTIES_PREFIX + ".static"));
&& !StringUtils.hasText(staticRegion);

registerRegionProvider(registry, autoDetect, useDefaultRegionChain,
staticRegion);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Properties related to AWS region configuration.
*
* @author Tom Gianos
* @author Maciej Walkowiak
* @since 2.0.2
* @see org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration
*/
Expand All @@ -30,6 +31,12 @@ public class AwsRegionProperties {
*/
private boolean auto = true;

/**
* Whether default AWS SDK region provider chain should be used when auto is set to
* true.
*/
private boolean useDefaultAwsRegionChain;

/**
* Configures a static region for the application. Possible regions are (currently)
* us-east-1, us-west-1, us-west-2, eu-west-1, eu-central-1, ap-southeast-1,
Expand Down Expand Up @@ -60,4 +67,12 @@ public void setStatic(String staticRegion) {
this.staticRegion = staticRegion;
}

public boolean isUseDefaultAwsRegionChain() {
return useDefaultAwsRegionChain;
}

public void setUseDefaultAwsRegionChain(boolean useDefaultAwsRegionChain) {
this.useDefaultAwsRegionChain = useDefaultAwsRegionChain;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCr
public void credentialsProvider_dashSeparatedPropertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(ContextCredentialsAutoConfiguration.class);
TestPropertyValues.of("cloud.aws.credentials.use-default-aws-credentials-chain:true")
TestPropertyValues
.of("cloud.aws.credentials.use-default-aws-credentials-chain:true")
.applyTo(this.context);
this.context.refresh();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@
import org.junit.After;
import org.junit.Test;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.cloud.aws.core.region.DefaultAwsRegionProviderChainDelegate;
import org.springframework.cloud.aws.core.region.Ec2MetadataRegionProvider;
import org.springframework.cloud.aws.core.region.StaticRegionProvider;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/**
* @author Agim Emruli
* @author Petromir Dzhunev
* @author Maciej Walkowiak
*/
public class ContextRegionProviderAutoConfigurationTest {

Expand Down Expand Up @@ -93,4 +97,23 @@ public void regionProvider_staticRegionConfigured_staticRegionProviderWithConfig
.isEqualTo(Region.getRegion(Regions.EU_WEST_1));
}

@Test
public void regionProvider_autoDetectionAndDefaultChainConfigured_DefaultAwsRegionProviderChainDelegateConfigured() {
// Arrange
this.context = new AnnotationConfigApplicationContext();
this.context.register(ContextRegionProviderAutoConfiguration.class);
TestPropertyValues.of("cloud.aws.region.auto:true").applyTo(this.context);
TestPropertyValues.of("cloud.aws.region.useDefaultAwsRegionChain:true")
.applyTo(this.context);

// Act
this.context.refresh();

// Assert
assertThat(this.context.getBean(DefaultAwsRegionProviderChainDelegate.class))
.isNotNull();
assertThatThrownBy(() -> this.context.getBean(Ec2MetadataRegionProvider.class))
.isInstanceOf(NoSuchBeanDefinitionException.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
+ importingClassMetadata.getClassName());

boolean autoDetect = annotationAttributes.getBoolean("autoDetect");
boolean useDefaultAwsRegionChain = annotationAttributes
.getBoolean("useDefaultAwsRegionChain");
String configuredRegion = annotationAttributes.getString("region");

registerRegionProvider(registry, autoDetect, configuredRegion);
registerRegionProvider(registry, autoDetect, useDefaultAwsRegionChain,
configuredRegion);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.amazonaws.regions.AwsRegionProviderChain;

import org.springframework.context.annotation.Import;

/**
Expand All @@ -29,11 +31,15 @@
* Service clients that are created inside the application context (by the Spring Cloud
* AWS classes). A region can be either manually configured
* {@link EnableContextRegion#region()} with a constant expression, dynamic expression
* (using a SpEL expression) or a place holder. The region can also be dynamically
* retrieved from the EC2 instance meta-data if the application context is running inside
* a EC2 instance by enabling the {@link EnableContextRegion#autoDetect()} attribute.
* (using a SpEL expression) or a place holder. If the application context is running
* inside a EC2 instance The region can also be dynamically retrieved from the EC2
* instance meta-data by enabling the {@link EnableContextRegion#autoDetect()} attribute
* or from the default AWS SDK {@link AwsRegionProviderChain} by enabling
* {@link EnableContextRegion#autoDetect()} and
* {@link EnableContextRegion#useDefaultAwsRegionChain()}.
*
* @author Agim Emruli
* @author Maciej Walkowiak
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
Expand All @@ -58,4 +64,12 @@
*/
boolean autoDetect() default false;

/**
* Whether default AWS SDK region provider chain should be used when auto is set to
* true.
* @return - if default AWS SDK region provider chain should be used for region
* resolution.
*/
boolean useDefaultAwsRegionChain() default false;

}
Loading