|
1 | 1 | # Working with S3 buckets ({{objstorage-full-name}})
|
2 | 2 |
|
| 3 | +To work with S3, you need to set up a data storage connection. There is a DDL for configuring such connections. Next, let's look at the SQL syntax and the management of these settings. |
| 4 | + |
| 5 | +There are two types of buckets in S3: public and private. To connect to a public bucket, use `AUTH_METHOD="NONE"`. To connect to a private bucket, use `AUTH_METHOD="AWS"`. A detailed description of `AWS` can be found [here](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-authentication-methods.html). `AUTH_METHOD="NONE"` means that no authentication is used. If `AUTH_METHOD="AWS"` is specified, several additional parameters are required: |
| 6 | + |
| 7 | +- `AWS_ACCESS_KEY_ID_SECRET_NAME` – reference to the name of the [secret](../../datamodel/secrets.md) where `AWS_ACCESS_KEY_ID` is stored. |
| 8 | +- `AWS_SECRET_ACCESS_KEY_SECRET_NAME` – reference to the name of the [secret](../../datamodel/secrets.md) where `AWS_SECRET_ACCESS_KEY` is stored. |
| 9 | +- `AWS_REGION` – region from which reading is performed, for example, `ru-central-1`. |
| 10 | + |
| 11 | +To set up a connection to a public bucket, execute the following SQL query. The query creates an external connection named `object_storage`, which points to a specific S3 bucket named `bucket`. |
| 12 | + |
| 13 | +```yql |
| 14 | +CREATE EXTERNAL DATA SOURCE object_storage WITH ( |
| 15 | + SOURCE_TYPE="ObjectStorage", |
| 16 | + LOCATION="https://object_storage_domain/bucket/", |
| 17 | + AUTH_METHOD="NONE" |
| 18 | +); |
| 19 | +``` |
| 20 | + |
| 21 | +To set up a connection to a private bucket, you need to run a few SQL queries. First, create [secrets](../../datamodel/secrets.md) containing `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. |
| 22 | + |
| 23 | +```yql |
| 24 | + CREATE OBJECT aws_access_id (TYPE SECRET) WITH (value=`<id>`); |
| 25 | + CREATE OBJECT aws_access_key (TYPE SECRET) WITH (value=`<key>`); |
| 26 | +``` |
| 27 | + |
| 28 | +The next step is to create an external connection named `object_storage`, which points to a specific S3 bucket named `bucket` and uses `AUTH_METHOD="AWS"`. The parameters `AWS_ACCESS_KEY_ID_SECRET_NAME`, `AWS_SECRET_ACCESS_KEY_SECRET_NAME`, and `AWS_REGION` are filled in for `AWS`. The values of these parameters are described above. |
| 29 | + |
| 30 | +```yql |
| 31 | +CREATE EXTERNAL DATA SOURCE object_storage WITH ( |
| 32 | + SOURCE_TYPE="ObjectStorage", |
| 33 | + LOCATION="https://object_storage_domain/bucket/", |
| 34 | + AUTH_METHOD="AWS", |
| 35 | + AWS_ACCESS_KEY_ID_SECRET_NAME="aws_access_id", |
| 36 | + AWS_SECRET_ACCESS_KEY_SECRET_NAME="aws_access_key", |
| 37 | + AWS_REGION="ru-central-1" |
| 38 | +); |
| 39 | +``` |
| 40 | + |
| 41 | +## Using an external connection to an S3 bucket {#external-data-source-settings} |
| 42 | + |
3 | 43 | When working with {{ objstorage-full-name }} using [external data sources](../../datamodel/external_data_source.md), it is convenient to perform prototyping and initial data connection setup.
|
4 | 44 |
|
5 | 45 | An example query to read data:
|
|
0 commit comments