A science-focused, more humane R interface to AWS.
CRAN version
# install.packages("pak") pak::pak("sixtyfour")
Development version
# install.packages("pak") pak::pak("getwilds/sixtyfour")
Load package
library(sixtyfour)
We leverage the package paws
to handle AWS authentication. There are many ways to configure paws
to authenticate with AWS - see paws documentation.
One way to authenticate is using these three environment variables:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION
You can set these three environment variables within R for the current R session like:
Sys.setenv( AWS_ACCESS_KEY_ID = "", AWS_SECRET_ACCESS_KEY = "", AWS_REGION = "us-west-2" )
Or set environment variables in a variety of ways to be available across R sessions. See the R Startup chapter of What They Forgot to Teach You About R book for more details.
aws_billing*
: manage AWS billing detailsaws_bucket*
: manage S3 bucketsaws_file_*
: manage files in S3 bucketsaws_user*
: manage AWS usersaws_group*
: manage AWS groupsaws_role*
: manage AWS rolesaws_policy*
/aws_policies*
: manage AWS policiesaws_db*
: interact with AWS database services Redshift and RDSaws_secrets*
: secrets manageraws_vpc*
: VPC security groupscon_*
: connection classes to various AWS servicessix_*
: magical methodsWe cover S3 in detail in another vignette (vignette("s3")
), so we'll briefly touch on it here.
Make a random bucket name
bucket <- random_bucket()
Create a bucket - check if it exists first
exists <- aws_bucket_exists(bucket) if (!exists) { aws_bucket_create(bucket) } #> [1] "http://bucket-lphnzotejwfyuxkm.s3.amazonaws.com/"
aws_bucket_delete(bucket)
First, create a bucket:
my_bucket <- random_bucket() aws_bucket_create(my_bucket) #> [1] "http://bucket-cdzsxyjiofheptnr.s3.amazonaws.com/"
Then, upload some files
temp_files <- replicate(n = 3, tempfile(fileext = ".txt")) for (i in temp_files) cat(letters, "\n", file = i) remote_files <- s3_path(my_bucket, basename(temp_files)) aws_file_upload(path = temp_files, remote_path = remote_files) #> [1] "s3://bucket-cdzsxyjiofheptnr/file16cf21ea161d1.txt" #> [2] "s3://bucket-cdzsxyjiofheptnr/file16cf2751cf00c.txt" #> [3] "s3://bucket-cdzsxyjiofheptnr/file16cf23ed3dfe5.txt"
List files in the bucket
obs <- aws_bucket_list_objects(my_bucket) obs #> # A tibble: 3 × 8 #> bucket key uri size type etag lastmodified storageclass #> <glue> <chr> <glu> <fs:> <chr> <chr> <dttm> <chr> #> 1 bucket-cdzsxyj… file… s3:/… 53 file "\"a… 2025-03-20 20:52:34 STANDARD #> 2 bucket-cdzsxyj… file… s3:/… 53 file "\"a… 2025-03-20 20:52:34 STANDARD #> 3 bucket-cdzsxyj… file… s3:/… 53 file "\"a… 2025-03-20 20:52:34 STANDARD
Billing is covered in the vignette("billing")
vignette.
IAM stands for Identity Access Management. IAM covers four resource types:
aws_user*
functionsaws_group*
functionsaws_role*
functionsaws_policy*
/aws_policies*
functionsAs a brief example let's create a group, a user, and a role. We'll assign the user to the group. Then clean it all up.
First, create a group
group_name <- random_string("gr-") group_name #> gr-gmpcjatq aws_group_create(group_name) #> # A tibble: 1 × 5 #> GroupName GroupId Path Arn CreateDate #> <chr> <chr> <chr> <chr> <dttm> #> 1 gr-gmpcjatq AGPA22PL7JXXYJ5WLSESJ / ***** 2025-03-20 20:52:35
Then create a user
name <- random_user() name #> [1] "RepellentFinale" aws_user_create(name) #> # A tibble: 1 × 6 #> UserName UserId Path Arn CreateDate PasswordLastUsed #> <chr> <chr> <chr> <chr> <dttm> <dttm> #> 1 RepellentFinale AIDA22PL7… / ***** 2025-03-20 20:52:35 NA
Now add the user to the group
aws_user_add_to_group(name, group_name) #> $user #> # A tibble: 1 × 6 #> UserName UserId Path Arn CreateDate PasswordLastUsed #> <chr> <chr> <chr> <chr> <dttm> <dttm> #> 1 RepellentFinale AIDA22PL7… / ***** 2025-03-20 20:52:35 NA #> #> $policies #> # A tibble: 0 × 0 #> #> $attached_policies #> # A tibble: 0 × 0 #> #> $groups #> # A tibble: 1 × 5 #> GroupName GroupId Path Arn CreateDate #> <chr> <chr> <chr> <chr> <dttm> #> 1 gr-gmpcjatq AGPA22PL7JXXYJ5WLSESJ / ***** 2025-03-20 20:52:35
Now create a role
role_name <- random_role() trust_policy <- list( Version = "2012-10-17", Statement = list( list( Sid = "Statement1", Effect = "Allow", Principal = list( Service = "lambda.amazonaws.com" ), Action = "sts:AssumeRole" ) ) ) doc1 <- jsonlite::toJSON(trust_policy, auto_unbox = TRUE) aws_role_create(role_name, assume_role_policy_document = doc1, description = "test role A" ) #> # A tibble: 1 × 7 #> RoleName RoleId Path Arn CreateDate Description #> <chr> <chr> <chr> <chr> <dttm> <lgl> #> 1 BridgedLiquidati AROA22PL7JXX5ETK… / ***** 2025-03-20 20:52:36 NA #> # ℹ 1 more variable: AssumeRolePolicyDocument <chr>
Finally, cleanup
aws_role_delete(role_name) six_user_delete(name) #> ! No access keys found for RepellentFinale #> ℹ Group gr-gmpcjatq detached #> ℹ RepellentFinale deleted six_group_delete(group_name) #> ℹ group gr-gmpcjatq deleted
Databases are covered in the vignette("databases")
vignette.
Magical methods are higher level functions to make your life easier.
As an example, six_user_create()
creates a new user, including a) creating the appropriate policy if it doesn't exist yet, b) attaching the policy to the created user, and c) creating an AWS Access Key for the user (and copy an email template to your clipboard with the details the new user needs).
name <- random_user() name #> [1] "GildedArchery" six_user_create(name) #> ℹ Added policy UserInfo to GildedArchery #> ✔ Key pair created for GildedArchery #> ℹ AccessKeyId: ***** #> ℹ SecretAccessKey: ***** #> ℹ Email template copied to your clipboard
There are other magical methods. See the docs and the vignette("six")
vignette for more information.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.