-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathS3.R
50 lines (37 loc) · 1.74 KB
/
S3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
sessionInfo() # this will list down the libraries you have in your environment
################################ Setup Your Keys ################################
#my keys
keyTable <- read.csv("accessKeys.csv", header = T)
AWS_ACCESS_KEY_ID <- as.character(keyTable$Access.key.ID)
AWS_SECRET_ACCESS_KEY <- as.character(keyTable$Secret.access.key)
#activate
Sys.setenv("AWS_ACCESS_KEY_ID" = AWS_ACCESS_KEY_ID,
"AWS_SECRET_ACCESS_KEY" = AWS_SECRET_ACCESS_KEY,
"AWS_DEFAULT_REGION" = "eu-west-2")
########################### S3 Interraction with R #############################
#> OSX: install.packages("aws.s3", repos = c("cloudyr" = "http://cloudyr.github.io/drat"))
install.packages("aws.s3", repos = c("cloudyr" = "http://cloudyr.github.io/drat"), INSTALL_opts = "--no-multiarch")
install.packages("xml2")
library(aws.s3)
library(xml2) # only on Windows
# i can have a look at my bucket list on s3
bucketlist()
#Make a unique s3 bucket name
my_name <- "pasztor-benedek" # type in your name here
bucket_name <- paste(c(my_name, sample(c(0:3, letters), size = 3, replace = TRUE)), collapse = "")
print(bucket_name)
#Now we can create the bucket on s3
put_bucket(bucket_name)
#bucket location
get_location(bucket_name)
#Create a text file using the website content:
write("This is a simple text file", "my_content.txt")
#Send the text file to AWS S3 bucket
put_object("my_content.txt", bucket = bucket_name)
#We have data on The Cloud! Check on your browser. Now let's get it back on our computer:
save_object("my_content.txt", bucket = bucket_name, file = "my_content_s3.txt")
list.files()
# lets delete this object
delete_object("my_content.txt", bucket = bucket_name)
# We're finished with this bucket, so let's delete it.
delete_bucket(bucket_name)