

# Exporting S3 Storage Lens metrics to S3 Tables

You can configure Amazon S3 Storage Lens for Tables to export your storage analytics and insights to S3 Tables. When you enable S3 Tables export, Amazon S3 stores your metrics in read-only Apache Iceberg tables. These tables are in the AWS-managed `aws-s3` table bucket. You can query them using SQL with AWS analytics services like Amazon Athena, Amazon Redshift, and Amazon EMR.

**Note**  
There is no additional charge for exporting S3 Storage Lens metrics to AWS-managed S3 Tables. Standard charges apply for table storage, table management, and requests on the tables. For more information, see [Amazon S3 pricing](https://aws.amazon.com/s3/pricing). 

## Enable S3 Tables export using the console
<a name="s3-tables-storage-lens-s3-tables-export-console"></a>

1. Sign in to the AWS Management Console and open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

1. In the left navigation pane, choose **Storage Lens**, and then choose the **Table buckets** tab.

1. In the list of dashboards, choose the dashboard that you want to edit, and then choose **Edit**.

1. In the **Metrics export and publishing** step, turn on the daily data export and choose the **Table bucket** destination type.

1. Proceed through the remaining steps, and then on the **Review and create** step, choose **Submit**.

**Note**  
After you enable S3 Tables export, it can take up to 48 hours for the first data to be available in the tables.

**Note**  
You can enable or disable export to S3 Tables by using the Amazon S3 console, Amazon S3 API, the AWS CLI, or AWS SDKs.

**Note**  
By default, records in your S3 tables don't expire. To help minimize storage costs for your tables, you can enable and configure record expiration for the tables. With this option, Amazon S3 automatically removes records from a table when the records expire. For more information, see [Record expiration for tables](s3-tables-record-expiration.md). 

## Enable S3 Tables export using the AWS CLI
<a name="s3-tables-storage-lens-s3-tables-export-cli"></a>

**Note**  
Before running the following commands, make sure that you have an up to date CLI version. See [Installing or updating to the latest version of the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html). 

The following example enables S3 Tables export for an Amazon S3 Storage Lens for Tables configuration by using the AWS CLI. To use this example, replace the {{user input placeholders}} with your own information.

**Note**  
The `put-storage-lens-configuration` operation replaces the entire configuration. Include all of the dashboard's existing settings, such as its scope and CloudWatch publishing, along with the export destination. To get the current configuration, use `get-storage-lens-configuration`.

**Note**  
The `advancedMetricsCategories` are optional. The free tier can also export to AWS-managed S3 Tables; omit `advancedMetricsCategories` to export free tier metrics only.

```
aws s3tables put-storage-lens-configuration --storage-lens-id={{your-configuration-id}} --storage-lens-configuration '{
   "id":"{{your-configuration-id}}",
   "isEnabled":true,
   "advancedMetricsCategories":[
      "StorageMetrics",
      "ActivityMetrics",
      "MaintenanceMetrics"
   ],
   "dataExport":{
      "storageLensTableDestination":{
         "isEnabled":true
      }
   }
}'
```

## Enable S3 Tables export using the AWS SDKs
<a name="s3-tables-storage-lens-s3-tables-export-sdk"></a>

The following example enables S3 Tables export for an Amazon S3 Storage Lens for Tables configuration by using the AWS SDK for Python (Boto3). To use this example, replace the {{user input placeholders}} with your own information.

```python
import boto3

s3tables = boto3.client('s3tables')

response = s3tables.put_storage_lens_configuration(
    storageLensId='{{your-configuration-id}}',
    storageLensConfiguration={
        'id': '{{your-configuration-id}}',
        'isEnabled': True,
        'advancedMetricsCategories': [
            'StorageMetrics',
            'ActivityMetrics',
            'MaintenanceMetrics'
        ],
        'dataExport': {
            'storageLensTableDestination': {
                'isEnabled': True
            }
        }
    }
)
```

For more information about using the AWS SDKs, see [AWS SDKs and tools](https://aws.amazon.com/developer/tools/). 

## Next steps
<a name="s3-tables-storage-lens-s3-tables-export-next-steps"></a>

After enabling S3 Tables export, you can:
+ Learn about [Table naming for S3 Storage Lens export to S3 Tables](s3-tables-storage-lens-s3-tables-naming.md) 
+ Learn about [Amazon S3 Storage Lens for Tables export column schemas](s3-tables-storage-lens-s3-tables-schemas.md) 