当前位置: 首页>>代码示例>>Scala>>正文


Scala AWSCredentials类代码示例

本文整理汇总了Scala中com.amazonaws.auth.AWSCredentials的典型用法代码示例。如果您正苦于以下问题:Scala AWSCredentials类的具体用法?Scala AWSCredentials怎么用?Scala AWSCredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AWSCredentials类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: AWSClient

//设置package包名称以及导入依赖的类
package org.andrewconner.spot.cmdrs

import cats.Later
import com.amazonaws.AmazonWebServiceRequest
import com.amazonaws.auth.AWSCredentials
import com.amazonaws.handlers.AsyncHandler
import com.amazonaws.regions.{ Regions, Region }
import com.amazonaws.services.ec2.AmazonEC2AsyncClient
import com.amazonaws.services.ec2.model.{ DescribeSpotPriceHistoryResult, DescribeSpotPriceHistoryRequest }
import org.andrewconner.spot.modules.AppShutdown
import org.joda.time.DateTime
import org.andrewconner.spot.core._
import play.api.inject.ApplicationLifecycle

import scala.concurrent.{ ExecutionContext, Future }
import scalaz.Memo
import scalaz.concurrent.Task
import scalaz.Scalaz._

class AWSClient(credentials: AWSCredentials, appShutdown: AppShutdown)(implicit val ec: ExecutionContext) {

  val clients = Regions.values().map { r =>
    r -> Lazily {
      val client = new AmazonEC2AsyncClient(credentials)
      client.setRegion(Region.getRegion(r))
      client
    }
  }.toMap

  appShutdown.onStopAsync {
    clients.foreach(_._2.foreach(_.shutdown()))
  }

  def fetchSpotPrices(region: Regions)(request: DescribeSpotPriceHistoryRequest, nextToken: String): Task[DescribeSpotPriceHistoryResult] = {
    Task.async[DescribeSpotPriceHistoryResult] { k =>
      clients(region).get.describeSpotPriceHistoryAsync(request.clone().withNextToken(Option(nextToken).getOrElse("")), asyncHandler[DescribeSpotPriceHistoryRequest, DescribeSpotPriceHistoryResult](k))
      ()
    }
  }

  private def asyncHandler[R <: AmazonWebServiceRequest, T](register: scalaz.\/[Throwable, T] => Unit): AsyncHandler[R, T] = {
    new AsyncHandler[R, T] {
      def onSuccess(req: R, res: T) = register(res.right)
      def onError(ex: Exception) = register(ex.left)
    }
  }

} 
开发者ID:andrewconner,项目名称:spotsy,代码行数:49,代码来源:AWSClient.scala

示例2: MyAmazonSES

//设置package包名称以及导入依赖的类
package utils

import com.amazonaws.auth.AWSCredentials
import com.amazonaws.regions.Regions
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient
import com.amazonaws.services.simpleemail.model._

class MyAmazonSES(credentials: AWSCredentials, region: Regions) {
  lazy val client = new AmazonSimpleEmailServiceClient(credentials)
  client.withRegion(region)

  def send(mail: Mail): Unit = {
    val req = new SendEmailRequest()
      .withSource(mail.from)
      .withDestination(mail.dest)
      .withMessage(mail.message)
    client.sendEmail(req)
  }
}

case class Mail(dest: Destination, subject: Content, body: Body, from: String) {
  def message: Message = new Message().withSubject(subject).withBody(body)
} 
开发者ID:ponkotuy,项目名称:train-stamp-rally,代码行数:24,代码来源:MyAmazonSES.scala

示例3: Config

//设置package包名称以及导入依赖的类
package utils

import com.amazonaws.auth.{AWSCredentials, BasicAWSCredentials}
import com.amazonaws.regions.Regions
import play.api.Configuration

class Config(orig: Configuration) {
  lazy val googleMapsKey: Option[String] = orig.getString("google.maps.key")
  lazy val amazon = orig.getConfig("amazon").map(new AmazonConfig(_))
  lazy val mail: Option[String] = orig.getString("management.mail")
}

class AmazonConfig(config: Configuration) {
  val regionRaw: Option[String] = config.getString("region")
  val access: Option[String] = config.getString("access_key")
  val secret: Option[String] = config.getString("secret_key")

  lazy val credentials: Option[AWSCredentials] = for {
    a <- access
    s <- secret
  } yield new BasicAWSCredentials(a, s)

  lazy val region: Option[Regions] = regionRaw.map(Regions.fromName)

  def ses: Option[MyAmazonSES] = for {
    c <- credentials
    r <- region
  } yield new MyAmazonSES(c, r)
} 
开发者ID:ponkotuy,项目名称:train-stamp-rally,代码行数:30,代码来源:Config.scala

