---
url: /process-functions/s3bucket.md
description: The S3Bucket object provides methods to interact with AWS S3.
---

# S3Bucket

The `S3Bucket` object provides methods to interact with AWS S3.

To initialize an S3Bucket object, you would use [datasource.S3Bucket](/process-functions/datasource-s3bucket.html).

## Methods

### `list() -> Array`

Lists all objects in the bucket. Each object in the returned list contains:

* `name`: Name of the object.
* `size`: Size of the object in bytes.
* `last_modified`: Timestamp when the object was last modified.

**Example:**

```javascript
var s3Bucket = datasource.S3Bucket("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY", "YOUR_BUCKET_NAME", "us-west-1");
let allObjects = s3Bucket.list();

allObjects.forEach(object => {
    console.log(`Name: ${object.name}, Size: ${object.size}, Last Modified: ${object.last_modified}`);
});
```

***

### `uploadFile(String object_key, String uploaded_filename)`

Uploads a file from the MODLR file system to the S3 bucket.

Parameters:

* `object_key`: The key for the object in the S3 bucket.
* `uploaded_filename`: Path of the file to upload.

**Example:**

```javascript
let objectKey = "destination/folder/filename.txt";
let uploadedFilename = "local/path/to/yourfile.txt"; 

s3Bucket.uploadFile(objectKey, uploadedFilename);
```

***

### `downloadFile(String object_key, String output_filename)`

Downloads a file from the S3 bucket into the MODLR file system.

Parameters:

* `object_key`: The key for the object in the S3 bucket.
* `output_filename`: The path where the file will be saved.

**Example:**

```javascript
let objectKey = "source/folder/filename.txt";
let outputFilename = "local/path/where/file/should/be/saved.txt";

s3Bucket.downloadFile(objectKey, outputFilename);
```

***

### `generatePresignedURL(String object_key, long expires_after_minutes) -> String`

Generates a pre-signed URL for an object.

Parameters:

* `object_key`: The key for the object in the S3 bucket.
* `expires_after_minutes`: Duration in minutes after which the generated URL will expire.

Returns:

* A pre-signed URL string.

**Example:**

```javascript
let objectKey = "path/to/your/object.txt";
let expiresAfterMinutes = 60; 
let presignedUrl = s3Bucket.generatePresignedURL(objectKey, expiresAfterMinutes);

console.log(`Pre-signed URL: ${presignedUrl}`);
```
