Skip to content

@CerebralMastication /awsExampleRjava.R
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Example of how to control AWS from R
library(rJava)
.jinit()
awsAccessKeyText <- "yourKeyHere"
awsSecretKeyText <- "yourSecretKeyHere"
pathToSdk <- "/home/jal/aws-java-sdk-1.1.0/"
testFile <- "/home/jal/aws-java-sdk-1.1.0/rJavaExamples/testFile.tst"
.jaddClassPath(paste(pathToSdk, "lib/aws-java-sdk-1.1.0.jar", sep=""))
.jaddClassPath(paste(pathToSdk, "third-party/commons-logging-1.1.1/commons-logging-1.1.1.jar", sep=""))
.jaddClassPath(paste(pathToSdk, "third-party/commons-httpclient-3.0.1/commons-httpclient-3.0.1.jar", sep=""))
.jaddClassPath(paste(pathToSdk, "third-party/commons-codec-1.3/commons-codec-1.3.jar", sep=""))
attach( javaImport( "java.lang" ) )
attach( javaImport( "java.io" ) )
awsCreds <- new(com.amazonaws.auth.BasicAWSCredentials, awsAccessKeyText, awsSecretKeyText)
tx <- new(com.amazonaws.services.s3.transfer.TransferManager, awsCreds)
bucketName <- paste("s3-upload-sdk-sample-", tolower(awsAccessKeyText), sep="")
s3 <- tx$getAmazonS3Client()
#test if the bucket exists; if not, make bucket
if (s3$doesBucketExist(bucketName) == FALSE) {
s3$createBucket(bucketName)
}
fileToUpload <- new(File, new(String, testFile))
request <- new(com.amazonaws.services.s3.model.PutObjectRequest, bucketName, fileToUpload$getName(), fileToUpload)
s3$putObject(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.