Spring cloud s3 service connectors to use s3 in CloudFoundry, Heroku or Local Config.
You can find an example app here: https://github.com/orange-cloudfoundry/s3-connectors-poc
Maven:
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-elpaaso-maven</id>
<name>bintray</name>
<url>http://dl.bintray.com/elpaaso/maven</url>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
Gradle:
repositories {
// ...
jcenter()
maven { url "http://dl.bintray.com/elpaaso/maven" }
}
First, make a version propertie:
Maven:
<properties>
<s3.connectors.version>2.0.15</s3.connectors.version>
</properties>
Gradle:
ext {
s3ConnectorsVersion = "2.0.15"
}
Maven:
<dependency>
<groupId>com.orange.spring.cloud.connectors</groupId>
<artifactId>spring-cloud-s3-connectors-cloudfoundry</artifactId>
<version>${s3.connectors.version}</version>
</dependency>
Gradle:
dependencies {
compile("com.orange.spring.cloud.connectors:spring-cloud-s3-connectors-cloudfoundry:$s3ConnectorsVersion")
}
Maven:
<dependency>
<groupId>com.orange.spring.cloud.connectors</groupId>
<artifactId>spring-cloud-s3-connectors-localconfig</artifactId>
<version>${s3.connectors.version}</version>
</dependency>
Gradle:
dependencies {
compile("com.orange.spring.cloud.connectors:spring-cloud-s3-connectors-localconfig:$s3ConnectorsVersion")
}
Maven:
<dependency>
<groupId>com.orange.spring.cloud.connectors</groupId>
<artifactId>spring-cloud-s3-connectors-heroku</artifactId>
<version>${s3.connectors.version}</version>
</dependency>
Gradle:
dependencies {
compile("com.orange.spring.cloud.connectors:spring-cloud-s3-connectors-heroku:$s3ConnectorsVersion")
}
Here the bootstrap for your spring boot app to get a SpringCloudBlobStore
which will help you to manipulate your s3 bucket:
@Configuration
@ServiceScan
public class S3Config extends AbstractCloudConfig {
@Autowired
private SpringCloudBlobStoreContext springCloudBlobStoreContext;
@Bean
public SpringCloudBlobStore blobStore() {
return this.springCloudBlobStoreContext.getSpringCloudBlobStore();
}
}
Usage example:
@Component
public class ExampleS3 {
@Autowired
@Qualifier(value = "blobStore")
protected SpringCloudBlobStore blobStore;
private final static String myfile = "mysuperfile.txt";
public void pushData(){
Blob blob = this.blobStore.blobBuilder(myfile).build();
blob.setPayload("test data");
blobStore.putBlob(blob);
// this will push 'test data' with the filename *mysuperfile.txt* to your connected s3
}
public void retrieveData(){
Blob blob = blobStore.getBlob(fileName);
String line;
BufferedReader br = new BufferedReader(new InputStreamReader(blob.getPayload().openStream()));
String content = "";
while ((line = br.readLine()) != null) {
content += line;
} // <- this will retrieve the content of the file *mysuperfile.txt* from your connected s3 (the content is 'test data' )
}
}
- Create a s3 service from the marketplace (e.g with p-riakcs:
cf cs p-riakcs developper nameofmyservice
) - Push your app with
cf push
- After the app has been pushed bind your new created service to your app (e.g:
cf bs nameofmyapp nameofmyservice
) - Restage your app:
cf restage nameofmyapp
- Create and push your app on heroku
- To use s3 connectors you have three ways
- Use the Bucketeer addon
- Use the native support of S3 on heroku: https://devcenter.heroku.com/articles/s3
- Set an env var called
S3_URL
with the address of your s3 bucket (e.g:S3_URL=s3://myaccesskey:[email protected]/mybucketname
)
- Restart your app:
heroku restart
- Follow the tutorial made by spring to create the property file: http://cloud.spring.io/spring-cloud-connectors/spring-cloud-connectors.html#_local_configuration_connector
- Add to your property file or system properties a key/value pair with this form:
spring.cloud.myServiceS3Name=s3://myaccesskey:[email protected]/mybucketname
(myServiceS3Name
can be replace to what you want only the schemes3
is required in value)
You can find an example app here: https://github.com/Orange-OpenSource/s3-connectors-poc
In order to use HTTP Proxy you can set these JVM properties:
- http.proxyHost: host of the proxy
- http.proxyPort: port of the proxy
- http.proxyUsername (Optional): User name to connect to the proxy
- http.proxyPassword (Optional): Password to connect to the proxy
- skip.ssl.verification (Optional): If set to true it will trust all certificates
Report any issues or pull request on this repo.
Feedbacks for heroku are really welcome.