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


Scala GetObjectRequest类代码示例

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


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

示例1: Access

//设置package包名称以及导入依赖的类
package hu.blackbelt.cd.bintray.deploy

import java.nio.file.{Files, StandardCopyOption}
import java.util.{Properties, UUID}

import awscala.s3.S3
import com.amazonaws.regions.Regions
import com.amazonaws.services.s3.model.GetObjectRequest
import hu.blackbelt.cd.bintray.VFS.FS

object Access {
  val bintray_organization = "bintray.organization"
  val bintray_user = "bintray.user"
  val bintray_apikey = "bintray.apikey"
  val aws_accessKeyId = "aws.accessKeyId"
  val aws_secretKey = "aws.secretKey"


  def collect = {
    implicit val s3 = S3()(com.amazonaws.regions.Region.getRegion(Regions.EU_CENTRAL_1))



    val destination = FS.getPath(s"/tmp/${UUID.randomUUID().toString}")
    Files.createDirectories(destination)
    val s3Object = s3.getObject(new GetObjectRequest("blackbelt-secrets", "bintray-deploy/access.properties"))
    Files.copy(s3Object.getObjectContent, destination, StandardCopyOption.REPLACE_EXISTING)

    import scala.collection.JavaConverters._
    val prop = new Properties()
    prop.load(Files.newInputStream(destination))
    prop.entrySet().asScala.foreach {
      (entry) => {
        sys.props += ((entry.getKey.asInstanceOf[String], entry.getValue.asInstanceOf[String]))
      }
    }
  }
} 
开发者ID:tsechov,项目名称:s3-bintray-deploy,代码行数:39,代码来源:Access.scala

示例2: AmazonHelpers

//设置package包名称以及导入依赖的类
package com.iheart.lambda

import java.text.SimpleDateFormat
import java.util.Date

import com.amazonaws.services.logs.AWSLogsClient
import com.amazonaws.services.logs.model._
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.services.s3.model.GetObjectRequest
import scala.collection.JavaConverters._
import scala.io.Source


object AmazonHelpers {

  val s3Client = new AmazonS3Client()
  val cwlClient = new AWSLogsClient()
  val cwlLogGroup = "/aws/lambda/fastlyLogProcessorSkips"
  //val cwlLogStream = "Skips"

  def cwlLogStream() = {
    val s = new SimpleDateFormat("YYYY-MMDD-HH-mm")
    s.format(new Date())
  }

  def readFileFromS3(bucket: String, key: String) = {
    val s3Object = s3Client.getObject(new GetObjectRequest(bucket,key))
    Source.fromInputStream(s3Object.getObjectContent).getLines()
  }

  def getCloudSeqToken(logStream: String) = {
    val req = new DescribeLogStreamsRequest(cwlLogGroup).withLogStreamNamePrefix(logStream)
    val descResult = cwlClient.describeLogStreams(req)
    if (descResult != null && descResult.getLogStreams != null && !descResult.getLogStreams.isEmpty) {
      descResult.getLogStreams.asScala.last.getUploadSequenceToken
    }
    else {
      println("Creating log stream " + logStream)
      cwlClient.createLogStream(new CreateLogStreamRequest(cwlLogGroup,logStream))
      null
    }
  }

  def sendCloudWatchLog(log: String) = {
    println("Skipping cloudwatch log: " + log)
    val logStream = cwlLogStream()
    val token = getCloudSeqToken(logStream)
    println("token is : " + token)
    val event = new InputLogEvent
    event.setTimestamp(new Date().getTime)
    event.setMessage(log)
    val req = new PutLogEventsRequest(cwlLogGroup,logStream,List(event).asJava)
    req.setSequenceToken(token)
    cwlClient.putLogEvents(req)
  }
} 
开发者ID:denen99,项目名称:fastly-lambda,代码行数:57,代码来源:AmazonHelpers.scala

示例3: 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)
  }
} 
开发者ID:guardian,项目名称:configuration-magic,代码行数:47,代码来源:S3ConfigurationSource.scala


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