class S3 extends AnyRef
Optimized for read-mostly AWS S3 buckets; uses caching to speed access.
To clear the caches after a invoking method that caches its response, either the app must be restarted or the clearCaches
method must be called.
Methods that are cached are denoted by cached.
When uploading, any leading slashes for keys are removed because when AWS S3 is enabled for a web site, S3 adds a leading slash.
Keys of assets that were uploaded by other clients might start with leading slashes, or a dash; those assets can not be fetched by web browsers.
When web site access to an S3 bucket is enabled, AWS content is accessed by paths constructed by concatenating the URL, a slash (/),
and the keyed data.
The keys must therefore consist of relative paths (relative directory name followed by a file name), and must not start with a leading slash.
awslib_scala
stores each file name (referred to by AWS as a key) without a leading slash.
For example, assuming that the default file name is index.html
, then http://domain.com
and http://domain.com/
are translated to http://domain.com/index.html
.
As another example, the key for a file in a directory called <WEBROOT>/blah/ick/yuck.html
is defined as blah/ick/yuck.html
.
AWS does not respect the last-modified
metadata provided when uploading; it uses the upload timestamp instead.
After uploading, the last-modified
timestamp of the uploaded file is read and applied to the local copy of the file
so the timestamps match.
Java on Windows does not handle last-modified
properly, so the creation date is set to the last-modified
date for files (Windows only).
For each directory, AWS creates a file of the same name, with the suffix _$folder$
.
If one of those files are deleted, the associated directory becomes unreachable. Don't mess with them.
These hidden files are ignored by awslib_scala
; users never see them because they are for AWS S3 internal use only.
- Source
- S3.scala
- Alphabetic
- By Inheritance
- S3
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new S3()
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
val
_allObjectData: Memoizer[(String, String), List[S3ObjectSummary]]
- Attributes
- protected
-
val
_bucketExists: Memoizer[String, Boolean]
- Attributes
- protected
-
val
_bucketLocation: Memoizer[String, String]
- Attributes
- protected
-
val
_bucketNames: Memoizer0[List[String]]
- Attributes
- protected
-
def
_bucketNamesWithDistributions(cf: CloudFront): List[String]
- Attributes
- protected
-
val
_bucketsWithDistributions: Memoizer[CloudFront, List[Bucket]]
- Attributes
- protected
- val _findByName: Memoizer[String, Option[Bucket]]
-
val
_isWebsiteEnabled: Memoizer[String, Boolean]
Requires property com.amazonaws.sdk.disableCertChecking to have a value (any value will do)
- val _listObjectsByPrefix: Memoizer[(String, String, String, Boolean), List[String]]
- val _oneObjectData: Memoizer[(String, String), Option[S3ObjectSummary]]
- val _resourceUrl: Memoizer[(String, String, Option[CloudFrontAlias]), String]
-
def
allObjectData(bucketName: String, prefix: String): List[S3ObjectSummary]
cached
cached
- prefix
Any leading slashes are removed if a prefix is specified
- returns
collection of S3ObjectSummary; keys are relativized if prefix is adjusted
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- def bucketExists(bucketName: String): Boolean
-
def
bucketLocation(bucketName: String): String
cached
-
def
bucketNames: List[String]
cached List the buckets in the account.
-
def
bucketNamesWithDistributions(implicit cf: CloudFront): Memoizer[CloudFront, List[String]]
cached Either the memo cache must be cleared, or the app must be restarted if a bucket or distribution is created after this method is called, or the bucket or distribution will never be found
-
def
bucketsWithDistributions(implicit cf: CloudFront): List[Bucket]
Either the memo cache must be cleared, or the app must be restarted if a bucket or distribution is created after this method is called, or the bucket or distribution will never be found
- val cacheIsDirty: AtomicBoolean
- def clearCaches(): Unit
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @throws( ... )
-
def
createBucket(bucketName: String): Bucket
Create a new S3 bucket.
Create a new S3 bucket. If the bucket name starts with "www.", make it publicly viewable and enable it as a web site. Amazon S3 bucket names are globally unique, so once a bucket repoName has been taken by any user, you can't create another bucket with that same repoName. You can optionally specify a location for your bucket if you want to keep your data closer to your applications or users.
-
def
deleteBucket(bucketName: String): Unit
Delete a bucket – the bucket will automatically be emptied if necessary so it can be deleted.
Delete a bucket – the bucket will automatically be emptied if necessary so it can be deleted.
- Annotations
- @throws( classOf[AmazonClientException] )
-
def
deleteObject(bucketName: String, key: String): Unit
Delete an object – if they key has any leading slashes, they are removed.
Delete an object – if they key has any leading slashes, they are removed. Unless versioning has been turned on for the bucket, there is no way to undelete an object.
-
def
deletePrefix(bucketName: String, prefix: String): Unit
Normal use case is to delete a directory and all its contents
- def disableWebsite(bucketName: String): Unit
-
def
downloadFile(bucketName: String, key: String): InputStream
Download an object – if the key has any leading slashes, they are removed.
Download an object – if the key has any leading slashes, they are removed. When you download an object, you get all of the object's metadata and a stream from which to read the contents. It is important to read the contents of the stream as quickly as possible since the data is streamed directly from Amazon S3 and the network connection will remain open until all the data is read or the input stream is closed.
GetObjectRequest
also supports several other options, including conditional downloading of objects based on modification times, ETags, and selectively downloading a range of an object; none of these are used. -
def
emptyBucket(bucketName: String): Unit
- Annotations
- @throws( classOf[AmazonClientException] )
-
def
enableCors(bucket: Bucket): Unit
Cross-Origin Resource Sharing
Cross-Origin Resource Sharing
- See also
https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
<?xml version="1.0" encoding="UTF-8"?> <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>GET</AllowedMethod> <AllowedMethod>HEAD</AllowedMethod> <AllowedMethod>PUT</AllowedMethod> <AllowedMethod>POST</AllowedMethod> <AllowedMethod>DELETE</AllowedMethod> <AllowedHeader>*</AllowedHeader> </CORSRule> </CORSConfiguration>
- def enableWebsite(bucketName: String, errorPage: String): Unit
- def enableWebsite(bucketName: String): Unit
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
findByName(bucketName: String): Option[Bucket]
cached
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
isWebsiteEnabled(bucketName: String): Boolean
cached
-
def
listObjectsByPrefix(bucketName: String, prefix: String, suffix: String = "", showSize: Boolean = false): List[String]
** cached ** List objects in given bucketName by prefix; number of bytes is included if showSize is true.
** cached ** List objects in given bucketName by prefix; number of bytes is included if showSize is true.
- prefix
Any leading slashes are removed if a prefix is specified
- suffix
optional secondary filter
-
def
move(oldBucketName: String, oldKey: String, newBucketName: String, newKey: String): Unit
Move
oldKey
in bucket withbucketName
tonewBucket
/newKey
.Move
oldKey
in bucket withbucketName
tonewBucket
/newKey
. Object metadata is preserved. -
def
move(bucketName: String, oldKey: String, newKey: String): Unit
Move
oldKey
in bucket withbucketName
tonewKey
.Move
oldKey
in bucket withbucketName
tonewKey
. Object metadata is preserved. -
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate()
-
def
oneObjectData(bucketName: String, prefix: String): Option[S3ObjectSummary]
cached
cached
- prefix
Any leading slashes are removed if a prefix is specified
- returns
Option[ObjectSummary] with leading "./", prepended if necessary
- implicit val s3: S3
- implicit val s3Client: AmazonS3Client
- def sanitizedPrefix(key: String): String
-
def
setBucketPolicy(bucket: Bucket, policyJson: String): Bucket
This method is idempotent Side effect: sets policy for AWS S3 upload bucket
-
def
setBucketPolicy(bucket: Bucket, statements: List[Statement]): Bucket
This method is idempotent Side effect: sets policy for AWS S3 upload bucket
- def setContentType(key: String, metadata: ObjectMetadata): ObjectMetadata
- def setContentType(key: String): ObjectMetadata
-
def
signUrl(bucket: Bucket, url: URL, minutesValid: Int = 60, useHttps: Boolean = false, maybeCnameAlias: Option[String] = None): URL
- useHttps
is only used if
maybeCnameAlias
isNone
-
def
signUrlStr(bucket: Bucket, key: String, minutesValid: Int = 0, useHttps: Boolean = false, maybeCnameAlias: Option[String] = None): URL
- useHttps
is only used if
maybeCnameAlias
isNone
-
def
staticResourceUrl(bucketName: String, key: String)(implicit maybeAlias: Option[StaticCFAlias]): String
cached The cache must be cleared or the app must be restarted if a bucket is created or the referenced CloudFront distribution alias is created (by assigning a CNAME) after this method is first called, or the distribution with the desired cname will never be found
-
def
streamingResourceUrl(bucketName: String, key: String)(implicit maybeAlias: Option[StreamingCFAlias]): String
cached The cache must be cleared or the app must be restarted if a bucket is created or the referenced CloudFront distribution alias is created (by assigning a CNAME) after this method is first called, or the distribution with the desired cname will never be found
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
uploadFile(bucketName: String, key: String, file: File, showProgress: Boolean = false): PutObjectResult
Uploads a file to the specified bucket using the REST interface that backs the Java facade.
Uploads a file to the specified bucket using the REST interface that backs the Java facade. The file's last-modified date is applied to the uploaded file. AWS does not respect the last-modified metadata, and Java on Windows does not handle last-modified properly either. If the key has leading slashes, they are removed for consistency.
AWS does not respect the last-modified metadata provided when uploading; it uses the upload timestamp instead. After uploading, the last-modified timestamp of the uploaded file is read and applied to the local copy of the file so the timestamps match.
Java on Windows does not handle last-modified properly, so the creation date is set to the last-modified date (Windows only).
To list the last modified date with seconds in bash with:
ls -lc --time-style=full-iso
To list the creation date with seconds in bash with:ls -l --time-style=full-iso
-
def
uploadFileOrDirectory(bucketName: String, dest: String, file: File): Unit
Recursive upload to AWS S3 bucket
Recursive upload to AWS S3 bucket
- dest
path to copy to on AWS S3
- file
or directory to copy
-
def
uploadStream(bucketName: String, key: String, stream: InputStream, length: Int): Unit
- key
if the key has any leading slashes, they are removed
- See also
- def uploadString(bucketName: String, key: String, contents: String): PutObjectResult
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
Deprecated Value Members
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @Deprecated @deprecated @throws( classOf[java.lang.Throwable] )
- Deprecated
(Since version ) see corresponding Javadoc for more information.
-
def
resourceUrl(bucketName: String, key: String): String
cached The cache must be cleared or the app must be restarted if a bucket is created after this method is first called, or the bucket will never be found
cached The cache must be cleared or the app must be restarted if a bucket is created after this method is first called, or the bucket will never be found
- Annotations
- @deprecated
- Deprecated
(Since version 1.0.4) Use staticResourceUrl or streamingResourceUrl instead