S3 service is a service help us store files. We can use s3 to store update patches for our game, users' save game files, users generated content and so on.
create s3 object
To access s3 service, we need to create a s3 object on client side.
To use s3 service on server side, we need to enable server mode and use it with imds.
Access key id and secret key credentials is required by all s3 object nodes. We can get access key id and secret key from pre-created IAM user or get allocated from cognito identity pool.
In s3, files are stored in bucket as objects with key which represent file path in s3. We can put, get, list, head, copy object.
To upload a file, we can call put object with file(absolute file path), bucket, key.
Put object may take very long time, to be safe, we shouldn't use PIE to test our game with this function.
To download a file, we can call get object with bucket, key.
The downloaded file will be saved to temporary file path. The file path will be returned in body of get object result.
Get object may take very long time, to be safe, we shouldn't use PIE to test our game with this function.
To list objects in a bucket, we can call list objects with bucket.
If we only want to get detail of an object instead of the whole file, we can call head object with bucket, key.
We can also operate objects in a bucket. We can copy, delete object in bucket.
To copy an object in the s3 to another place, we can call copy object with bucket, copy source, key.
To delete an object or objects in a bucket, we can call delete object with bucket, key or delete objects with bucket, delete object.
Sometimes, we may want to upload a large file or maybe we want to upload a creating file. We can use multipart upload.
Sometimes, we may want to encrypt the file we upload and decrypt when we download, we can use s3 encryption service.
Transfer manager is an embedded download and upload solution. It can help us download and upload files in the fastest and the most convenient way. It uses multipart upload to upload files. It will retry download and upload if there is a failure.
To use transfer manager, we need to construct a transfer manager configuration with an s3 object first.
We can also create a subclass of transfer manager configuration and override its functions to get more details about the download and upload process.
Next, we need to call create transfer manager object with transfer manager configuration.
With the transfer manager object, we can download and upload file or files in directory, manually retry download and upload, abort multipart upload.
To download a single file, we can call download file with bucket name, key name, write to file.
To upload a single file, we can call upload file with file name, bucket name, key name.
Download file and upload file will return a transfer handler, with which we can monitor and control the download and upload process.
To download files in a directory of the bucket, we can call download to directory with directory, bucket name, prefix(directory in s3).
To upload files in a directory, we can call upload directory with directory, bucket name, prefix(directory in s3).
To get transfer handler in download to directory and upload directory, we need to override transfer initiated function in transfer manager configuration. Each file download or upload process will trigger transfer initiated function when it starts.
With the transfer handler, we can call retry download and retry upload and abort multipart upload.
Retry download will help us retry a failed download process, we can call retry download with retry handler(transfer handler).
Retry upload will help us retry a failed upload process, we can call retry upload with file name, retry handler(transfer handler).
We can also call abort multipart upload with in progress handler(transfer handler) to abort an upload process.