示例4: S3PlainClient

//设置package包名称以及导入依赖的类
package uk.gov.homeoffice.aws.s3

import java.net.URL

import com.amazonaws.ClientConfiguration
import com.amazonaws.auth.AWSCredentials
import com.amazonaws.services.s3.model.{CryptoConfiguration, EncryptionMaterialsProvider}
import com.amazonaws.services.s3.{AmazonS3, AmazonS3Client, AmazonS3EncryptionClient}

trait S3Client extends AmazonS3

class S3PlainClient(endpoint: URL, credentials: AWSCredentials)(implicit clientConfiguration: ClientConfiguration = new ClientConfiguration) extends AmazonS3Client(credentials, clientConfiguration) with S3Client {
  setEndpoint(endpoint.toString)

  def clientConfig = clientConfiguration
}

class S3EncryptionClient(endpoint: URL, credentials: AWSCredentials,
                         encryptionMaterialsProvider: EncryptionMaterialsProvider, cryptoConfiguration: CryptoConfiguration)
                        (implicit clientConfiguration: ClientConfiguration = new ClientConfiguration)
  extends AmazonS3EncryptionClient(credentials, encryptionMaterialsProvider, clientConfiguration, cryptoConfiguration) with S3Client {
  setEndpoint(endpoint.toString)

  def clientConfig = clientConfiguration
} 
开发者ID:UKHomeOffice,项目名称:aws-scala-lib,代码行数:26,代码来源:S3Client.scala

示例5: SQSClient

//设置package包名称以及导入依赖的类
package uk.gov.homeoffice.aws.sqs

import java.net.URL
import com.amazonaws.ClientConfiguration
import com.amazonaws.auth.AWSCredentials
import com.amazonaws.services.sqs.AmazonSQSClient
import grizzled.slf4j.Logging

class SQSClient(val sqsHost: URL, credentials: AWSCredentials)(implicit clientConfiguration: ClientConfiguration = new ClientConfiguration) extends AmazonSQSClient(credentials, clientConfiguration) with Logging {
  val Host = """^(http[s]?):\/?\/?([^:\/\s]+):?(\d*).*""".r

  sqsHost.toString match {
    case Host(protocol, "localhost", port) =>
      info(s"Configuring endpoint as $protocol://localhost:$port")
      setEndpoint(s"$protocol://localhost:$port")

    case Host(protocol, host, port) if port == "" =>
      info(s"Configuring endpoint as $host")
      setEndpoint(s"$host")

    case Host(protocol, host, port) =>
      info(s"Configuring endpoint as $protocol://$host:$port")
      setEndpoint(s"$protocol://$host:$port")
  }

  def clientConfig = clientConfiguration
} 
开发者ID:UKHomeOffice,项目名称:aws-scala-lib,代码行数:28,代码来源:SQSClient.scala

示例6: SQSClientSpec

//设置package包名称以及导入依赖的类
package uk.gov.homeoffice.aws.sqs

import java.net.{URI, URL}
import com.amazonaws.AmazonWebServiceClient
import com.amazonaws.auth.AWSCredentials
import org.specs2.mock.Mockito
import org.specs2.mutable.Specification

class SQSClientSpec extends Specification with Mockito {
  "SQS client" should {
    "be instantiated without account number" in {
      val sqsClient = new SQSClient(new URL("https://sqs.eu-west-1.amazonaws.com"), mock[AWSCredentials])

      val endpointField = classOf[AmazonWebServiceClient].getDeclaredField("endpoint")
      endpointField.setAccessible(true)

      endpointField.get(sqsClient) mustEqual new URI("https://sqs.eu-west-1.amazonaws.com")
    }

    "be instantiated with account number" in {
      val sqsClient = new SQSClient(new URL("https://sqs.eu-west-1.amazonaws.com/1111"), mock[AWSCredentials])

      val endpointField = classOf[AmazonWebServiceClient].getDeclaredField("endpoint")
      endpointField.setAccessible(true)

      endpointField.get(sqsClient) mustEqual new URI("https://sqs.eu-west-1.amazonaws.com")
    }

    "be instantiated locally" in {
      val sqsClient = new SQSClient(new URL("http://localhost:9234/queue"), mock[AWSCredentials])

      val endpointField = classOf[AmazonWebServiceClient].getDeclaredField("endpoint")
      endpointField.setAccessible(true)

      endpointField.get(sqsClient) mustEqual new URI("http://localhost:9234")
    }
  }
} 
开发者ID:UKHomeOffice,项目名称:aws-scala-lib,代码行数:39,代码来源:SQSClientSpec.scala

示例7: StreamConfig

