forked from itismeghasyam/recover-s3-synindex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
awscli_utils.R
52 lines (45 loc) · 1.93 KB
/
awscli_utils.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
51
52
##########
## AWS CLI helper functions
## Uses synapse STS token to access AWS token
##########
####
# Sync between two buckets - source and destination
####
s3SyncBuckets <- function(source_bucket, destination_bucket, aws_profile='service-catalog'){
command_in <- glue::glue('aws --profile {aws_profile} s3 sync {source_bucket} {destination_bucket}')
print(paste0('RUNNING: ',command_in))
system(command_in)
}
####
# Sync to local location from a source bucket
####
s3SyncToLocal <- function(source_bucket, local_destination = './temp_aws', aws_profile='service-catalog'){
command_in <- glue::glue('aws --profile {aws_profile} s3 sync {source_bucket} {local_destination}')
if(aws_profile == 'env-var'){
command_in <- glue::glue('aws s3 sync {source_bucket} {local_destination}')
}
print(paste0('RUNNING: ',command_in))
system(command_in)
}
####
# Sync from local location to a destination bucket
####
s3SyncFromLocal <- function(local_source = './temp_aws', destination_bucket, aws_profile='service-catalog'){
command_in <- glue::glue('aws --profile {aws_profile} s3 sync {local_source} {destination_bucket}')
if(aws_profile == 'env-var'){
command_in <- glue::glue('aws s3 sync {local_source} {destination_bucket} --acl bucket-owner-full-control')
} # need to add acl permisisons as bucket-owner-full-control to upload/put objects in the bucket
print(paste0('RUNNING: ',command_in))
system(command_in)
}
####
# Get a list of all files in a bucket, Stores to a txt file in the local working directory
####
s3lsBucketObjects <- function(source_bucket, output_file='s3files.txt', aws_profile='service-catalog'){
command_in <- glue::glue('aws --profile {aws_profile} s3 ls {source_bucket} --recursive --output text > {output_file}')
if(aws_profile == 'env-var'){
command_in <- glue::glue('aws s3 ls {source_bucket} --recursive --output text > {output_file}')
}
print(paste0('RUNNING: ',command_in))
system(command_in)
}