Skip to content

Commit f61be52

Browse files
committed
s3 with credentials
1 parent 9c6dd5e commit f61be52

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

build.sbt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,28 @@ mappings in upload := Seq()
2020

2121
upload := {
2222
import com.amazonaws.{ClientConfiguration, Protocol}
23-
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
23+
import com.amazonaws.auth.{BasicAWSCredentials, AWSStaticCredentialsProvider, DefaultAWSCredentialsProviderChain}
2424
import com.amazonaws.services.s3.AmazonS3ClientBuilder
25-
import com.amazonaws.services.s3.model.{CannedAccessControlList, PutObjectRequest}
25+
import com.amazonaws.services.s3.model.PutObjectRequest
2626
import com.amazonaws.regions.Regions
2727

28-
// the publishing job runs on an EC2 instance that has access to the S3 bucket via its IAM instance profile
29-
val client = AmazonS3ClientBuilder.standard.withRegion(Regions.US_EAST_1).build
28+
def env(v: String) = {
29+
val r = System.getenv(v)
30+
assert(r != null, s"Credentials env not specified: $v")
31+
r
32+
}
33+
34+
val awsCreds = new BasicAWSCredentials(env("AWS_ACCESS_KEY_ID"), env("AWS_SECRET_ACCESS_KEY"))
35+
val client = AmazonS3ClientBuilder.standard
36+
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
37+
.withRegion(Regions.US_EAST_1)
38+
.build
3039

3140
val log = streams.value.log
3241

3342
(mappings in upload).value map { case (file, key) =>
3443
log.info("Uploading "+ file.getAbsolutePath() +" as "+ key)
35-
36-
// since the s3 bucket is in a separate account from where the EC2 CI instances are, must explicitly set acl as public-read
37-
client.putObject(new PutObjectRequest("downloads.typesafe.com", key, file).withCannedAcl(CannedAccessControlList.PublicRead))
44+
client.putObject(new PutObjectRequest("downloads.typesafe.com", key, file))
3845
}
3946
}
4047

0 commit comments

Comments
 (0)