Title: | 'AWS Python SDK' ('boto3') for R |
---|---|
Description: | Fork-safe, raw access to the 'Amazon Web Services' ('AWS') 'SDK' via the 'boto3' 'Python' module, and convenient helper functions to query the 'Simple Storage Service' ('S3') and 'Key Management Service' ('KMS'), partial support for 'IAM', the 'Systems Manager Parameter Store' and 'Secrets Manager'. |
Authors: | Gergely Daróczi [aut, cre] , System1 [fnd] |
Maintainer: | Gergely Daróczi <[email protected]> |
License: | AGPL-3 |
Version: | 0.4.0.9000 |
Built: | 2024-11-06 05:12:51 UTC |
Source: | https://github.com/daroczig/botor |
Raw access to the boto3 module imported at package load time
boto3
boto3
An object of class python.builtin.module
(inherits from python.builtin.object
) of length 0.
You may rather want to use botor
instead, that provides a fork-safe boto3
session.
The default, fork-safe Boto3 session
botor( aws_access_key_id, aws_secret_access_key, aws_session_token, region_name, botocore_session, profile_name )
botor( aws_access_key_id, aws_secret_access_key, aws_session_token, region_name, botocore_session, profile_name )
aws_access_key_id |
AWS access key ID |
aws_secret_access_key |
AWS secret access key |
aws_session_token |
AWS temporary session token |
region_name |
Default region when creating new connections |
botocore_session |
Use this Botocore session instead of creating a new default one |
profile_name |
The name of a profile to use. If not given, then the default profile is used |
boto3 Session
Creates an initial or reinitialize an already existing AWS client or resource cached in the package's namespace
botor_client(service, type = c("client", "resource"), cache = TRUE, ...)
botor_client(service, type = c("client", "resource"), cache = TRUE, ...)
service |
string, eg S3 or IAM |
type |
AWS service client or resource to be created, eg |
cache |
booelan flag for caching the client or resource in the package namespace. For (internal) package functions, it's best to set to |
... |
further parameters passed to the |
cached AWS client
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html
Check if an argument looks like an S3 bucket
check_s3_uri(x)
check_s3_uri(x)
x |
string, URI of an S3 object, should start with |
check_s3_uri('s3://foo/bar') check_s3_uri('https://foo/bar') ## Not run: assert_s3_uri('https://foo/bar') ## End(Not run)
check_s3_uri('s3://foo/bar') check_s3_uri('https://foo/bar') ## Not run: assert_s3_uri('https://foo/bar') ## End(Not run)
botor
The default, fork-safe IAM client on the top of botor
iam()
iam()
botocore.client.IAM
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html
Retrieves information about the specified IAM user, including the user's creation date, path, unique ID, and ARN
iam_get_user(...)
iam_get_user(...)
... |
optional extra arguments passed |
list
Get the current AWS username
iam_whoami()
iam_whoami()
string
botor
The default, fork-safe Kinesis client on the top of botor
kinesis()
kinesis()
botocore.client.Kinesis
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/kinesis.html
Describes the specified Kinesis data stream
kinesis_describe_stream(stream)
kinesis_describe_stream(stream)
stream |
the name of the stream to describe |
list
Gets data records from a Kinesis data stream's shard
kinesis_get_records(shard_iterator, limit = 25L)
kinesis_get_records(shard_iterator, limit = 25L)
shard_iterator |
the position in the shard from which you want to start sequentially reading data records, usually provided by |
limit |
maximum number of records to return |
list of Records
, NextShardIterator
and MillisBehindLatest
## Not run: botor(profile_name = 'botor-tester') iterator <- kinesis_get_shard_iterator(stream = 'botor-tester', shard = '0') kinesis_get_records(iterator$ShardIterator) ## End(Not run)
## Not run: botor(profile_name = 'botor-tester') iterator <- kinesis_get_shard_iterator(stream = 'botor-tester', shard = '0') kinesis_get_records(iterator$ShardIterator) ## End(Not run)
Gets an Amazon Kinesis shard iterator
kinesis_get_shard_iterator( stream, shard, shard_iterator_type = c("TRIM_HORIZON", "LATEST", "AT_SEQUENCE_NUMBER", "AFTER_SEQUENCE_NUMBER", "AT_TIMESTAMP"), ... )
kinesis_get_shard_iterator( stream, shard, shard_iterator_type = c("TRIM_HORIZON", "LATEST", "AT_SEQUENCE_NUMBER", "AFTER_SEQUENCE_NUMBER", "AT_TIMESTAMP"), ... )
stream |
the name of the stream to describe |
shard |
the shard ID of the Kinesis Data Streams shard to get the iterator for |
shard_iterator_type |
determines how the shard iterator is used to start reading data records from the shard |
... |
optional further parameters, such as |
list of ShardIterator
Writes a single data record into an Amazon Kinesis data stream
kinesis_put_record(stream, data, partition_key, ...)
kinesis_put_record(stream, data, partition_key, ...)
stream |
the name of the stream to describe |
data |
the data blob (<1 MB) to put into the record, which is base64-encoded when the blob is serialized |
partition_key |
Unicode string with a maximum length limit of 256 characters determining which shard in the stream the data record is assigned to |
... |
optional further parameters, such as |
list of ShardId
, SequenceNumber
and EncryptionType
botor
The default, fork-safe KMS client on the top of botor
kms()
kms()
botocore.client.KMS
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/kms.html
Decrypt cipher into plain text via KMS
kms_decrypt(cipher, simplify = TRUE)
kms_decrypt(cipher, simplify = TRUE)
cipher |
Base64-encoded ciphertext |
simplify |
returns decrypted plain-text instead of raw list |
decrypted text as string or list
Decrypt file via KMS
kms_decrypt_file(file, return = file)
kms_decrypt_file(file, return = file)
file |
base file path (without the |
return |
where to place the encrypted file (defaults to |
decrypted file path
Encrypt plain text via KMS
kms_encrypt(key, text, simplify = TRUE)
kms_encrypt(key, text, simplify = TRUE)
key |
the KMS customer master key identifier as a fully specified Amazon Resource Name (eg |
text |
max 4096 bytes long string, eg an RSA key, a database password, or other sensitive customer information |
simplify |
returns Base64-encoded text instead of raw list |
string or list
Encrypt file via KMS
kms_encrypt_file(key, file)
kms_encrypt_file(key, file)
key |
the KMS customer master key identifier as a fully specified Amazon Resource Name (eg |
file |
file path |
two files created with enc
(encrypted data) and key
(encrypted key) extensions
Generate a data encryption key for envelope encryption via KMS
kms_generate_data_key(key, bytes = 64L)
kms_generate_data_key(key, bytes = 64L)
key |
the KMS customer master key identifier as a fully specified Amazon Resource Name (eg |
bytes |
the required length of the data encryption key in bytes (so provide eg |
list
of the Base64-encoded encrypted version of the data encryption key (to be stored on disk), the raw
object of the encryption key and the KMS customer master key used to generate this object
mimetypes
Python moduleGuess the type of a file based on the filename using mimetypes
Python module
mime_guess(file)
mime_guess(file)
file |
path |
string
botor
The default, fork-safe Amazon Simple Storage Service (S3) client on the top of botor
s3()
s3()
s3.ServiceResource
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#service-resource
Copy an object from one S3 location to another
s3_copy(uri_source, uri_target)
s3_copy(uri_source, uri_target)
uri_source |
string, location of the source file |
uri_target |
string, location of the target file |
invisibly uri_target
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Object.copy
Delete an object stored in S3
s3_delete(uri)
s3_delete(uri)
uri |
string, URI of an S3 object, should start with |
Download a file from S3
s3_download_file(uri, file, force = TRUE)
s3_download_file(uri, file, force = TRUE)
uri |
string, URI of an S3 object, should start with |
file |
string, location of local file |
force |
boolean, overwrite local file if exists |
invisibly file
## Not run: s3_download_file('s3://botor/example-data/mtcars.csv', tempfile()) ## End(Not run)
## Not run: s3_download_file('s3://botor/example-data/mtcars.csv', tempfile()) ## End(Not run)
Checks if an object exists in S3
s3_exists(uri)
s3_exists(uri)
uri |
string, URI of an S3 object, should start with |
boolean
## Not run: s3_exists('s3://botor/example-data/mtcars.csv') s3_exists('s3://botor/example-data/UNDEFINED.CSVLX') ## End(Not run)
## Not run: s3_exists('s3://botor/example-data/mtcars.csv') s3_exists('s3://botor/example-data/UNDEFINED.CSVLX') ## End(Not run)
List all S3 buckets
s3_list_buckets(simplify = TRUE)
s3_list_buckets(simplify = TRUE)
simplify |
return bucket names as a character vector |
list
of boto3.resources.factory.s3.Bucket
or a character vector
List objects at an S3 path
s3_ls(uri)
s3_ls(uri)
uri |
string, should start with |
data.frame
with bucket_name
, object key
, uri
(that can be directly passed to eg s3_read
), size
in bytes, owner
and last_modified
timestamp
Create an S3 Object reference from an URI
s3_object(uri)
s3_object(uri)
uri |
string, URI of an S3 object, should start with |
s3$Object
Sets tags on s3 object overwriting all existing tags. Note: tags and metadata tags are not the same
s3_put_object_tagging(uri, tags)
s3_put_object_tagging(uri, tags)
uri |
string, URI of an S3 object, should start with |
tags |
named character vector, e.g. |
Download and read a file from S3, then clean up
s3_read(uri, fun, ..., extract = c("none", "gzip", "bzip2", "xz"))
s3_read(uri, fun, ..., extract = c("none", "gzip", "bzip2", "xz"))
uri |
string, URI of an S3 object, should start with |
fun |
R function to read the file, eg |
... |
optional params passed to |
extract |
optionally extract/decompress the file after downloading from S3 but before passing to |
R object
## Not run: s3_read('s3://botor/example-data/mtcars.csv', read.csv) s3_read('s3://botor/example-data/mtcars.csv', data.table::fread) s3_read('s3://botor/example-data/mtcars.csv2', read.csv2) s3_read('s3://botor/example-data/mtcars.RDS', readRDS) s3_read('s3://botor/example-data/mtcars.json', jsonlite::fromJSON) s3_read('s3://botor/example-data/mtcars.jsonl', jsonlite::stream_in) ## read compressed data s3_read('s3://botor/example-data/mtcars.csv.gz', read.csv, extract = 'gzip') s3_read('s3://botor/example-data/mtcars.csv.gz', data.table::fread, extract = 'gzip') s3_read('s3://botor/example-data/mtcars.csv.bz2', read.csv, extract = 'bzip2') s3_read('s3://botor/example-data/mtcars.csv.xz', read.csv, extract = 'xz') ## End(Not run)
## Not run: s3_read('s3://botor/example-data/mtcars.csv', read.csv) s3_read('s3://botor/example-data/mtcars.csv', data.table::fread) s3_read('s3://botor/example-data/mtcars.csv2', read.csv2) s3_read('s3://botor/example-data/mtcars.RDS', readRDS) s3_read('s3://botor/example-data/mtcars.json', jsonlite::fromJSON) s3_read('s3://botor/example-data/mtcars.jsonl', jsonlite::stream_in) ## read compressed data s3_read('s3://botor/example-data/mtcars.csv.gz', read.csv, extract = 'gzip') s3_read('s3://botor/example-data/mtcars.csv.gz', data.table::fread, extract = 'gzip') s3_read('s3://botor/example-data/mtcars.csv.bz2', read.csv, extract = 'bzip2') s3_read('s3://botor/example-data/mtcars.csv.xz', read.csv, extract = 'xz') ## End(Not run)
Upload a file to S3
s3_upload_file(file, uri, content_type = mime_guess(file))
s3_upload_file(file, uri, content_type = mime_guess(file))
file |
string, location of local file |
uri |
string, URI of an S3 object, should start with |
content_type |
content type of a file that is auto-guess if omitted |
invisibly uri
## Not run: t <- tempfile() write.csv(mtcars, t, row.names = FALSE) s3_upload_file(t, 's3://botor/example-data/mtcars.csv') unlink(t) ## note that s3_write would have been a much nicer solution for the above ## End(Not run)
## Not run: t <- tempfile() write.csv(mtcars, t, row.names = FALSE) s3_upload_file(t, 's3://botor/example-data/mtcars.csv') unlink(t) ## note that s3_write would have been a much nicer solution for the above ## End(Not run)
Write an R object into S3
s3_write(x, fun, uri, compress = c("none", "gzip", "bzip2", "xz"), ...)
s3_write(x, fun, uri, compress = c("none", "gzip", "bzip2", "xz"), ...)
x |
R object |
fun |
R function with |
uri |
string, URI of an S3 object, should start with |
compress |
optionally compress the file before uploading to S3. If compression is used, it's better to include the related file extension in |
... |
optional further arguments passed to |
The temp file used for this operation is automatically removed.
## Not run: s3_write(mtcars, write.csv, 's3://botor/example-data/mtcars.csv', row.names = FALSE) s3_write(mtcars, write.csv2, 's3://botor/example-data/mtcars.csv2', row.names = FALSE) s3_write(mtcars, jsonlite::write_json, 's3://botor/example-data/mtcars.json', row.names = FALSE) s3_write(mtcars, jsonlite::stream_out, 's3://botor/example-data/mtcars.jsonl', row.names = FALSE) s3_write(mtcars, saveRDS, 's3://botor/example-data/mtcars.RDS') ## compress file after writing to disk but before uploading to S3 s3_write(mtcars, write.csv, 's3://botor/example-data/mtcars.csv.gz', compress = 'gzip', row.names = FALSE) s3_write(mtcars, write.csv, 's3://botor/example-data/mtcars.csv.bz2', compress = 'bzip2', row.names = FALSE) s3_write(mtcars, write.csv, 's3://botor/example-data/mtcars.csv.xz', compress = 'xz', row.names = FALSE) ## End(Not run)
## Not run: s3_write(mtcars, write.csv, 's3://botor/example-data/mtcars.csv', row.names = FALSE) s3_write(mtcars, write.csv2, 's3://botor/example-data/mtcars.csv2', row.names = FALSE) s3_write(mtcars, jsonlite::write_json, 's3://botor/example-data/mtcars.json', row.names = FALSE) s3_write(mtcars, jsonlite::stream_out, 's3://botor/example-data/mtcars.jsonl', row.names = FALSE) s3_write(mtcars, saveRDS, 's3://botor/example-data/mtcars.RDS') ## compress file after writing to disk but before uploading to S3 s3_write(mtcars, write.csv, 's3://botor/example-data/mtcars.csv.gz', compress = 'gzip', row.names = FALSE) s3_write(mtcars, write.csv, 's3://botor/example-data/mtcars.csv.bz2', compress = 'bzip2', row.names = FALSE) s3_write(mtcars, write.csv, 's3://botor/example-data/mtcars.csv.xz', compress = 'xz', row.names = FALSE) ## End(Not run)
botor
The default, fork-safe AWS Systems Manager (SecretManager) client on the top of botor
sm()
sm()
botocore.client.secretsmanager
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager.html
Read AWS System Manager's Secrets Manager via Secret Manager
sm_get_secret(path, key = NULL, parse_json = TRUE)
sm_get_secret(path, key = NULL, parse_json = TRUE)
path |
name/path of the key to be read |
key |
single key or a vector of keys. |
parse_json |
logical. Default TRUE |
(optionally decrypted) value
botor
The default, fork-safe AWS Systems Manager (SSM) client on the top of botor
ssm()
ssm()
botocore.client.SSM
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html
Read AWS System Manager's Parameter Store
ssm_get_parameter(path, decrypt = TRUE)
ssm_get_parameter(path, decrypt = TRUE)
path |
name/path of the key to be read |
decrypt |
decrypt the value or return the raw ciphertext |
(optionally decrypted) value
Returns details about the IAM user or role whose credentials are used to call the operation
sts_whoami()
sts_whoami()
list
with UserId
, Account
and Arn