Amazon Simple Storage Service (Amazon S3) is an object storage service that offers scalability, data availability, security, and performance. Amazon S3 provides features for data organization and configuration of access controls for your business, organization, and compliance requirements.
This TD export integration allows you to write job results from Treasure Data directly to Amazon S3.
What can you do with this Integration?
- Create buckets: Create and name a bucket that stores data.
- Storing data: Store an infinite amount of data in a bucket.
Differences between Amazon S3 Export Integration v2 and Amazon S3 Export Integration v1
Review information in the following table to understand the differences and potential advantages between v2 and v1.
|Feature||Amazon S3 v2||Amazon S3 v1|
|Server-side Encryption with Customer Master Key (CMK)|
stored in AWS Key Management Service
|Support for Quote Policy for output data format||X|
|Support Assume Role authentication method||X|
This topic includes:
Basic knowledge of Treasure Data, including the TD Toolbelt.
For AWS: the IAM User
with s3:PutObject, s3:AbortMultipartUpload permissions
with kms:Decrypt, kms:GenerateDataKey* permissions when selecting sse-kms setting
Requirements and Limitations
The default query result limit for export to S3 is 100GB. you could config part size setting up to 5000 (MB), the file limit will be about 5TB.
The default export format is CSV RFC 4180.
Output in TSV, JSONL format is also supported.
About S3 Server-Side Encryption
You can encrypt upload data with AWS S3 Server-Side Encryption. You don’t need to prepare an encryption key. Data will be encrypted at the server side with 256-bit Advanced Encryption Standard (AES-256).
Use the Server-Side Encryption bucket policy if you require server-side encryption for all objects that are stored in your bucket. When you have server-side encryption enabled, you don't have to turn on the SSE option. However, job results might fail if you have bucket policies to reject HTTP requests without encryption information.
About KMS Server-Side Encryption
You can encrypt upload data with Amazon S3-managed encryption keys (SSE-S3).
When you enable AWS KMS for server-side encryption in Amazon S3
if not input KMS key id, it will create/using the default KMS key
if input KMS Key ID, you must choose symmetric CMK, not asymmetric CMKs
The AWS KMS CMK must be in the same Region as the bucket
About File Formats for S3
For both CSV, TSV, JSONL formats, the following table lists options you can use to customize the final format of the files written into the destination:
Main setting to specify the file format
csv (Use ‘tsv’ to select the TSV format)
|Use JSONL to select JSONL format|
Use to specify the delimiter character
|quote policy||Use to determine field type to quote||MINIMAL||MINIMAL||parameter ignored|
Use to specify the quote character
not available for TSV format
“ (double quote)
Specifies the character used to escape other special characters
not available for TSV format
“ (double quote)
Use to specify how a ‘null’ value is displayed
\N (backslash capital n)
Use to specify the EOL (End-Of-Line) representation
Can be used to suppress the column header
column header printed. Use ‘false’ to suppress
the column header printed. Use ‘false’ to suppress
The following example shows a default sample output in CSV format when no customization is requested:
When the format=tsv, delimiter=|, and null=NULL options are specified. The output changes to:
When the format=jsonl. The output changes to:
Use the TD Console to Create a Connection
In Treasure Data, you must create and configure the data connection prior to running your query. As part of the data connection, you provide authentication to access the integration.
Create a New Authentication
1. Open TD Console.
2. Navigate to Integrations Hub > Catalog.
3. Search for S3 and select AmazonS3.
4. Select Create Authentication.
5. Type the credentials to authenticate:
When specified will override region setting
|Access Key ID||AWS S3 issued|
|Secret Access Key||AWS S3 issued|
Create authentication with the assume_role authentication method
- Create a new authentication with the assume_role authentication method
- Create your AWS IAM role
6. Select Continue.
7. Type a name for your connection.
8. Select Done.
Define your Query
- Complete the instructions in Creating a Destination Integration.
Navigate to Data Workbench > Queries.
Select a query for which you would like to export data.
Run the query to validate the result set.
Select Export Results.
- Select an existing integration authentication.
- Define any additional Export Results details. In your export integration content review the integration parameters.
For example, your Export Results screen might be different, or you might not have additional details to fill out:
- Select Done.
- Run your query
- Validate that your data moved to the destination you specified.
Integration Export Parameters for S3
|Parameter||Data Type||Required?||Supported in V1?||Description|
|Server-side Encryption||String||yes, only sse-s3|
|Server-side Encryption Algorithm||String||yes|
|KMS Key ID||String||no||Symmetric AWS KMS Key Id, if not input KMS key id, it will create/using the default KMS key|
Provide the S3 bucket name (Ex. your_bucket_name)
|Path||String||yes||yes||Specify s3 filename (object key), include an extension (Ex. test.csv)|
|Format||String||yes||Format of the exported file: csv, tsv, jsonl|
|Compression||String||yes||The compression format of the exported files (Ex. None or gz)|
|Header||Boolean||yes||Include header in the exported file|
|Delimiter||String||yes||Use to specify the delimiter character (Ex, (comma))|
|String for NULL values||String||yes||Placed holder to insert for null values (Ex. Empty String)|
|End-of-line character||String||yes||Specify the EOL(End-Of-Line) representation (Ex. CRLF, LF)|
|Quote Policy||String||no||Use to determine field type to quote. Support values:|
Default value: MINIMAL
|Quote character (Optional)||Char||yes||The character used for quotes in the exported file(Ex. "). Only quote those fields which contain delimiter, quote, or any of the characters in lineterminator. If the input is more than 1 character, the default value will be used|
The escape character is used in the exported file. If the input is more than 1 character, the default value will be used
|Part Size (MB) (Optional)||Integer||no|
The part size in multipart upload
Default 10, min 5, max 5000
(Optional) Schedule the Query
You can use Scheduled Jobs with Result Export to periodically write the output result to a target destination that you specify.
1. Navigate to Data Workbench > Queries.
2. Create a new query or select an existing query.
3. Next to Schedule, select None.
4. In the drop-down, select one of the following schedule options.
Review Custom cron... details.
|@daily (midnight)||Run once a day at midnight (00:00 am) in the specified time zone.|
|@hourly (:00)||Run every hour at 00 minutes.|
Custom cron... Details
Run once an hour
Run once a day at midnight
Run once a month at midnight on the morning of the first day of the month
Create a job that has no scheduled run time.
The following named entries can be used:
Day of Week: sun, mon, tue, wed, thu, fri, sat
Month: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec
A single space is required between each field. The values for each field can be composed of:
|Field Value||Example||Example Description|
a single value, within the limits displayed above for each field.
|configures the schedule to run at midnight (00:00) on the first day of each month.|
|a range ||configures the schedule to run at midnight (00:00) on the first 10 days of each month.|
|a list of comma-separated values ||configures the schedule to run at midnight (00:00) every 1st, 11th, and 21st day of each month.|
|a periodicity indicator ||configures the schedule to run on the 1st of every month, every 2 hours starting at 00:30. |
|a comma-separated list of any of the above except the ||configures the schedule to run at midnight (00:00) every 5th, 10th, 20th, and 25th day of each month.|
5. (Optional) If you enabled the Delay execution, you can delay the start time of a query.
Execute the Query
Save the query with a name and run, or just run the query. Upon successful completion of the query, the query result is automatically imported to the specified container destination.
Scheduled jobs that continuously fail due to configuration errors may be disabled on the system side after several notifications.
(Optional) Configure Export Results in Workflow
Within Treasure Workflow, you can specify the use of this data connector to export data.
Learn more at Exporting Data with Parameters.
S3 (v2) Configuration Keys
csv, tsv, jsonl
|delimiter||String||default , \t ||
|null_value||String||default, empty, \\N, NULL, null|
|newline||String||CR, LF, CRLF|
|quote_policy||String||ALL, MINIMAL, NONE|
Example Workflow for S3 (v2)
(Optional) Configure Export Results in CLI
To output the result of a single query to an S3 buck add the --result option to the td query command. After the job is finished, the results are written into your s3
You can specify detailed settings to export your S3 via --result parameter.
Only support create authentication with Assume Role using the console, creating through TD CLI will result in an error