//设置package包名称以及导入依赖的类
package io.flow.event.v2

import com.amazonaws.ClientConfiguration
import com.amazonaws.auth.{AWSCredentials, AWSCredentialsProvider, AWSStaticCredentialsProvider}
import com.amazonaws.services.kinesis.{AmazonKinesis, AmazonKinesisClientBuilder}
import io.flow.event.Naming

case class StreamConfig(
  awsCredentials: AWSCredentials,
  appName: String,
  streamName: String,
  maxRecords: Int = 1000,   // number of records in each fetch
  idleTimeBetweenReadsInMillis: Int = 1000
) {

  val awSCredentialsProvider: AWSCredentialsProvider = new AWSStaticCredentialsProvider(awsCredentials)

  def kinesisClient: AmazonKinesis = {
    AmazonKinesisClientBuilder.standard().
      withCredentials(awSCredentialsProvider).
      withClientConfiguration(
        new ClientConfiguration()
          .withMaxErrorRetry(5)
          .withThrottledRetries(true)
          .withConnectionTTL(60000)
      ).
      build()
  }

  def dynamoTableName: String = {
    Naming.dynamoKinesisTableName(
      streamName = streamName,
      appName = appName
    )
  }

} 
开发者ID:flowcommerce,项目名称:lib-event,代码行数:38,代码来源:StreamConfig.scala

示例8: DefaultCredentialsProvider

//设置package包名称以及导入依赖的类
package aws

import com.amazonaws.auth.AWSCredentials

class DefaultCredentialsProvider extends CredentialsProvider {
  private val provider = new com.amazonaws.auth.DefaultAWSCredentialsProviderChain
  override def getCredentials: Credentials = {
    provider.getCredentials match {
      case credentials: com.amazonaws.auth.AWSSessionCredentials ?
        Credentials(credentials.getAWSAccessKeyId, credentials.getAWSSecretKey, credentials.getSessionToken)

      case credentials: AWSCredentials ?
        Credentials(credentials.getAWSAccessKeyId, credentials.getAWSSecretKey)
    }
  }
  override def refresh: Unit = provider.refresh
}

object DefaultCredentialsProvider {
  def apply(): DefaultCredentialsProvider =
    new DefaultCredentialsProvider
} 
开发者ID:larroy,项目名称:DynamoDBScala,代码行数:23,代码来源:DefaultCredentialsProvider.scala

示例9: S3Client

//设置package包名称以及导入依赖的类
package org.personal.durdina.s3dr.io

import java.io.File

import com.amazonaws.auth.{AWSCredentials, BasicAWSCredentials}
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.services.s3.model._

import scala.annotation.tailrec
import scala.collection.JavaConverters._


class S3Client {

  // TODO: externalize
  val accessKey = "AKIAIM4TY5PUZ3VXMDKA"
  val secretKey = "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"

  val credentials: AWSCredentials = new BasicAWSCredentials(accessKey, secretKey)
  val s3client = new AmazonS3Client(credentials)

  def upload(source: File, target: S3File) {
    val request = new PutObjectRequest(target.bucket, target.key, source)
    s3client.putObject(request)
  }

  def listOfFiles(prefix: S3File) = {
    listObjects(prefix.bucket, prefix.key, _.getKey)
  }

  def emptyBucket(bucket: String) {
    listOfFiles(new S3File(bucket, "")).foreach(s3client.deleteObject(bucket, _))
  }

  private def listObjects[T](bucket: String, keyPrefix: String, transformFunc: S3ObjectSummary => T): Seq[T] = {
    @tailrec
    def aggregateObjects(objectListing: ObjectListing, files: List[S3ObjectSummary]): List[S3ObjectSummary] = {
      if (!objectListing.isTruncated)
        files ++ objectListing.getObjectSummaries.asScala
      else
        aggregateObjects(s3client.listNextBatchOfObjects(objectListing), files ++ objectListing.getObjectSummaries.asScala)
    }

    val files = aggregateObjects(s3client.listObjects(bucket, keyPrefix), Nil)
    files.map(transformFunc)
  }

} 
开发者ID:durdina,项目名称:s3-dist-reader,代码行数:49,代码来源:S3Client.scala

示例10: DynamoDBTableLoader

//设置package包名称以及导入依赖的类
import com.amazonaws.auth.{AWSCredentials, AWSCredentialsProvider, BasicAWSCredentials}
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient
import com.amazonaws.services.dynamodbv2.document.DynamoDB
import com.amazonaws.services.dynamodbv2.model._

object DynamoDBTableLoader {

  val awsCredProvider = new AWSCredentialsProvider {
    override def refresh(): Unit = ()

    override def getCredentials: AWSCredentials = new BasicAWSCredentials("accessKey", "secretKey")
  }

