Last active
October 31, 2018 04:23
-
-
Save onema/1c30063c5ae1b53690c681a6d7be5258 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.amazonaws.services.lambda.runtime.Context | |
import com.amazonaws.services.lambda.runtime.events.S3Event | |
import com.amazonaws.services.s3.{AmazonS3, AmazonS3ClientBuilder} | |
import com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord | |
import io.onema.userverless.configuration.lambda.EnvLambdaConfiguration | |
import io.onema.userverless.function.LambdaHandler | |
import scala.collection.JavaConverters._ | |
class CopyFunction extends LambdaHandler[S3Event, Unit] with EnvLambdaConfiguration { | |
//--- Fields --- | |
private val destinationBucket: String = getValue("destination/bucket").getOrElse("") | |
private val s3Client: AmazonS3 = AmazonS3ClientBuilder.defaultClient() | |
//--- Methods --- | |
def execute(event: S3Event, context: Context): Unit = { | |
event.getRecords.asScala.foreach(copy) | |
} | |
def copy(record: S3EventNotificationRecord): Unit = { | |
val sourceBucket = record.getS3.getBucket.getName | |
val sourceKey = record.getS3.getObject.getKey | |
s3Client.copyObject(sourceBucket, sourceKey, destinationBucket, sourceKey) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment