# Integrating with S3

[Prerequisites](#prerequisites)

[Amazon S3 Setup](#amazon-s3-setup)\
[Integration Methods](#integration-methods)\
[Method 1: Using Access Key and Secret](#method-1-using-access-key-and-secret)\
&#x20;  [Step 1: Create an IAM policy](#step-1-create-an-iam-policy)\
&#x20;  [Step 2: Create User](#step-2-create-user)\
&#x20;  [Step 3: Generate the Access key and secret](#step-3-generate-the-access-key-and-secret)\
&#x20;  [Step 4: Integration details](#step-4-integration-details)\
[Method 2: Using the IAM role](#method-2-using-iam-role)\
&#x20;  [Step 1: Create an IAM policy](#step-1-create-an-iam-policy-1)\
&#x20;  [Step 2: Create an IAM role](#step-2-create-an-iam-role)\
&#x20;  [Step 3: Adding permissions to the S3 bucket](#step-3-adding-permissions-to-the-s3-bucket)\
&#x20;  [Step 4: Integration details](#step-4-integration-details-1)

## Prerequisites

To connect your Amazon S3 bucket to Drivetrain, you need:

* An S3 bucket containing files with CSV file types and encodings
* For private or encrypted buckets, an AWS account with the ability to grant Drivetrain permission and to read from the bucket

## Amazon S3 Setup <a href="#amazon-s3-setup" id="amazon-s3-setup"></a>

We recommend disabling Access Control Lists (ACLs) on each S3 bucket so that the bucket contents are controlled by the bucket's access control settings and not the original file owner's settings. For more information about disabling ACLs for your bucket, see [Amazon S3 documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html).

## Integration Methods <a href="#integration-methods" id="integration-methods"></a>

Method 1: Using the Access key and Secret

* Bucket name
* Folder path
* Access key
* Access secret
* AWS Region

Method 2: Using Roles (More secure)

* Bucket name
* Folder path
* AWS Region

## Method 1: Using Access Key and Secret <a href="#method-1-using-access-key-and-secret" id="method-1-using-access-key-and-secret"></a>

### Step 1: Create an IAM Policy <a href="#step-1-create-an-iam-policy" id="step-1-create-an-iam-policy"></a>

{% hint style="info" %}
You must create an IAM policy for both the IAM Role and Access Key and Secret approaches.
{% endhint %}

{% hint style="info" %}
For encrypted buckets, follow [Amazon S3 bucket instructions](https://aws.amazon.com/premiumsupport/knowledge-center/s3-bucket-access-default-encryption/) to modify the AWS KMS key's policy to grant Drivetrain permissions to download files from your encrypted bucket
{% endhint %}

1. Open your [Amazon IAM console](https://console.aws.amazon.com/iam/home#home).
2. Go to **Policies**, then click **Create Policy**

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2F9b7YpLn16mPTpYEEpgtN%2FS3-1.avif?alt=media&#x26;token=dbaedb24-bf9b-488a-91c3-14394b1d318a" alt=""><figcaption></figcaption></figure>

3. Go to the **JSON** tab

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2FNyOpLeZkhAO8tVW8hkAs%2FS3-2.avif?alt=media&#x26;token=e215a126-795e-4a42-8d58-015f890db6bb" alt=""><figcaption></figcaption></figure>

4. Copy the following policy and paste it into the visual editor. Replace `{your-bucket-name}` with the name of your S3 bucket. After that, click **Next: Tags**.

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
        "Effect": "Allow",
        "Action": [
                "s3:GetBucketLocation",
                "s3:GetObject",
                "s3:ListBucket"

        ],
        "Resource": [
                "arn:aws:s3:::{your-bucket-name}/*",
                "arn:aws:s3:::{your-bucket-name}"
        ]
        }
    ]
}
```

\
5\. ***(Optional)*** If you use a customer-managed KMS key, add the following policy to the Action section of the IAM policy to provide read access to the encrypted files.

```
Action": [
         "kms:Decrypt",
         "kms:GenerateDataKey"
     ] 
```

6. In the Add tags step, you can optionally add custom tags that will be associated with your bucket. Click **Next: Review**.
7. In the Review policy step, specify the name of your policy, for example "Drivetrain-S3-Access", then click **Create policy.**

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2FOlOYjpjYzEj2LAOYGq0m%2FS3-3.png?alt=media&#x26;token=618a7ca9-c2df-4159-948a-7da329758901" alt=""><figcaption></figcaption></figure>

### Step 2: Create User <a href="#step-2-create-user" id="step-2-create-user"></a>

1. Open your [Amazon IAM console](https://console.aws.amazon.com/iam/home#home).
2. Go to **Users**, then click **Add users**.
3. Enter the user name, then click **Next**.
4. Select the **Attach policies directly** option, then choose the "Drivetrain-S3-Access" policy you created in Step 1.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2FGDEGGFJtZLZjPgdhd0Jv%2FS3-4.png?alt=media&#x26;token=2ec71588-b5a3-453d-afd1-14729dc7c48a" alt=""><figcaption></figcaption></figure>

5. Click **Next**, then click **Create User.**

### Step 3: Generate the access key and secret <a href="#step-3-generate-the-access-key-and-secret" id="step-3-generate-the-access-key-and-secret"></a>

1. In the **Users** tab, open the User you created.
2. Go to the **Security credentials** tab and navigate to the **Access keys** section.
3. Click the **Create access key**.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2FJBxgDnbZl8j6xPxqE73O%2FS3-5.png?alt=media&#x26;token=11c27b0d-e12c-4776-bb1b-e0a5ff482599" alt=""><figcaption></figcaption></figure>

4. From the **Use Case** options, select the **Third-party service** option and then click **Next**.
5. Enter a **Description tag** value and then click the **Create access key**.
6. Copy the **Access key** and **Secret access key** values. You will need them to configure the integration.

### Step 4: Integration details <a href="#step-4-integration-details" id="step-4-integration-details"></a>

Share the following details with the Drivetrain team:

1. Bucket name
2. Folder path
3. Access key
4. Access secret
5. AWS Region

## Method 2: Using IAM Role <a href="#method-2-using-iam-role" id="method-2-using-iam-role"></a>

### Step 1: Create an IAM Policy <a href="#step-1-create-an-iam-policy-1" id="step-1-create-an-iam-policy-1"></a>

Follow the same steps as in [Step 1](#step-1-create-an-iam-policy) of Method 1.

### Step 2: Create an IAM Role <a href="#step-2-create-an-iam-role" id="step-2-create-an-iam-role"></a>

1. Go to Roles, then click **Create role.**

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fwg6e3sgeqqP92ZAbgmyr%2FS3-6.png?alt=media&#x26;token=a089fbef-f444-4973-9e2e-9573a633d37b" alt=""><figcaption></figcaption></figure>

2. Select AWS account, then enter Drivetrain’s AWS Account ID, `865992467666`, in the **Account ID** field.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2FOxH5xqaFvXlKSdxMMwMQ%2FS3-7.png?alt=media&#x26;token=d9dd5b7f-2401-420b-b75e-31f1b9fe4407" alt=""><figcaption></figcaption></figure>

3. In the **Add permissions** step, select the "Drivetrain-S3-Access" policy you created, then click **Next.**

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2FYJaolOjUZdcx6LhhkeOn%2FS3-8.png?alt=media&#x26;token=9ec1b7f3-6726-4152-94e9-f31a646c0f57" alt=""><figcaption></figcaption></figure>

4. Enter the name Drivetrain-Integration check Trust policy settings and attached policy and click Create Role.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2FDGIEuN7LsedwJOsbfAuV%2FS3-9.png?alt=media&#x26;token=e8f23808-a1cd-4241-9367-13d9df125134" alt=""><figcaption></figcaption></figure>

### Step 3: Adding permissions to the S3 bucket

To assign permissions to your S3 bucket, follow the below steps:

1. Select the bucket to which you want to assign permissions.
2. Navigate to the **Permissions** tab.
3. Go to **Bucket Policy.**
4. Click **Edit**. Copy the below policy and paste it into the visual editor. Replace `{your-bucket-name}` with the name of your S3 bucket.

```
{    
	"Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::865992467666:role/Drivetrain-Integration"
            },
            "Action": [
                "s3:GetBucketLocation",
                "s3:GetObject",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::{your-bucket-name}/*",
				"arn:aws:s3:::{your-bucket-name}"
            ]
        }
    ]
}
```

4. Click 'Save' to apply the changes.

### Step 4: Integration details

Share the following details with the Drivetrain team:

1. Bucket name.
2. Folder path.
3. AWS Region
