本文整理汇总了Scala中com.amazonaws.auth.DefaultAWSCredentialsProviderChain类的典型用法代码示例。如果您正苦于以下问题:Scala DefaultAWSCredentialsProviderChain类的具体用法?Scala DefaultAWSCredentialsProviderChain怎么用?Scala DefaultAWSCredentialsProviderChain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DefaultAWSCredentialsProviderChain类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: client
//设置package包名称以及导入依赖的类
package org.zalando.react.nakadi.commit.handlers.aws
import com.amazonaws.regions.Regions
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.services.dynamodbv2.document.DynamoDB
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient
import org.zalando.react.nakadi.properties.CommitProperties
trait Provider {
def client: DynamoDB
def leaseProperties: CommitProperties
}
class ClientProvider(override val leaseProperties: CommitProperties) extends Provider {
private val credentialsProviderChain = new DefaultAWSCredentialsProviderChain()
private val region = Regions.fromName(leaseProperties.awsCommitRegion)
override val client: DynamoDB = {
val c = new AmazonDynamoDBClient(credentialsProviderChain)
c.configureRegion(region)
new DynamoDB(c)
}
}
示例2: SQSConsumer
//设置package包名称以及导入依赖的类
package com.hivehome.kafka.connect.sqs
import javax.jms.{JMSException, MessageConsumer, Session}
import com.amazon.sqs.javamessaging.SQSConnectionFactory
import com.amazonaws.auth.{AWSCredentialsProviderChain, BasicAWSCredentials, DefaultAWSCredentialsProviderChain}
import com.amazonaws.internal.StaticCredentialsProvider
import com.amazonaws.regions.{Region, Regions}
object SQSConsumer {
def apply(conf: Conf): MessageConsumer = {
val chain = buildCredentialsProviderChain(conf)
createSQSConsumer(conf, chain)
}
@throws(classOf[JMSException])
private def createSQSConsumer(conf: Conf, chain: AWSCredentialsProviderChain): MessageConsumer = {
val region = Regions.fromName(conf.awsRegion)
val connectionFactory = SQSConnectionFactory.builder
.withRegion(Region.getRegion(region))
.withAWSCredentialsProvider(chain)
.build
val connection = connectionFactory.createConnection
val session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE)
val queue = session.createQueue(conf.queueName.get)
val consumer = session.createConsumer(queue)
connection.start()
consumer
}
private def buildCredentialsProviderChain(conf: Conf): AWSCredentialsProviderChain = {
(conf.awsKey, conf.awsSecret) match {
case (Some(key), Some(secret)) =>
val credentials = new BasicAWSCredentials(key, secret)
new AWSCredentialsProviderChain(new StaticCredentialsProvider(credentials), new DefaultAWSCredentialsProviderChain)
case _ => new DefaultAWSCredentialsProviderChain
}
}
}
示例3: createBucket
//设置package包名称以及导入依赖的类
package akka.persistence.s3
import java.io.InputStream
import com.amazonaws.auth.{ BasicAWSCredentials, DefaultAWSCredentialsProviderChain }
import com.amazonaws.services.s3.{ S3ClientOptions, AmazonS3Client }
import com.amazonaws.services.s3.model._
import scala.concurrent.{ Future, ExecutionContext }
trait S3Client {
val s3ClientConfig: S3ClientConfig
lazy val client: AmazonS3Client = {
val client =
if (s3ClientConfig.awsUseDefaultCredentialsProviderChain)
new AmazonS3Client(new DefaultAWSCredentialsProviderChain).withRegion(s3ClientConfig.region)
else
new AmazonS3Client(new BasicAWSCredentials(s3ClientConfig.awsKey, s3ClientConfig.awsSecret))
s3ClientConfig.endpoint.foreach { endpoint =>
client.withEndpoint(endpoint)
()
}
client.setS3ClientOptions(new S3ClientOptions()
.withPathStyleAccess(s3ClientConfig.options.pathStyleAccess)
.withChunkedEncodingDisabled(s3ClientConfig.options.chunkedEncodingDisabled))
client
}
def createBucket(bucketName: String)(implicit ec: ExecutionContext): Future[Bucket] = Future {
client.createBucket(bucketName)
}
def deleteBucket(bucketName: String)(implicit ec: ExecutionContext): Future[Unit] = Future {
client.deleteBucket(bucketName)
}
def putObject(bucketName: String, key: String, input: InputStream, metadata: ObjectMetadata)(implicit ec: ExecutionContext): Future[PutObjectResult] = Future {
client.putObject(new PutObjectRequest(bucketName, key, input, metadata))
}
def getObject(bucketName: String, key: String)(implicit ec: ExecutionContext): Future[S3Object] = Future {
client.getObject(new GetObjectRequest(bucketName, key))
}
def listObjects(request: ListObjectsRequest)(implicit ec: ExecutionContext): Future[ObjectListing] = Future {
client.listObjects(request)
}
def deleteObject(bucketName: String, key: String)(implicit ec: ExecutionContext): Future[Unit] = Future {
client.deleteObject(bucketName, key)
}
def deleteObjects(request: DeleteObjectsRequest)(implicit ec: ExecutionContext): Future[Unit] = Future {
client.deleteObjects(request)
}
}
示例4: LaunchConfiguration
//设置package包名称以及导入依赖的类
package catherine
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.services.autoscaling.AmazonAutoScalingClient
import com.amazonaws.services.autoscaling.model.{BlockDeviceMapping, CreateLaunchConfigurationRequest, DescribeLaunchConfigurationsRequest}
import scala.Some
import scala.collection.JavaConversions._
object LaunchConfiguration {
val client= new AmazonAutoScalingClient(new DefaultAWSCredentialsProviderChain)
def clone(launchConfigurationOld: String,
launchConfigurationNew: String,
instanceType: String,
encryption: Option[Boolean] = None,
spotPrice: String = null,
iam: Option[String] = None) {
val result = client.describeLaunchConfigurations(
new DescribeLaunchConfigurationsRequest().withLaunchConfigurationNames(launchConfigurationOld)
).getLaunchConfigurations
require (result.size() != 0, "No configuration with name " + launchConfigurationOld)
val lc = result.head
client.createLaunchConfiguration(
(encryption match{
case Some (e) =>
new CreateLaunchConfigurationRequest()
.withBlockDeviceMappings(
lc.getBlockDeviceMappings.
map(b =>
b.withEbs(b.getEbs.withEncrypted(e)))
)
case None =>
new CreateLaunchConfigurationRequest()
.withBlockDeviceMappings(
lc.getBlockDeviceMappings
)
})
.withIamInstanceProfile(iam.getOrElse(lc.getIamInstanceProfile))
.withImageId(lc.getImageId)
.withLaunchConfigurationName(launchConfigurationNew)
.withSecurityGroups(lc.getSecurityGroups)
.withSpotPrice(spotPrice)
.withUserData(lc.getUserData)
.withInstanceType(instanceType)
.withKeyName(lc.getKeyName)
.withAssociatePublicIpAddress(true)
)
}
}
示例5: ApplicationStartupS3DAO
//设置package包名称以及导入依赖的类
package daos
import java.io.{File, FileOutputStream, InputStream}
import javax.inject.{Inject, Singleton}
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.regions.Regions
import com.amazonaws.services.s3.{AmazonS3, AmazonS3ClientBuilder}
import org.apache.commons.io.IOUtils
import play.api.Configuration
@Singleton
class ApplicationStartupS3DAO @Inject()(config: Configuration) {
private val s3: AmazonS3 = AmazonS3ClientBuilder.standard()
.withCredentials(new DefaultAWSCredentialsProviderChain())
.withRegion(Regions.EU_WEST_2)
.build()
private val bucketName = config.underlying.getString("s3-static")
def downloadImageToTempFile(key: String): File = {
val inputStream: InputStream = s3.getObject(bucketName, key).getObjectContent
val tempFile = File.createTempFile(s"temp-file-$key", ".tmp")
tempFile.deleteOnExit()
val out = new FileOutputStream(tempFile)
IOUtils.copy(inputStream, out)
inputStream.close()
out.close()
tempFile
}
}
示例6: DynamoDbConfigurationSource
//设置package包名称以及导入依赖的类
package com.gu.cm
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.regions.RegionUtils
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient
import com.amazonaws.services.dynamodbv2.document.{PrimaryKey, DynamoDB}
import com.typesafe.config.{ConfigFactory, Config}
import scala.util.{Failure, Success, Try}
class DynamoDbConfigurationSource(dynamoDb: DynamoDB, identity: Identity, prefix: String) extends ConfigurationSource {
val tableName = s"$prefix${identity.stack}"
override def load: Config = {
val config = for {
table <- Try(dynamoDb.getTable(tableName))
item <- Try(table.getItem(new PrimaryKey("App", identity.app, "Stage", identity.stage)))
} yield {
ConfigFactory.parseMap(item.getMap("Config"), s"Dynamo DB table $tableName [App=${identity.app}, Stage=${identity.stage}]")
}
config match {
case Success(theConfig) => theConfig
case Failure(theFailure) => ConfigFactory.empty(s"no DynamoDB config (or failed to load) for $tableName [App=${identity.app}, Stage=${identity.stage}], exception=[$theFailure]")
}
}
}
object DynamoDbConfigurationSource {
def apply(identity: Identity, prefix: String = "config-"): DynamoDbConfigurationSource = {
val dynamoDb = {
val client = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain())
client.setRegion(RegionUtils.getRegion(identity.region))
new DynamoDB(client)
}
new DynamoDbConfigurationSource(dynamoDb, identity, prefix)
}
}
示例7: S3ConfigurationSource
//设置package包名称以及导入依赖的类
package com.gu.cm
import com.amazonaws.auth.{AWSCredentialsProvider, DefaultAWSCredentialsProviderChain}
import com.amazonaws.regions.RegionUtils
import com.amazonaws.regions.ServiceAbbreviations.S3
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.services.s3.model.GetObjectRequest
import com.typesafe.config.{Config, ConfigFactory}
import scala.util.{Failure, Success, Try}
class S3ConfigurationSource(s3: AmazonS3Client, identity: Identity, bucket: String, version: Option[Int]) extends ConfigurationSource {
override def load: Config = {
val configPath = versionedFilePath(identity, version)
val request = new GetObjectRequest(bucket, configPath)
val config = for {
result <- Try(s3.getObject(request))
item <- Try(scala.io.Source.fromInputStream(result.getObjectContent, "UTF-8").mkString)
} yield {
ConfigFactory.parseString(item)
}
config match {
case Success(theConfig) => theConfig
case Failure(theFailure) => ConfigFactory.empty(s"no s3 config (or failed to load) for bucket=$bucket path=$configPath, exception=[$theFailure]")
}
}
def versionedFilePath(identity: Identity, version:Option[Int]): String = {
val fileVersion = version.map(".v" + _).getOrElse("")
s"config/${identity.region}-${identity.stack}$fileVersion.conf"
}
}
object S3ConfigurationSource {
def apply(identity: Identity, bucket: String, credentials: AWSCredentialsProvider = new DefaultAWSCredentialsProviderChain(), version: Option[Int] = None): S3ConfigurationSource = {
val s3 = {
val client = new AmazonS3Client(credentials)
client.setRegion(RegionUtils.getRegion(identity.region))
client.setEndpoint(RegionUtils.getRegion(identity.region).getServiceEndpoint(S3))
client
}
new S3ConfigurationSource(s3, identity, bucket, version)
}
}
示例8: DynamoDbConfigurationSourceSpec
//设置package包名称以及导入依赖的类
package com.gu.cm
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient
import com.amazonaws.services.dynamodbv2.document.{Item, DynamoDB}
import com.amazonaws.services.dynamodbv2.model._
import com.typesafe.config.ConfigFactory
import org.specs2.mutable.Specification
import org.specs2.specification.Scope
import scala.collection.JavaConverters._
class DynamoDbConfigurationSourceSpec extends Specification {
"a dynamo DB configuration Source" should {
"load a config from dynamodb" in new DynamoDbScope {
val conf = dynamoDbConfigurationSource.load
conf.getInt("foo.a") shouldEqual 42
}
}
trait DynamoDbScope extends Scope {
val dynamoDb = {
val client = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain())
client.setEndpoint("http://localhost:8000")
new DynamoDB(client)
}
val identity = AwsApplication(
stack = "test-stack",
app = "configuration-magic",
stage = "test",
region = "eu-west-1"
)
val dynamoDbConfigurationSource = new DynamoDbConfigurationSource(dynamoDb, identity, "prefix-")
def initTable() = {
val req = new CreateTableRequest(
"prefix-test-stack",
List(
new KeySchemaElement("App", KeyType.HASH),
new KeySchemaElement("Stage", KeyType.RANGE)
).asJava).withAttributeDefinitions(
new AttributeDefinition("App", "S"),
new AttributeDefinition("Stage", "S")
).withProvisionedThroughput(new ProvisionedThroughput(1000L, 1000L))
val table = dynamoDb.createTable(req)
val confBlob = ConfigFactory.parseResourcesAnySyntax("sample").root.unwrapped()
val item = new Item()
.withString("App", "configuration-magic")
.withString("Stage", "test")
.withMap("Config", confBlob)
table.putItem(item)
}
initTable()
}
}
示例9: s3ConfigurationSourceSpec
//设置package包名称以及导入依赖的类
package com.gu.cm
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.regions.RegionUtils
import com.amazonaws.regions.ServiceAbbreviations._
import com.amazonaws.services.s3.AmazonS3Client
import org.specs2.mutable.Specification
import org.specs2.specification.Scope
class s3ConfigurationSourceSpec extends Specification {
"a s3 configuration Source" should {
"look for a versioned file if a version is present" in new s3Scope {
val version = 2
val filePath = s3ConfigurationSource.versionedFilePath(identity, Some(version))
filePath shouldEqual "config/eu-west-1-test-stack.v2.conf"
}
"look for a non versioned file if a version is not present" in new s3Scope {
val filePath = s3ConfigurationSource.versionedFilePath(identity, None)
filePath shouldEqual "config/eu-west-1-test-stack.conf"
}
}
trait s3Scope extends Scope {
val identity = AwsApplication(
stack = "test-stack",
app = "configuration-magic",
stage = "test",
region = "eu-west-1"
)
val s3 = {
val client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain())
client.setRegion(RegionUtils.getRegion(identity.region))
client.setEndpoint(RegionUtils.getRegion(identity.region).getServiceEndpoint(S3))
client
}
val s3ConfigurationSource = new S3ConfigurationSource(s3, identity, "frontend", Some(1))
}
}