SELECT query to Amazon S3 in your specified file format. You can specify the output file format, compression type, and other options to control how the data is written, such as file name conventions and whether to overwrite existing files. Use COPY TO for backing up query results or integrating Firebolt with other data processing tools.
Syntax
The
WITH keyword before the options list is optional. Additionally, you can use either = or a space to separate option names from their values. For example, both TYPE = JSON and TYPE JSON are valid.Parameters
Credentials
Firebolt needs permissions to write query results to the specified Amazon S3 URL. You can specify IAM credentials using the AWS access keys, and the specified credentials must be associated with a user with permissions to write objects to the bucket.Credentials for Amazon S3
Specify access key credentials using the syntax shown below.For role-based AWS access you can additionally set an external ID. An external ID is a value you choose and control that AWS checks when Firebolt assumes your role, adding a second condition on top of your account’s unique IAM principal. Configuring one is a recommended best practice. See IAM roles.
Least privileged permissions
The example AWS IAM policy statement below demonstrates the minimum actions that must be allowed for Firebolt to write query files to an example Amazon S3 URL. A permissions policy that allows at least these actions for the<s3_url> that you specify in the COPY TO statement must be attached to the user or role specified in the CREDENTIALS clause.
Using Location Objects
Location objects provide a secure and reusable way to specify Amazon S3 destinations for your data exports. This is the recommended approach as it:- Centralizes credential management
- Eliminates the need to specify credentials in each COPY statement
- Provides better security through role-based access control
- Simplifies maintenance and updates
Example with Location Object
my_export_location contains the Amazon S3 URL and credentials, making the statement cleaner and more secure.
Examples
- COPY TO with location object
- COPY TO with defaults and role ARN
- COPY TO with single file and AWS access keys
- COPY TO with custom file name prefix and ARN with external ID
- COPY TO with custom file name and overwrite set to TRUE
COPY TO with location object
This example demonstrates the recommended approach using a location object. The location object contains the Amazon S3 URL and credentials, making the statement more secure and maintainable.COPY TO with defaults and role ARN
The example below shows aCOPY TO statement with minimal parameters that specifies an AWS_ROLE_ARN together with a recommended AWS_ROLE_EXTERNAL_ID. Because TYPE is omitted, the file or files will be written in CSV format, and because COMPRESSION is omitted, they are compressed using GZIP (*.csv.gz).
AWS_ROLE_EXTERNAL_ID is optional; omit it to assume the role without an external ID.
Firebolt assigns a UUID formatted query ID, to the query at runtime. The compressed output is 40 MB, exceeding the default of 16 MB, so Firebolt writes 4 files as shown below.
COPY TO with single file and AWS access keys
The example below exports a single, uncompressed JSON file with the same name as the query ID. If the file to be written exceeds the specifiedMAX_FILE_SIZE (5 GB), an error occurs. AWS access keys are specified for credentials.
COPY TO with custom file name prefix and ARN with external ID
In the example below, becauseFILE_NAME_PREFIX parameter is specified, Firebolt adds a string to the query ID to form file names. The IAM role specified for CREDENTIALS also has an external ID configured in AWS, so the ID is specified.
16B90E96716236D6 at runtime and writes files as shown below.
COPY TO with custom file name and overwrite set to TRUE
In the example below,INCLUDE_QUERY_ID_IN_FILE_NAME is set to FALSE and a FILE_NAME_PREFIX is specified. In this case, Firebolt writes files using only the specified FILE_NAME_PREFIX as the file name. In addition, SINGLE_FILE and OVERWRITE_EXISTING_FILES are set to TRUE so that the Amazon S3 URL always contains a single file with the latest query results.