  val dynamoDBClient = new AmazonDynamoDBClient(awsCredProvider.getCredentials)
  dynamoDBClient.setEndpoint("http://localhost:8000")
  val dynamoDB = new DynamoDB(dynamoDBClient)
  dynamoDB.shutdown()


  //Helper functions
  private val keySchemaType = (name: String, keyType: KeyType) => new KeySchemaElement().withAttributeName(name).withKeyType(keyType)
  private val keySchema = (name: String) => keySchemaType(name, KeyType.HASH)
  private val attributeDefType = (name: String, attrType: ScalarAttributeType) => new AttributeDefinition().withAttributeName(name).withAttributeType(attrType)
  private val attributeDef = (name: String) => attributeDefType(name, ScalarAttributeType.S)
  private val provisionedThroughput = (throughput: Long) => new ProvisionedThroughput().withReadCapacityUnits(throughput).withWriteCapacityUnits(throughput)
  private val globalSecondaryIndex = (indexName: String, keySchema: Seq[KeySchemaElement], throughput: ProvisionedThroughput) =>
    new GlobalSecondaryIndex()
      .withIndexName(indexName)
      .withKeySchema(keySchema: _*)
      .withProjection(new Projection().withProjectionType(ProjectionType.ALL))
      .withProvisionedThroughput(throughput)

  def initTestTable() = {
    new CreateTableRequest()
        .withTableName("test_table")
        .withKeySchema(keySchema("my_key"))

  }
} 
开发者ID:lifeway,项目名称:play-dynamodb,代码行数:40,代码来源:DynamoDBTableLoader.scala

示例11: SQSClient

//设置package包名称以及导入依赖的类
package uk.gov.homeoffice.amazon.sqs

import java.net.URL
import com.amazonaws.auth.AWSCredentials
import com.amazonaws.services.sqs.AmazonSQSClient
import grizzled.slf4j.Logging

class SQSClient(val sqsHost: URL, credentials: AWSCredentials) extends AmazonSQSClient(credentials) with Logging {
  val Host = """^(http[s]?):\/?\/?([^:\/\s]+):?(\d*).*""".r

  sqsHost.toString match {
    case Host(protocol, "localhost", port) =>
      info(s"Configuring endpoint as $protocol://localhost:$port")
      setEndpoint(s"$protocol://localhost:$port")

    case Host(protocol, host, port) if port == "" =>
      info(s"Configuring endpoint as $host")
      setEndpoint(s"$host")

    case Host(protocol, host, port) =>
      info(s"Configuring endpoint as $protocol://$host:$port")
      setEndpoint(s"$protocol://$host:$port")
  }
} 
开发者ID:UKHomeOffice,项目名称:rtp-amazon-sqs-lib,代码行数:25,代码来源:SQSClient.scala

示例12: SQSClientSpec

//设置package包名称以及导入依赖的类
package uk.gov.homeoffice.amazon.sqs

import java.net.{URI, URL}
import com.amazonaws.AmazonWebServiceClient
import com.amazonaws.auth.AWSCredentials
import org.specs2.mock.Mockito
import org.specs2.mutable.Specification

class SQSClientSpec extends Specification with Mockito {
  "SQS client" should {
    "be instantiated without account number" in {
      val sqsClient = new SQSClient(new URL("https://sqs.eu-west-1.amazonaws.com"), mock[AWSCredentials])

      val endpointField = classOf[AmazonWebServiceClient].getDeclaredField("endpoint")
      endpointField.setAccessible(true)

      endpointField.get(sqsClient) mustEqual new URI("https://sqs.eu-west-1.amazonaws.com")
    }

    "be instantiated with account number" in {
      val sqsClient = new SQSClient(new URL("https://sqs.eu-west-1.amazonaws.com/1111"), mock[AWSCredentials])

      val endpointField = classOf[AmazonWebServiceClient].getDeclaredField("endpoint")
      endpointField.setAccessible(true)

      endpointField.get(sqsClient) mustEqual new URI("https://sqs.eu-west-1.amazonaws.com")
    }

    "be instantiated locally" in {
      val sqsClient = new SQSClient(new URL("http://localhost:9234/queue"), mock[AWSCredentials])

      val endpointField = classOf[AmazonWebServiceClient].getDeclaredField("endpoint")
      endpointField.setAccessible(true)

      endpointField.get(sqsClient) mustEqual new URI("http://localhost:9234")
    }
  }
} 
开发者ID:UKHomeOffice,项目名称:rtp-amazon-sqs-lib,代码行数:39,代码来源:SQSClientSpec.scala


注:本文中的com.amazonaws.auth.AWSCredentials类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。