> ## Documentation Index
> Fetch the complete documentation index at: https://arize-ax.mintlify.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS S3

> Set up an import job to ingest data into Arize from AWS S3

<Info>
  If you prefer to use Terraform, jump to [Applying Bucket Policy & Tag via Terraform](/ax/machine-learning/machine-learning/integrations-ml/aws-s3-example#applying-bucket-policy-and-tag-via-terraform)
</Info>

Set up an import job to log inference files to Arize. Updates to files are checked every 10 seconds. Users generally find a sweet spot around a few hundred thousand to a million rows in each file with the total file limit being 1GB.

## **Select Amazon S3**

Navigate to the 'Upload Data' page on the left navigation bar in the Arize platform. From there, select the 'AWS S3' card to begin **a new file import job.**

<Frame caption="Step 1: Select Amazon S3">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/e226bdb3-image.jpeg" />
</Frame>

## Enable Access To Individual or Multiple Buckets

There are two ways to setup access permissions with Arize

<Columns cols={2}>
  <Card title="Configure An Individual Bucket Policy" href="/ax/machine-learning/machine-learning/integrations-ml/aws-s3-example#configure-an-individual-bucket-policy">Give Arize permission to access individual buckets</Card>
  <Card title="Configure Multiple Buckets Via Role Based Permissions" href="/ax/machine-learning/machine-learning/integrations-ml/aws-s3-example#configure-multiple-buckets-via-role-based-permissions">Assign Arize a role to access multiple buckets using external IDs</Card>
</Columns>

<Tabs>
  <Tab title="Configure An Individual Bucket Policy">
    #### Add File Path

    Fill in the file path where you would like Arize to pull your model's inferences. Arize will automatically infer your bucket name and prefix.

    <Frame caption="Example File Path In Arize UI">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/31014ebb-image.jpeg" />
    </Frame>

    Create the path to your bucket and folder to pull your model's inferences. In this example, you might have an AWS bucket and folder named `s3://example-demo-bucket/click-thru-rate/production/v1/` that contains parquet files of your model inferences. Your bucket name is `example-demo-bucket` and your prefix is `click-thru-rate/production/v1/`*.*

    <Info>
      The file structure can take into consideration various model environments (training, production, etc) and locations of ground truth. In addition, S3 bucket import allows recursive operations. This means that it will include all nested subdirectories within the specified bucket prefix, regardless of the number or depth of these directories.
    </Info>

    **File Directory Example**

    There are multiple ways to structure your file directory. If actuals and predictions can be sent together, simply store this data in a the same file and import this data together through a single file importer job.

    In the case of delayed actuals, we recommend you separate your predictions and actuals into **separate folders** and loading this data through two separate file importer jobs. Learn more [here](/ax/machine-learning/machine-learning/concepts-ml/how-to-send-delayed-actuals).

    ```bash theme={null}
    s3://bucket1/click-thru-rate/production/prediction/
    ├── 11-19-2022.parquet 
    ├── 11-20-2022.parquet
    ├── 11-21-2022.parquet

    s3://bucket1/click-thru-rate/production/actuals/
    ├── 12-1-2022.parquet # same prediction id column, model, and space as the corresponding prediction
    ├── 12-2-2022.parquet
    └── 12-3-2022.parquet
    ```

    #### **Configure Ingestion Key**

    Tag your bucket with the key `arize-ingestion-key` and the provided tag value *(i.e.* [*AWS Object Tags*](https://docs.aws.amazon.com/AmazonS3/latest/userguide/tagging-managing.html)*).*

    **In Arize UI:** Copy `arize-ingestion-key` value

    <Frame caption="Example Bucket Tag In Arize UI">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/13cedd2c-image.jpeg" />
    </Frame>

    **In AWS Console:** Navigate to your S3 bucket -> Properties -> Edit Bucket Policy

    <Frame caption="Navigate to your bucket properties tab">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/623639f2-image.jpeg" />
    </Frame>

    **In AWS Console:** Set tag Key = `arize-ingestion-key` and Value as the value copied from Arize UI from the previous step

    <Frame caption="Add arize-ingestion-key as a bucket tag">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/c905ff80-image.jpeg" />
    </Frame>

    #### **Enable Bucket Policy Permissions**

    **In Arize UI:** Copy the policy supplied by Arize in the file importer job setup

    <Frame caption="Copy AWS Policy In Arize UI">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/3a11d391-image.jpeg" />
    </Frame>

    **In the AWS console:** Navigate to your S3 bucket -> Permission -> Edit Bucket Policy

    <Frame caption="Add/Edit bucket policy">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/05f821e4-image.jpeg" />
    </Frame>

    **In the AWS console:** Paste the above AWS policy from Arize UI into the bucket policy

    <Frame caption="Add policy to your bucket">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/0a5cab33-image.jpeg" />
    </Frame>
  </Tab>

  <Tab title="Configure Multiple Buckets Via Role Based Permissions">
    #### **Configure Role Based Permissions**

    <Info>
      If your data contains image embeddings with S3 links to the images, use the method of setting up "Individual Bucket Access" and do not use the Role Based access described here. Visit [here](/ax/machine-learning/machine-learning/integrations-ml/aws-s3-example/aws-s3-example) for information on configuring S3 image access.

      If your S3 images are encrypted using the AWS managed KMS encryption key and thus, individual bucket access is not an option, please reach out to [support@arize.com](mailto:support@arize.com) for more assistance.
    </Info>

    **Ask Arize:** To give Arize access to multiple buckets, ask arize to provide you with an[External ID](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user_externalid.html). **Reach out to ****[support@arize.com](mailto:support@arize.com)**** for assistance.**

    **Provide Arize:** Provide Arize with the role ARN to access each AWS bucket you want to connect.

    **In AWS Console:** For each role, Arize will assume add the following statement to the role's Trust Policy

    ```json theme={null}
    {
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::756106863523:root"
        },
        "Action": "sts:AssumeRole",
        "Condition": {
            "StringEquals": {
                "sts:ExternalId": "<EXTERNAL ID PROVIDED BY ARIZE>"
            }
        }
    }
    ```

    **In AWS Console:** Add the following statement to the role's Permissions Policies

    ```json theme={null}
    {
        "Effect": "Allow",
        "Action": [
            "s3:GetBucketTagging",
            "s3:GetObject",
            "s3:ListBucket"
        ],
        "Resource": [
            "arn:aws:s3:::<YOUR BUCKET NAME>",
            "arn:aws:s3:::<YOUR BUCKET NAME>/*"
            ]
        }
    ```

    #### **Configure Ingestion Key**

    Tag your bucket with the key `arize-ingestion-key` and the provided tag value *(i.e.* [*AWS Object Tags*](https://docs.aws.amazon.com/AmazonS3/latest/userguide/tagging-managing.html)*).*

    **In Arize UI:** Copy `arize-ingestion-key` value

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/632f3e62-image.jpeg" />
    </Frame>

    **In AWS Console:** Navigate to your S3 bucket -> Properties -> Edit Bucket Policy

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/9ff1090a-image.jpeg" />
    </Frame>

    **In AWS Console:** Set tag Key = `arize-ingestion-key` and Value as the value copied from Arize UI from the previous step

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/3a681aa2-image.jpeg" />
    </Frame>
  </Tab>
</Tabs>

## **Define Your Model Schema**

Model schema parameters are a way of organizing model inference data to ingest to Arize. When configuring your schema, be sure to match your data column headers with the model schema.

You can either **use a form** or a simple **JSON-based schema** to specify the column mapping.

Arize supports **CSV, Parquet, Avro**, and **Apache Arrow.** Refer [here](/ax/machine-learning/machine-learning/how-to-ml/upload-data-to-arize/sending-data-faq#what-are-the-expected-data-types-for-my-file-type) for a list of the expected data types by input type.

<Frame caption="File Schema Form Inputs">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/e1172c00-image.jpeg" />
</Frame>

<Frame caption="Form Schema JSON Inputs">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/4047340a-image.jpeg" />
</Frame>

Learn more about Schema fields [here](https://arize.com/docs/ax/machine-learning/machine-learning/concepts-ml/model-schema-reference).

## Validate Your Model Schema

Once you fill in your applicable predictions, actuals, and model inputs, click 'Validate Schema' to visualize your model schema in the Arize UI. Check that your column names and corresponding data match for a successful import job.

<Frame caption="">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/95f2f2d5-image.jpeg" />
</Frame>

Once finished, your import job will be created and will start polling your bucket for files.

<Info>
  If your model receives delayed actuals, connect your predictions and actuals using the same **prediction ID**, which links your data together in the Arize platform. Arize regularly checks your data source for both predictions and actuals, and ingests them separately as they become available. Learn more [here](/ax/machine-learning/machine-learning/how-to-ml/upload-data-to-arize/sending-data-faq#delayed-actuals-q-and-a).
</Info>

## **Check Job Status**

Arize will attempt a dry run to validate your job for any access, schema, or record-level errors. If the dry run is successful, you can proceed to create the import job. From there, you will be taken to the 'Job Status' tab.

All active jobs will regularly sync new data from your data source with Arize. You can view the job details by clicking on the job ID, which reveals more information about the job.

<Frame caption="Job status page showing job listings">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/05e23085-image.jpeg" />
</Frame>

To pause, delete, or edit your file schema, click on 'Job Options'.

* **Delete** a job if it is no longer needed or if you made an error connecting to the wrong bucket. This will set your job status as 'deleted' in Arize.

* **Pause** a job if you have a set cadence to update your table. This way, you can 'start job' when you know there will be new data to reduce query costs. This will set your job status as 'inactive' in Arize.

* **Edit** a file schema if you have added, renamed, or missed a column in the original schema declaration.

## Troubleshoot Import Job

An import job may run into a few problems. Use the dry run and job details UI to troubleshoot and quickly resolve data ingestion issues.

#### Validation Errors

If there is an error validating a file against the model schema, Arize will surface an **actionable** error message. From there, click on the 'Fix Schema' button to adjust your model schema.

<Frame caption="">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/4ed14075-image.jpeg" />
</Frame>

#### Dry Run File/Table Passes But The Job Fails

If your dry run is successful, but your job fails, click on the job ID to view the **job details**. This uncovers job details such as information about the file path or query id, the last import job, potential errors, and error locations.

<Frame caption="">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/a4992f3f-image.jpeg" />
</Frame>

Once you've identified the job failure point, fix the file errors and reupload the file to Arize with a new name.

## Applying Bucket Policy & Tag via Terraform

```powershell theme={null}
resource "aws_s3_bucket" "arize-example-bucket" {
  bucket = "my-arize-example-bucket"
  tags = {
    arize-ingestion-key = "value_from_arize_ui"
  }
}

resource "aws_s3_bucket_policy" "grant_arize_read_only_access" {
  bucket = aws_s3_bucket.arize-example-bucket.id
  policy = data.aws_iam_policy_document.grant_arize_read_only_access.json
}

data "aws_iam_policy_document" "grant_arize_read_only_access" {
  statement {
    principals {
      type        = "AWS"
      identifiers = ["arn:aws:iam::<REDACTED>:role/arize-importer"]
    }

    actions = [
      "s3:GetBucketTagging",
      "s3:GetObject",
      "s3:ListBucket",
    ]

    resources = [
      aws_s3_bucket.arize-example-bucket.arn,
      "${aws_s3_bucket.arize-example-bucket.arn}/*",
    ]
  }
}
```
