# STACKIT FOCUS export

STACKIT writes your cost as FOCUS reports into an Object Storage bucket of yours, and Costfluent
reads that bucket as a [FOCUS bucket](/connect/focus-bucket). Costfluent has no other connection
for STACKIT, so this is how its cost arrives.

## Before you start

- The Costfluent access under [Prerequisites](/connect/focus-bucket#prerequisites).
- The Owner or Cost Management Cost Admin role in STACKIT, on the customer account.
- A STACKIT project for the reports alone, with Object Storage enabled and one bucket. STACKIT
  recommends it, and the read-only key needs it: a key reaches every bucket of its project.

## Turn on the export

<Stepper>

1. On the organizations overview page, select "Billing", then "FOCUS Export", and select
   "Create schedule".
2. Under the general information, choose "Month to date" as the "Type" and "Daily" as the
   "Frequency", and enter an "Export name" of at most 40 letters, digits and `_ + & -`.
3. Under the destination, choose the "Project" and the "Object Storage bucket", and enter an
   "Object Storage path" such as `focus`. Note it: it is the **Prefix** in Costfluent.
4. Leave "File Overwrite" off. The folders STACKIT documents, which Costfluent reads, are those of a
   daily report without overwriting.
5. Select "Create". STACKIT creates a service account, a credentials group whose name starts with
   `focus-` and an access key in the project, and writes the reports with them.

</Stepper>

:::caution
Never use the export's own `focus-*` credentials for Costfluent, and delete none of what STACKIT
created. STACKIT says the schedule then fails, and a failed schedule has to be created again.
:::

## Create a read-only key

A key of a STACKIT project may read and write every bucket of that project. Create a separate
credentials group with an access key that may only read the export's bucket. The group is
Costfluent's alone, and a bucket policy denies it every write.

<Stepper>

1. In the project, open "Object Storage - Credentials & Groups" and create a credentials group for
   Costfluent, or with the STACKIT CLI:

   ```bash
   stackit object-storage credentials-group create --name costfluent-read --project-id <project ID>
   ```

2. Open the group's "Credentials" tab, select "Create credentials", and copy the "Access key ID" and
   the "Secret access key", which STACKIT shows once. With the CLI:

   ```bash
   stackit object-storage credentials create --credentials-group-id <group ID> --project-id <project ID>
   ```

3. Find the group's URN, such as `urn:sgws:identity::<account>:group/<group>`, in the URN column of
   `stackit object-storage credentials-group list --project-id <project ID>`.
4. With credentials of another group of the project, never the `focus-*` one, put this policy on
   the bucket, with the group's URN and your bucket's name:

   ```json
   {
     "Statement": [
       {
         "Sid": "costfluent-read-only",
         "Effect": "Deny",
         "Principal": { "AWS": "<group URN>" },
         "Action": ["s3:Put*", "s3:Delete*", "s3:Create*", "s3:AbortMultipartUpload"],
         "Resource": ["arn:aws:s3:::<bucket>", "arn:aws:s3:::<bucket>/*"]
       }
     ]
   }
   ```

   With the AWS CLI, for a bucket in `eu01`:

   ```bash
   aws s3api put-bucket-policy --bucket <bucket> --policy file://policy.json --endpoint-url https://object.storage.eu01.onstackit.cloud
   ```

</Stepper>

The policy holds for this bucket. Keep the project for the reports alone, because the key still
reaches any other bucket in it.

## Connect in Costfluent

<Stepper>

1. Open **Settings**, then **Integrations**, select **FOCUS bucket**, open the **Connect** tab and
   select **Add access key**.
2. Choose STACKIT as the **Provider**, and enter the bucket's region in **Region**: `eu01` or `eu02`.
3. Enter the bucket's name in **Bucket**, and the "Object Storage path" in **Prefix**: the folder
   above the schedule's own folder, which STACKIT names with an ID such as
   `f51ce5b9-653c-43e8-90e3-d8bad69734df`.
4. Enter the read-only credentials in **Access key ID** and **Secret access key**.
5. Select **Test connection** to see each check, or **Connect** to save.

</Stepper>

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

## How it behaves

- STACKIT writes the first report at 12:00 UTC on the day after you create the schedule, then one
  every day at 12:00 UTC. Each report is the billing period so far, in FOCUS 1.1 or 1.2, as
  gzip-compressed CSV files of up to a million rows each, in a new folder per report.
- Costfluent reads the newest report of each billing period in each sync's window
  ([Data and freshness](/connect/focus-bucket#data-and-freshness)).
- Around the 5th of the next month, STACKIT recreates the month's last report with its invoice IDs
  and credits, and Costfluent collects that month again
  ([Data and freshness](/connect/focus-bucket#data-and-freshness)).

## Troubleshooting

- **No cost arrives on the first day.** STACKIT writes the first report at 12:00 UTC the next day.
- **The schedule has failed.** A part STACKIT created for it, the service account, the `focus-`
  credentials group or its key, was deleted. STACKIT cannot reactivate the schedule: create a new
  one.
- Every other message: [Troubleshooting](/connect/focus-bucket#troubleshooting) on the FOCUS bucket
  page.

## Related

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