# Save To S3 (`drinksight/save-to-s3`) Actor

Designed to be run from an ACTOR.RUN.SUCCEEDED webhook, this actor downloads a task run's default dataset and saves it to an S3 bucket.

- **URL**: https://apify.com/drinksight/save-to-s3.md
- **Developed by:** [Richard Weaver](https://apify.com/drinksight) (community)
- **Categories:** Automation, Open source
- **Stats:** 101 total users, 11 monthly users, 12.9% runs succeeded, 4 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## save-to-s3

An [Apify](https://apify.com) actor to save the default dataset of a run to an S3 bucket.

It is designed to be called from the ACTOR.RUN.SUCCEEDED webhook of the actor that has generated the dataset.

This actor is compatible with API v2 - I made it because I couldn't get the [Crawler Results To S3](https://apify.com/apify/crawler-results-to-s3) actor to work with v2 actors.

### Usage

AWS credentials and options for fomatting the data set are set on this actor's input, which are merged with the webhook's post data. You'll therefore need to create a task for your uploads so you can save common config such as your AWS credentials and dataset format details.

#### 1. Create the task

Create a new task using the save-to-3 actor. This allows you to specify input to use every time the task is run. The webhook's post data will be merged with this at runtime - the values are those from the [get actor run API endpoint](https://apify.com/docs/api/v2#/reference/actors/run-object/get-run), all grouped under a `resource` property.

The properties you can specify in your Input for the task:

| Property          | Description                                                                                                                                                                                                                                                                                                                                                                                      |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `accessKeyId`     | The access key for the AWS user to connect with                                                                                                                                                                                                                                                                                                                                                  |
| `secretAccessKey` | The secret access key for the AWS user to connect with                                                                                                                                                                                                                                                                                                                                           |
| `region`          | The AWS region your bucket is located in (eg `eu-west-2`)                                                                                                                                                                                                                                                                                                                                        |
| `bucket`          | The bucket name to save files to                                                                                                                                                                                                                                                                                                                                                                 |
| `objectKeyFormat` | A string to specify the key (i.e. filename) for the S3 object you will save. You can specify any property from the `input` object using dot notation in a syntax similar to JavaScript template literals. For example, the defauult value `${resource.id}_${resource.startedAt}.${format}` will yield an S3 object with a name something like `SBNgQGmp87LtspHF1_2019-05-15T07:25:00.414Z.json`. |
| `format`          | Maps to the `format` parameter of the [get dataset items API endpoint](https://apify.com/docs/api/v2#/reference/datasets/item-collection) and accepts any of the valid string values                                                                                                                                                                                                             |
| `clean`           | Maps to the `clean` parameter of the [get dataset items API endpoint](https://apify.com/docs/api/v2#/reference/datasets/item-collection)                                                                                                                                                                                                                                                         |
| `datasetOptions`  | An object that allows you to specify any of the other parameters of the [get dataset items API endpoint](https://apify.com/docs/api/v2#/reference/datasets/item-collection), for example `{ "offset": "10" }` is the equivalent of settings `?offset=10` in the API call                                                                                                                         |
| `debugLog`        | A `boolean` indicating whether to use debug level logging                                                                                                                                                                                                                                                                                                                                        |

#### 2. Create the webhook

Go to your save-to-s3 task's API tab and copy the URL for the Run Task endpoint, which will be in the format: `https://api.apify.com/v2/actor-tasks/TASK_NAME_HERE/runs?token=YOUR_TOKEN_HERE`

Go to either the actor or (more likely) the actor task you want to add save-to-s3 functionality to. In the Webhooks tab, add a webhook with the URL you just copied. For Event types, select ACTOR.RUN.SUCCEEDED. Then Save.

### Security

Because you store yoour AWS user's key and secret as part of this actor's input, it is *strongly recommended* that you create an AWS IAM user specifically for Apify, and only grant access to the specific buckey you are using.

An example policy:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:GetBucketLocation", "s3:ListAllMyBuckets"],
      "Resource": "arn:aws:s3:::*"
    },
    {
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": ["arn:aws:s3:::YOUR-BUCKET", "arn:aws:s3:::YOUR-BUCKET/*"]
    }
  ]
}
```

# Actor input Schema

## `accessKeyId` (type: `string`):

Enter the access key ID for the AWS user

## `secretAccessKey` (type: `string`):

Enter the secret access key for the AWS user

## `region` (type: `string`):

Enter the AWS region your S3 bucket is located in

## `bucket` (type: `string`):

Enter the name of the S3 bucket to use

## `objectKeyFormat` (type: `string`):

The key to use for the filename

## `format` (type: `string`):

The data format to download the dataset in

## `clean` (type: `boolean`):

Crawler will ignore SSL certificate errors.

## `datasetOptions` (type: `object`):

An object whose properties will be enumerated and added to the dataset get items API request. See https://apify.com/docs/api/v2#/reference/datasets/item-collection/get-items.

## `debugLog` (type: `boolean`):

Debug messages will be included in the log. Use <code>context.log.debug('message')</code> to log your own debug messages.

## Actor input object example

```json
{
  "objectKeyFormat": "${resource.id}_${resource.startedAt}.${format}",
  "format": "json",
  "clean": false,
  "datasetOptions": {},
  "debugLog": false
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "accessKeyId": "",
    "secretAccessKey": "",
    "region": "",
    "bucket": "",
    "objectKeyFormat": "${resource.id}_${resource.startedAt}.${format}",
    "datasetOptions": {}
};

// Run the Actor and wait for it to finish
const run = await client.actor("drinksight/save-to-s3").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "accessKeyId": "",
    "secretAccessKey": "",
    "region": "",
    "bucket": "",
    "objectKeyFormat": "${resource.id}_${resource.startedAt}.${format}",
    "datasetOptions": {},
}

# Run the Actor and wait for it to finish
run = client.actor("drinksight/save-to-s3").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "accessKeyId": "",
  "secretAccessKey": "",
  "region": "",
  "bucket": "",
  "objectKeyFormat": "${resource.id}_${resource.startedAt}.${format}",
  "datasetOptions": {}
}' |
apify call drinksight/save-to-s3 --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,drinksight/save-to-s3"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/zPS5oJWp7gcpJmxeX/builds/K6mwi4jeedzGpb3Tp/openapi.json
