# AWS FOCUS export

AWS Data Exports can write your cost as FOCUS files into an S3 bucket of yours, and Costfluent reads
that bucket as a [FOCUS bucket](/connect/focus-bucket). It is the optional second path:
[Connect AWS](/connect/aws) is the recommended one, through a role Costfluent assumes, with no
long-lived key to store. Connect one of the two, because each imports the same cost and the second
counts it twice.

## Before you start

- The Costfluent access under [Prerequisites](/connect/focus-bucket#prerequisites).
- An AWS account that may create a data export and an IAM user. A management account's export holds
  every member account; a member account's holds only that account.
- An S3 bucket for the export, or a name for a new one.

## Turn on the export

<Stepper>

1. In the Billing and Cost Management console, choose "Data Exports", then "Create export".
2. Under "Export type", choose "Standard data export", and enter an "Export name" of letters, digits,
   hyphens and underscores.
3. Under "Data table configurations", choose the table "FOCUS 1.2 with AWS columns".
4. Under "Data table delivery options", choose "gzip - text/csv" or "Parquet - Parquet" as the
   compression type and file format, and "Create new data export file" as the file versioning.
5. Under "Data export storage settings", choose "Configure", select or create the bucket, and
   acknowledge the bucket policy Data Exports writes to it.
6. Enter an "S3 path prefix", such as `focus`, then choose "Create".

</Stepper>

"Create new data export file" writes each delivery into a folder of its own, so Costfluent always
reads one whole delivery. With "Overwrite existing data export file", a delivery replaces the
previous one's files in place, and a sync in the middle of it could read files of both.

## Create a read-only key

Costfluent reads the bucket with an IAM user whose policy allows only listing the bucket and reading
its objects. With the AWS CLI, save this policy as `policy.json` with your bucket's name:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    { "Effect": "Allow", "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::<bucket>" },
    { "Effect": "Allow", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::<bucket>/*" }
  ]
}
```

Then create the user, give it the policy, and create its access key:

```bash
aws iam create-user --user-name costfluent-focus-read
aws iam put-user-policy --user-name costfluent-focus-read --policy-name costfluent-focus-read --policy-document file://policy.json
aws iam create-access-key --user-name costfluent-focus-read
```

The last command prints the `AccessKeyId` and the `SecretAccessKey`, which AWS shows once.

## Connect in Costfluent

<Stepper>

1. Open **Settings**, then **Integrations**, select **FOCUS bucket**, open the **Connect** tab and
   select **Add access key**.
2. Choose **Other S3-compatible storage** as the **Provider**. Enter the bucket's regional endpoint
   in **Endpoint** and its region in **Region**, such as `https://s3.eu-central-1.amazonaws.com` and
   `eu-central-1` for a bucket in eu-central-1.
3. Enter the bucket's name in **Bucket**, and in **Prefix** the S3 path prefix, the export's name and
   `data`, such as `focus/<export name>/data`.
4. Enter the `AccessKeyId` in **Access key ID** and the `SecretAccessKey` in **Secret access key**.
5. Select **Test connection** to see each check, or **Connect** to save.

</Stepper>

You can connect before the first delivery: Costfluent accepts a prefix that holds no file yet.

## How it behaves

- Data Exports refreshes the export at least once a day, until the billing period ends, and may
  update a closed month within the first two weeks after it.
- Each delivery holds the month so far, in a folder of its own below the month's
  `BILLING_PERIOD=YYYY-MM` folder. Costfluent reads the newest delivery of each month in each sync's window
  ([Data and freshness](/connect/focus-bucket#data-and-freshness)).
- Every delivery stays in the bucket, so it grows by one copy of the month so far with each
  delivery.
- Data Exports writes its manifests under `metadata`, beside `data`; with the prefix ending in
  `data`, Costfluent never sees them.

## Troubleshooting

- **The endpoint "is not the endpoint of the bucket".** The **Endpoint** is not the bucket's
  region's, such as `https://s3.us-east-1.amazonaws.com` for a bucket in eu-central-1. Enter the
  endpoint and the region of the bucket's own region.
- **AWS cost is counted twice.** An [AWS](/connect/aws) connection imports the same cost. Remove one
  of the two connections.
- Every other message: [Troubleshooting](/connect/focus-bucket#troubleshooting) on the FOCUS bucket
  page.

## Related

- [Connect a FOCUS bucket](/connect/focus-bucket)
- [Connect AWS](/connect/aws)
- [Manage connections](/connect/manage-connections)
