S3 Interaction
AWSS3.s3_arn
— Functions3_arn(resource)
s3_arn(bucket,path)
Amazon Resource Name for S3 resource
or bucket
and path
.
AWSS3.s3_get
— Functions3_get([::AbstractAWSConfig], bucket, path; <keyword arguments>)
Retrieves an object from the bucket
for a given path
.
Optional Arguments
version=nothing
: version of object to get.retry=true
: try again on "NoSuchBucket", "NoSuchKey" (common if object was recently created).raw=false
: return response asVector{UInt8}
byte_range=nothing
: given an iterator of(start_byte, end_byte)
gets only the range of bytes of the object fromstart_byte
toend_byte
. For example,byte_range=1:4
gets bytes 1 to 4 inclusive. Arguments should use the Julia convention of 1-based indexing.header::Dict{String,String}
: pass in an HTTP header to the request.
As an example of how to set custom HTTP headers, the below is equivalent to s3_get(aws, bucket, path; byte_range=range)
:
s3_get(aws, bucket, path; headers=Dict{String,String}("Range" => "bytes=$(first(range)-1)-$(last(range)-1)"))
API Calls
Permissions
s3:GetObject
: (conditional): required whenversion === nothing
.s3:GetObjectVersion
: (conditional): required whenversion !== nothing
.s3:ListBucket
(optional): allows requests to non-existent objects to throw a exception with HTTP status code 404 (Not Found) instead of HTTP status code 403 (Access Denied).
AWSS3.s3_get_file
— Functions3_get_file([::AbstractAWSConfig], bucket, path, filename; [version=], kwargs...)
Like s3_get
but streams result directly to filename
. Keyword arguments accept are the same as those for s3_get
.
AWSS3.s3_get_meta
— Functions3getmeta([::AbstractAWSConfig], bucket, path; [version], kwargs...)
Retrieves metadata from an object without returning the object itself.
API Calls
Permissions
s3:GetObject
(conditional): required whenversion === nothing
.s3:GetObjectVersion
: (conditional): required whenversion !== nothing
.s3:ListBucket
(optional): allows requests to non-existent objects to throw a exception with HTTP status code 404 (Not Found) instead of HTTP status code 403 (Access Denied).
AWSS3.s3_exists
— Functions3_exists([::AbstractAWSConfig], bucket, path; version=nothing)
Returns if an object exists with the key path
in the bucket
. If a version
is specified then an object must exist with the specified version identifier.
Note that the AWS API's support for object versioning is quite limited and this check will involve try
/catch
logic if a version
is specified.
API Calls
Permissions
s3:GetObject
(conditional): required whenversion === nothing
.s3:GetObjectVersion
: (conditional): required whenversion !== nothing
.s3:ListBucket
(optional): allows requests to non-existent objects to throw a exception with HTTP status code 404 (Not Found) instead of HTTP status code 403 (Access Denied).
AWSS3.s3_delete
— Functions3_delete([::AbstractAWSConfig], bucket, path; [version], kwargs...)
Deletes an object from a bucket. The version
argument can be used to delete a specific version.
API Calls
Permissions
AWSS3.s3_copy
— Functions3_copy([::AbstractAWSConfig], bucket, path; acl::AbstractString="",
to_bucket=bucket, to_path=path, metadata::AbstractDict=SSDict(),
parse_response::Bool=true, kwargs...)
Copy the object at path
in bucket
to to_path
in to_bucket
.
Optional Arguments
acl=
;x-amz-acl
header for setting access permissions with canned config. See here.metadata::Dict=
;x-amz-meta-
headers.parse_response::Bool=
; whenfalse
, return rawAWS.Response
kwargs
; additional kwargs passed through intoS3.copy_object
API Calls
Permissions
AWSS3.s3_create_bucket
— Functions3_create_bucket([::AbstractAWSConfig], bucket; kwargs...)
Creates a new S3 bucket with the globally unique bucket
name. The bucket will be created AWS region associated with the AbstractAWSConfig
(defaults to "us-east-1").
API Calls
Permissions
AWSS3.s3_put_cors
— Functions3_put_cors([::AbstractAWSConfig], bucket, cors_config; kwargs...)
s3_put_cors("my_bucket", """
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://my.domain.com</AllowedOrigin>
<AllowedOrigin>http://my.other.domain.com</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
<ExposeHeader>Content-Range</ExposeHeader>
</CORSRule>
</CORSConfiguration>
"""
AWSS3.s3_enable_versioning
— Functions3_enable_versioning([::AbstractAWSConfig], bucket, [status]; kwargs...)
Enables or disables versioning for all objects within the given bucket
. Use status
to either enable or disable versioning (respectively "Enabled" and "Suspended").
API Calls
Permissions
AWSS3.s3_put_tags
— Functions3_put_tags([::AbstractAWSConfig], bucket, [path], tags::Dict; kwargs...)
Sets the tags for a bucket or an existing object. When path
is specified then tagging is performed on the object, otherwise it is performed on the bucket
.
See also s3_put_tags
, s3_delete_tags
, and s3_put
's tag
option.
API Calls
PutBucketTagging
(conditional): used whenpath
is not specified (bucket tagging).PutObjectTagging
(conditional): used whenpath
is specified (object tagging).
Permissions
s3:PutBucketTagging
(conditional): required for whenpath
is not specified (bucket tagging).s3:PutObjectTagging
(conditional): required whenpath
is specified (object tagging).
AWSS3.s3_get_tags
— Functions3_get_tags([::AbstractAWSConfig], bucket, [path]; kwargs...)
Get the tags associated with a bucket or an existing object. When path
is specified then tag retrieval is performed on the object, otherwise it is performed on the bucket
.
See also s3_put_tags
and s3_delete_tags
.
API Calls
GetBucketTagging
(conditional): used whenpath
is not specified (bucket tagging).GetObjectTagging
(conditional): used whenpath
is specified (object tagging).
Permissions
s3:GetBucketTagging
(conditional): required for whenpath
is not specified (bucket tagging).s3:GetObjectTagging
(conditional): required whenpath
is specified (object tagging).
AWSS3.s3_delete_tags
— Functions3_delete_tags([::AbstractAWSConfig], bucket, [path])
Delete the tags associated with a bucket or an existing object. When path
is specified then tag deletion is performed on the object, otherwise it is performed on the bucket
.
See also s3_put_tags
and s3_get_tags
.
API Calls
DeleteBucketTagging
(conditional): used whenpath
is not specified (bucket tagging).DeleteObjectTagging
(conditional): used whenpath
is specified (object tagging).
Permissions
s3:PutBucketTagging
(conditional): required for whenpath
is not specified (bucket tagging).s3:DeleteObjectTagging
(conditional): required whenpath
is specified (object tagging).
AWSS3.s3_delete_bucket
— Functions3_delete_bucket([::AbstractAWSConfig], "bucket"; kwargs...)
Deletes an empty bucket. All objects in the bucket must be deleted before a bucket can be deleted.
See also AWSS3.s3_nuke_bucket
.
API Calls
Permissions
AWSS3.s3_list_buckets
— Functions3_list_buckets([::AbstractAWSConfig]; kwargs...)
Return a list of all of the buckets owned by the authenticated sender of the request.
API Calls
Permissions
AWSS3.s3_list_objects
— Functions3_list_objects([::AbstractAWSConfig], bucket, [path_prefix]; delimiter="/", max_items=1000, kwargs...)
List Objects in bucket
with optional path_prefix
.
Returns an iterator of Dict
s with keys Key
, LastModified
, ETag
, Size
, Owner
, StorageClass
.
AWSS3.s3_list_keys
— Functions3_list_keys([::AbstractAWSConfig], bucket, [path_prefix]; kwargs...)
Like s3_list_objects
but returns object keys as Vector{String}
.
AWSS3.s3_purge_versions
— Functions3_purge_versions([::AbstractAWSConfig], bucket, [path_prefix [, pattern]]; kwargs...)
Removes all versions of an object except for the latest version. When path_prefix
is provided then only objects whose key starts with path_prefix
will be purged. Use of pattern
further restricts which objects are purged by only purging object keys containing the pattern
(i.e string literal or regex). When both path_prefix
and pattern
are not' specified then all objects in the bucket will be purged.
API Calls
Permissions
AWSS3.s3_put
— Functions3_put([::AbstractAWSConfig], bucket, path, data, data_type="", encoding="";
acl::AbstractString="", metadata::SSDict=SSDict(), tags::AbstractDict=SSDict(),
parse_response::Bool=true, kwargs...)
PUT Object data
at path
in bucket
.
Optional Arguments
data_type=
;Content-Type
header.encoding=
;Content-Encoding
header.acl=
;x-amz-acl
header for setting access permissions with canned config. See here.metadata::Dict=
;x-amz-meta-
headers.tags::Dict=
;x-amz-tagging-
headers (see alsos3_put_tags
ands3_get_tags
).parse_response::Bool=
; whenfalse
, return rawAWS.Response
kwargs
; additional kwargs passed through intoS3.put_object
AWSS3.s3_sign_url
— Functions3_sign_url([::AbstractAWSConfig], bucket, path, [seconds=3600];
[verb="GET"], [content_type="application/octet-stream"],
[protocol="http"], [signature_version="v4"])
Create a pre-signed url for bucket
and path
(expires after for seconds
).
To create an upload URL use verb="PUT"
and set content_type
to match the type used in the Content-Type
header of the PUT request.
For compatibility, the signature version 2 signing process can be used by setting signature_version="v2"
but it is recommended that the default version 4 is used.
url = s3_sign_url("my_bucket", "my_file.txt"; verb="PUT")
Requests.put(URI(url), "Hello!")
url = s3_sign_url("my_bucket", "my_file.txt";
verb="PUT", content_type="text/plain")
Requests.put(URI(url), "Hello!";
headers=Dict("Content-Type" => "text/plain"))
Permissions
s3:GetObject
(conditional): required permission whenverb="GET"
.s3:PutObject
(conditional): required permission whenverb="PUT"
.
AWSS3.s3_nuke_bucket
— Functions3_nuke_bucket([::AbstractAWSConfig], bucket_name)
Deletes a bucket including all of the object versions in that bucket. Users should not call this function unless they are certain they want to permanently delete all of the data that resides within this bucket.
The s3_nuke_bucket
is purposefully not exported as a safe guard against accidental usage.
Permanent data loss will occur when using this function. Do not use this function unless you understand the risks. By using this function you accept all responsibility around any repercussions with the loss of this data.
API Calls
Permissions
s3:ListBucketVersions
s3:DeleteObjectVersion
: required even on buckets that do not have versioning enabled.s3:DeleteBucket
S3Path
Note that S3Path
implements the AbstractPath
interface, some the FilePathsBase documentation for the interface here.
AWSS3.S3Path
— TypeS3Path()
S3Path(str::AbstractString; version::Union{Nothing, AbstractString}=nothing, config::Union{Nothing, AWS.AbstractAWSConfig}=nothing)
S3Path(path::S3Path; isdirectory=path.isdirectory, version=path.version, config=path.config)
Construct a new AWS S3 path type which should be of the form "s3://<bucket>/prefix/to/my/object"
.
NOTES:
- Directories are required to have a trailing
/
due to how S3 distinguishes files from folders, as internally they're just keys to objects. - Objects
p"s3://bucket/a"
andp"s3://bucket/a/b"
can co-exist. If both of these objects exist listing the keys forp"s3://bucket/a"
returns[p"s3://bucket/a"]
whilep"s3://bucket/a/"
returns[p"s3://bucket/a/b"]
. - The drive property will return
"s3://<bucket>"
- On top of the standard path properties (e.g.,
segments
,root
,drive
,separator
),S3Path
s also supportbucket
andkey
properties for your convenience. - If
version
argument isnothing
, will return latest version of object. Version can be provided via either kwargversion
or as suffix"?versionId=<object_version>"
ofstr
, e.g.,"s3://<bucket>/prefix/to/my/object?versionId=<object_version>"
. - If
config
is left at its default value ofnothing
, then the latestglobal_aws_config()
will be used in any operations involving the path. To "freeze" the config at construction time, explicitly pass anAbstractAWSConfig
to theconfig
keyword argument.
Base.stat
— Functionstat(fp::S3Path)
Return the status struct for the S3 path analogously to stat
for local directories.
Note that this cannot be used on a directory. This is because S3 is a pure key-value store and internally does not have a concept of directories. In some cases, a directory may actually be an empty file, in which case you should use s3_get_meta
.
Base.Filesystem.mkdir
— Functionmkdir(fp::S3Path; recursive=false, exist_ok=false)
Create an empty directory within an existing bucket for the S3 path fp
. If recursive
, this will create any previously non-existent directories which would contain fp
. An error will be thrown if an object exists at fp
unless exist_ok
.
Creating a directory in S3 creates a 0-byte object with a key set to the provided directory name.
Base.read
— Functionread(fp::S3Path; byte_range=nothing)
Fetch data from the S3 path as a Vector{UInt8}
. A subset of the object can be specified with byte_range
which should be a contiguous integer range, e.g. 1:4
.
AWSS3.get_config
— Functionget_config(fp::S3Path)
Returns the AWS configuration used by the path fp
. This can be stored within the path itself, but if not it will be fetched with AWS.global_aws_config()
.
Internal
AWSS3._s3_exists_dir
— Function_s3_exists_dir(aws::AbstractAWSConfig, bucket, path)
An internal function used by s3_exists
.
Checks if the given directory exists within the bucket
. Since S3 uses a flat structure, as opposed to being hierarchical like a file system, directories are actually just a collection of object keys which share a common prefix. S3 implements empty directories as 0-byte objects with keys ending with the delimiter.
It is possible to create non 0-byte objects with a key ending in the delimiter (e.g. s3_put(bucket, "abomination/", "If I cannot inspire love, I will cause fear!")
) which the AWS console interprets as the directory "abmonination" containing the object "/".
AWSS3.s3_exists_versioned
— Functions3_exists_versioned([::AbstractAWSConfig], bucket, path, version)
Returns if an object version
exists with the key path
in the bucket
.
Note that the AWS API's support for object versioning is quite limited and this check will involve try
/catch
logic. Prefer using s3_exists_unversioned
where possible for more performant checks.
See s3_exists
and s3_exists_unversioned
.
API Calls
Permissions
s3:GetObjectVersion
s3:ListBucket
(optional): allows requests to non-existent objects to throw a exception with HTTP status code 404 (Not Found) instead of HTTP status code 403 (Access Denied).
AWSS3.s3_exists_unversioned
— Functions3_exists_unversioned([::AbstractAWSConfig], bucket, path)
Returns a boolean whether an object exists at path
in bucket
.
See s3_exists
and s3_exists_versioned
.
API Calls
Permissions
s3:GetObject
s3:ListBucket
(optional): allows requests to non-existent objects to throw a exception with HTTP status code 404 (Not Found) instead of HTTP status code 403 (Access Denied).