1
1
package services
2
2
3
- import com .amazonaws .services .s3 .model .CannedAccessControlList .{Private , PublicRead }
4
- import com .amazonaws .services .s3 .model ._
5
- import com .amazonaws .services .s3 .{AmazonS3 , AmazonS3Client }
3
+ // import com.amazonaws.services.s3.model.CannedAccessControlList.{Private, PublicRead}
4
+ // import com.amazonaws.services.s3.model._
6
5
import com .amazonaws .util .StringInputStream
7
6
import com .gu .etagcaching .aws .s3 .ObjectId
8
7
import common .GuLogging
9
8
import conf .Configuration
10
9
import model .PressedPageType
11
10
import org .joda .time .DateTime
12
11
import services .S3 .logS3ExceptionWithDevHint
12
+ import software .amazon .awssdk .services .s3 .model .{GetObjectRequest , NoSuchKeyException }
13
+ import utils .AWSv2
13
14
14
15
import java .io ._
15
16
import java .util .zip .GZIPOutputStream
@@ -19,17 +20,17 @@ trait S3 extends GuLogging {
19
20
20
21
lazy val bucket = Configuration .aws.frontendStoreBucket
21
22
22
- lazy private val client : AmazonS3 = AmazonS3Client .builder
23
- .withCredentials(Configuration .aws.credentials.get)
24
- .withRegion(conf.Configuration .aws.region)
25
- .build()
23
+ lazy private val client = AWSv2 .S3Sync
26
24
27
25
private def withS3Result [T ](key : String )(action : S3Object => T ): Option [T ] = {
28
26
val objectId = ObjectId (bucket, key)
29
27
try {
30
- val request = new GetObjectRequest ( bucket, key)
28
+ val request = GetObjectRequest .builder(). bucket(bucket). key(key).build( )
31
29
val result = client.getObject(request)
32
- log.info(s " S3 got ${result.getObjectMetadata.getContentLength} bytes from ${result.getKey}" )
30
+
31
+ val getObjectResponse = result.response()
32
+
33
+ log.info(s " S3 got ${getObjectResponse.contentLength} bytes from $key" )
33
34
34
35
// http://stackoverflow.com/questions/17782937/connectionpooltimeoutexception-when-iterating-objects-in-s3
35
36
try {
@@ -41,10 +42,10 @@ trait S3 extends GuLogging {
41
42
result.close()
42
43
}
43
44
} catch {
44
- case e : AmazonS3Exception if e.getStatusCode == 404 =>
45
+ case e : NoSuchKeyException if e.statusCode == 404 =>
45
46
log.warn(s " not found at ${objectId.s3Uri}" )
46
47
None
47
- case e : AmazonS3Exception =>
48
+ case e : software.amazon.awssdk.services.s3.model. S3Exception =>
48
49
logS3ExceptionWithDevHint(objectId, e)
49
50
None
50
51
case e : Exception =>
0 commit comments