-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from svezfaz/103-S3-documentation
S3 - add documentation #103
- Loading branch information
Showing
14 changed files
with
411 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# S3 Connector | ||
|
||
The S3 connector provides Akka Stream sources and sinks to connect to [Amazon S3](https://aws.amazon.com/s3/). | ||
S3 stands for Simple Storage Service and is an object storage service with a web service interface. | ||
|
||
## Artifacts | ||
|
||
sbt | ||
: @@@vars | ||
```scala | ||
libraryDependencies += "com.lightbend.akka" %% "akka-stream-alpakka-s3" % "$version$" | ||
``` | ||
@@@ | ||
|
||
Maven | ||
: @@@vars | ||
```xml | ||
<dependency> | ||
<groupId>com.lightbend.akka</groupId> | ||
<artifactId>akka-stream-alpakka-s3_$scala.binaryVersion$</artifactId> | ||
<version>$version$</version> | ||
</dependency> | ||
``` | ||
@@@ | ||
|
||
Gradle | ||
: @@@vars | ||
```gradle | ||
dependencies { | ||
compile group: "com.lightbend.akka", name: "akka-stream-alpakka-s3_$scala.binaryVersion$", version: "$version$" | ||
} | ||
``` | ||
@@@ | ||
|
||
## Usage | ||
|
||
### Set up your S3 clients | ||
|
||
The S3 connector can be configured within your `application.conf` file. | ||
|
||
Configuration | ||
: @@snip (../../../../s3/src/main/resources/reference.conf) | ||
|
||
### Create an S3 client | ||
|
||
Scala | ||
: @@snip (../../../../s3/src/test/scala/akka/stream/alpakka/s3/scaladsl/S3ClientIntegrationSpec.scala) { #client } | ||
|
||
Java | ||
: @@snip (../../../../s3/src/test/java/akka/stream/alpakka/s3/javadsl/S3ClientTest.java) { #client } | ||
|
||
### Storing a file in S3 | ||
|
||
Scala | ||
: @@snip (../../../../s3/src/test/scala/akka/stream/alpakka/s3/scaladsl/S3SinkSpec.scala) { #upload } | ||
|
||
Java | ||
: @@snip (../../../../s3/src/test/java/akka/stream/alpakka/s3/javadsl/S3ClientTest.java) { #upload } | ||
|
||
### Downloading a file from S3 | ||
|
||
Scala | ||
: @@snip (../../../../s3/src/test/scala/akka/stream/alpakka/s3/scaladsl/S3SourceSpec.scala) { #download } | ||
|
||
Java | ||
: @@snip (../../../../s3/src/test/java/akka/stream/alpakka/s3/javadsl/S3ClientTest.java) { #download } | ||
|
||
### Running the example code | ||
|
||
The code in this guide is part of runnable tests of this project. You are welcome to edit the code and run it in sbt. | ||
|
||
Scala | ||
: ``` | ||
sbt | ||
> s3/test | ||
``` | ||
|
||
Java | ||
: ``` | ||
sbt | ||
> s3/test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
s3/src/test/java/akka/stream/alpakka/s3/javadsl/S3ClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2016-2017 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
package akka.stream.alpakka.s3.javadsl; | ||
|
||
import akka.NotUsed; | ||
import akka.actor.ActorSystem; | ||
import akka.http.javadsl.model.Uri; | ||
import akka.stream.ActorMaterializer; | ||
import akka.stream.Materializer; | ||
import akka.stream.alpakka.s3.auth.AWSCredentials; | ||
import akka.stream.alpakka.s3.auth.BasicCredentials; | ||
import akka.stream.alpakka.s3.scaladsl.S3WireMockBase; | ||
import akka.stream.javadsl.Sink; | ||
import akka.stream.javadsl.Source; | ||
import akka.util.ByteString; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class S3ClientTest extends S3WireMockBase { | ||
|
||
final Materializer materializer = ActorMaterializer.create(system()); | ||
|
||
//#client | ||
final AWSCredentials credentials = new BasicCredentials("my-AWS-access-key-ID", "my-AWS-password"); | ||
final S3Client client = new S3Client(credentials, "us-east-1", system(), materializer); | ||
//#client | ||
|
||
@Test | ||
public void multipartUpload() throws Exception { | ||
|
||
mockUpload(); | ||
|
||
//#upload | ||
final Sink<ByteString, CompletionStage<MultipartUploadResult>> sink = client.multipartUpload(bucket(), bucketKey()); | ||
//#upload | ||
|
||
final CompletionStage<MultipartUploadResult> resultCompletionStage = | ||
Source.single(ByteString.fromString(body())).runWith(sink, materializer); | ||
|
||
MultipartUploadResult result = resultCompletionStage.toCompletableFuture().get(5, TimeUnit.SECONDS); | ||
|
||
assertEquals(new MultipartUploadResult(Uri.create(url()), bucket(), bucketKey(), etag()), result); | ||
} | ||
|
||
@Test | ||
public void download() throws Exception { | ||
|
||
mockDownload(); | ||
|
||
//#download | ||
final Source<ByteString, NotUsed> source = client.download(bucket(), bucketKey()); | ||
//#download | ||
|
||
final CompletionStage<String> resultCompletionStage = | ||
source.map(ByteString::utf8String).runWith(Sink.head(), materializer); | ||
|
||
String result = resultCompletionStage.toCompletableFuture().get(5, TimeUnit.SECONDS); | ||
|
||
assertEquals(body(), result); | ||
} | ||
} |
93 changes: 0 additions & 93 deletions
93
s3/src/test/scala/akka/stream/alpakka/s3/impl/S3SinkSpec.scala
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
s3/src/test/scala/akka/stream/alpakka/s3/impl/S3SourceSpec.scala
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.