Skip to main content

S3 Library

The S3 Library is an importable library containing functions to read, write, and list with AWS S3 buckets. This library is used in the AWS S3 Adapter.

When imported into projects, typically only the S3client module needs to be required in order to create the client and access the API methods.

require "S3.S3client"   

How it works:

Use the Translator's built in help to review how to use each function:

S3client - sets up the adapter framework

Sets up the S3 adapter framework, adding the various method modules to a metatable and storing the configurations added to the custom fields.

S3custom - makes API requests and returns the response

S3custom takes in any API requests and parameters to make the API call and return the response.

  • Uses the passed configurations API request parameters - the canonical endpoint (ex. JSON/), method (ex. get), action (ex. list) and parameters (ex. list-type) for the call (ex. the list of files in the bucket) - to build and carry out the appropriate HTTP request.

S3list - prepares the arguments and calls S3custom for an S3 bucket list request

S3list prepares the arguments and calls S3custom for an S3 bucket List HTTP GET request.

S3readFile - prepares the arguments and calls S3custom for an S3 bucket read file request

S3readFile prepares the arguments and calls S3custom for an S3 bucket read HTTP GET request.

S3upload - prepares the arguments and calls S3custom for an S3 bucket upload file request

S3upload prepares the arguments and calls S3custom for an S3 bucket upload HTTP PUT request.

S3createHeaders - generates headers using S3 credentials for requests

S3createHeaders generates headers for each HTTP request.

  • authorization- generated based on the payload, canonical endpoint, parameters, and action, then signed with IAM user credentials. This header is used with every request type.

  • content-type- content type of the data in the HTTP request. This header is used with PUT requests.

  • content-length - size of the message in bytes. This header is used with PUT requests.

  • Expect- response expected by the server. This header is used with PUT requests.

  • Connection - controls if network connection stays open after the request is complete. This header is used with PUT requests.

S3logWebErrors - logs web errors from requests and sleeps when necessary

S3logWebErrors records web errors to the logs. Depending on the web error, util.sleep will be utilized if the error suggests the same request may be successful at a later point in time.

S3retry - retries requests if first attempt fails

S3retry retries web (HTTP) requests if the initial request fails.