Amazon Ads is an advertising service that enables users to promote their products and services on Amazon's platforms.
The Amazon Ads Export integration supports TD users as they manage their audience and audience records on Amazon Ads platforms like Amazon Marketing Cloud (AMC) and Amazon Demand-Side Platform (DSP).
- Basic Knowledge of Treasure Data
- Basic knowledge of the Amazon Ad platforms AMC and DSP
- The Audience ID used in the Amazon Ads API is not the Audience ID displayed under DSP Advertiser account. The Audience ID that you need for the API is displayed when a new audience is created, and it should stored in a secure location.
If your security policy requires IP whitelisting, you must add Treasure Data's IP addresses to your allowlist to ensure a successful connection.
Please find the complete list of static IP addresses, organized by region, at the following link:
https://api-docs.treasuredata.com/en/overview/ip-addresses-integrations-result-workers/
In Treasure Data, you must create and configure the data connection before running your query. As part of the data connection, you provide authentication to access the integration.
Your first step is to create a new authentication with a set of credentials.
- Select Integrations Hub.
- Select Catalog.
3. Search for your Amazon Ads in the Catalog; hover your mouse over the icon and select Create Authentication.


The New Authentication modal displays. 4. Below the OAuth connection field, select the Click here link. 5. Log in to your Amazon account to approve OAuth access. 6. On the New Authentication modal, provide this information and select Continue. 7. Enter a name for the authentication, and select Done.
If you want to use this authentication with TD APIs or with the TD Toolbelt, you will need to get it's Authentication ID. To get the Authentication ID:
- Navigate to Integrations Hub > Authentications.
- Select the integration you want to use. The Edit Authentication modal displays.
- In the browser address bar, at the end of the URL, note the Authentication ID. In this example the ID is 2881.

- Navigate to Data Workbench > Queries.

- Select New Query.
- From the table drop-down menu, select the database you want to query.
- Enter your query.
Here is a sample query:
SELECT
usr_firstname AS firstname,
usr_address AS address,
usr_phone AS phone,
usr_city AS city,
usr_state AS state,
usr_postalcode AS postal,
usr_email AS email, -- required
usr_lastname AS lastname,
usr_country AS countrycode,
ext_id AS externaluserid -- required
FROM
mytableHere are the required fields for the query:
| Field | Required | Hash Required |
|---|---|---|
| firstname | Yes | |
| address | Yes | |
| phone | Yes | |
| city | Yes | |
| state | Yes | |
| postal | Yes | |
| Yes | Yes | |
| lastname | Yes | |
| countrycode | ||
| externalUserId | Yes |
There are two ways to export data to Amazon Ads:
- Create a new audience
- Update existing audience
This is an example of how to create an audience on AMC and DSP and then add users to that audience.
- Using the TD Console, perform steps 1-4 from the "Define your Query" section above.
- Select Export Results.
- Select the integration you created for Amazon Ads.
The Export Results modal displays.
4. In the Action field, ensure that Create is selected. 5. Enter your information into the remaining fields.
| Field | Description | Note |
|---|---|---|
| Audience Fee | Currency and cost per impression (CPM). Required. Format: currrency:cpm in cents Example: USD:1 | Currency should align with the marketplace of the advertiser. |
| Time to live | Specify time the audience time to live in seconds.Required. | Value needs to be greater than 0 and less than 34300800.Default: 34300800 |
| Country code | Specify country codes where the audience data collected from. Required. | See full list of ISO 3166-2 country codes. |
| Wait for next status | Select the "Wait for upload next status" check box, and then, in the "Max waiting time" field specify in minutes how long the job should wait for Amazon services to signal the upload status. Optional. |
- Select Done.
Example Result
************* REPORT *************2024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): Total records: 382024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): Total batches: 12024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): Total skipped records: 02024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): ************* UPLOAD STATUS
*************2024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): Total completed batches: 1/12024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): Total uploaded records but invalid: 02024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): ************* AUDIENCE INFO *************
2024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): Audience ID: 361054992504331xxx2024-05-29 04:40:12.081 +0000 [INFO] (0001:transaction): {done: 1 / 1, running: 0}2024-05-29 04:40:12.082 +0000 [INFO] (0001:transaction): Incremental job, setting last_path to [job_2167618832_result]2024-05-29 04:40:12.280 +0000 [INFO] (pool-10-thread-1): Saving all buffers2024-05-29 04:40:12.280 +0000 [INFO] (pool-10-thread-1): Closing buffers2024-05-29 04:40:14.281 +0000 [INFO] (main): Stopped sending metricsAs AudienceID is only returned during the audience creation process, you will need to securely store the ID for later use. The Audience ID can be found at the end of job logs.
Tip: If the audience has been created under "AMC and DSP" and the wish is continuously upload new records to that audience. You can schedule the job in this use case to run repeatedly. No need any modifications. Otherwise, follow next use case. |
This is an example of how to update an audience on AMC and DSP.
Rather than create a new query, it is easier to clone a query and make modifications to the existing configuration.
- Using the TD Console, perform steps 1-4 from the "Define your Query" section above.
- Select Export Results.
- Select the integration you created for Amazon Ads.
The Export Results modal displays.
4. In the Action field, ensure that Updateis selected. 5. Enter your information into the remaining fields.
| Field | Description | Note |
|---|---|---|
| Upload Mode | Select either - Append—appends new records to an existing audience. - Delete—deletes matching records in an existing audience. | The deletion process is handled by Amazon. |
| Target | User can select between: - AMC—audience created on AMC, and query records uploaded to AMC. - AMC and DSP— records uploaded to AMC and then synced to DSP. | |
| DSP Advertiser ID | Required when target is DSP related. | |
| Audience ID | Specify which audience to update. Required when the action is Update. | This is the ID that was returned when the audience was created. |
| Audience Description | Specify the Description of the Audience. Required. | |
| Audience Fee | Currency and cost per impression (CPM). Required. Format: currrency:cpm in cents Example: USD:1 | Currency should align with the marketplace of the advertiser. |
| Time to live | Specify time the audience time to live in seconds.Required. | Value needs to be greater than 0 and less than 34300800. Default: 34300800 |
| Country code | Specify country codes where the audience data collected from. Required. | See full list of ISO 3166-2 country codes. |
| Wait for next status | Select the "Wait for upload next status" check box, and then, in the "Max waiting time" field specify in minutes how long the job should wait for Amazon services to signal the upload status. Optional. |
- Select Done.
You can also send segment data to the target platform by creating an activation in the Audience Studio.
- Navigate to Audience Studio.
- Select a parent segment.
- Open the target segment, right-mouse click, and then select Create Activation.
- In the Details panel, enter an Activation name and configure the activation according to the previous section on Configuration Parameters.
- Customize the activation output in the Output Mapping panel.

- Attribute Columns
- Select Export All Columns to export all columns without making any changes.
- Select + Add Columns to add specific columns for the export. The Output Column Name pre-populates with the same Source column name. You can update the Output Column Name. Continue to select + Add Columnsto add new columns for your activation output.
- String Builder
- + Add string to create strings for export. Select from the following values:
- String: Choose any value; use text to create a custom value.
- Timestamp: The date and time of the export.
- Segment Id: The segment ID number.
- Segment Name: The segment name.
- Audience Id: The parent segment number.
- + Add string to create strings for export. Select from the following values:
- Set a Schedule.

- Select the values to define your schedule and optionally include email notifications.
- Select Create.
If you need to create an activation for a batch journey, review Creating a Batch Journey Activation.
You can use Scheduled Jobs with Result Export to periodically write the output result to a target destination that you specify.
Treasure Data's scheduler feature supports periodic query execution to achieve high availability.
When two specifications provide conflicting schedule specifications, the specification requesting to execute more often is followed while the other schedule specification is ignored.
For example, if the cron schedule is '0 0 1 * 1', then the 'day of month' specification and 'day of week' are discordant because the former specification requires it to run every first day of each month at midnight (00:00), while the latter specification requires it to run every Monday at midnight (00:00). The latter specification is followed.
Navigate to Data Workbench > Queries
Create a new query or select an existing query.
Next to Schedule, select None.

In the drop-down, select one of the following schedule options:

Drop-down Value Description Custom cron... 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. None No schedule.

| Cron Value | Description |
|---|---|
0 * * * * | Run once an hour. |
0 0 * * * | Run once a day at midnight. |
0 0 1 * * | 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. |
* * * * *
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +---------- month (1 - 12)
| | +--------------- day of month (1 - 31)
| +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)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. | ||
A wildcard '*' to indicate no restriction based on the field. | '0 0 1 * *' | Configures the schedule to run at midnight (00:00) on the first day of each month. |
A range '2-5', indicating the range of accepted values for the field. | '0 0 1-10 * *' | Configures the schedule to run at midnight (00:00) on the first 10 days of each month. |
A list of comma-separated values '2,3,4,5', indicating the list of accepted values for the field. | 0 0 1,11,21 * *' | Configures the schedule to run at midnight (00:00) every 1st, 11th, and 21st day of each month. |
A periodicity indicator '*/5' to express how often based on the field's valid range of values a schedule is allowed to run. | '30 */2 1 * *' | Configures the schedule to run on the 1st of every month, every 2 hours starting at 00:30. '0 0 */5 * *' configures the schedule to run at midnight (00:00) every 5 days starting on the 5th of each month. |
A comma-separated list of any of the above except the '*' wildcard is also supported '2,*/5,8-10'. | '0 0 5,*/10,25 * *' | Configures the schedule to run at midnight (00:00) every 5th, 10th, 20th, and 25th day of each month. |
- (Optional) You can delay the start time of a query by enabling the Delay execution.
Save the query with a name and run, or just run the query. Upon successful completion of the query, the query result is automatically exported to the specified destination.
Scheduled jobs that continuously fail due to configuration errors may be disabled on the system side after several notifications.
(Optional) You can delay the start time of a query by enabling the Delay execution.
Within Treasure Workflow, you can specify the use of this integration to export data.
_export:
td:
database: td.database
+amazon_ads_export_task:
td>: export_amazon_ads.sql
database: ${td.database}
result_connection: new_amazon_ads_auth
result_settings:
type: amazon_ads
td_authentication_id: td_authentication_id
amc_instance_id: amc_instance_id
amc_account_id: amc_account_id
dsp_region: NA
action: CREATE
upload_mode: APPEND
target: AMC_AND_DSP
dsp_advertiser_id: dsp_advertiser_id
external_audience_id: external_audience_id
audience_name: audience_name
time_to_live: 34300800
country_code: US
wait_until_finish: true
max_wait_time: 5You can also use the TD Toolbelt to export results to Amazon Ads using the td query command with the --result option. For additional information see TD Query.
The data specified in with the --result option is in JSON format, and the general structure is as follows.
{
"type": "amazon_ads",
"td_authentication_id": ${authentication_id_from_td_console},
"amc_instance_id": "amc_instance_id",
"amc_account_id": "amc_account_id",
"region": "NA",
"action": "CREATE",
"upload_mode": "APPEND",
"target": "AMC_AND_DSP",
"dsp_advertiser_id": "dsp_advertiser_id",
"external_audience_id": "external_audience_id",
"audience_name": "audience_name",
"time_to_live": 34300800,
"country_code": "US",
"wait_until_finish": false,
"max_wait_time": 1
}| Name | Description | Value | Default Value | Required |
|---|---|---|---|---|
| type | The destination of the export. | "amazon_ads" | Yes | |
| td_authentication_id | The authentication ID for the Amazon Ads authentication in the TD. Console. See Getting the Authentication ID for information on how to determine the value for this ID. | Yes | ||
| amc_instance_id | Your Amazon Marketing Cloud Instance ID | Yes | ||
| amc_account_id | Your AMC Account ID. If leave you leave this field blank, the integration will automatically retrieve it. | No | ||
| region | The Region that corresponds with your DSP Advertiser account. | enums ["NA", "EU", "FE"] | "NA" | Yes |
| action | Action to perform: - Create - Update | enums ["CREATE", "UPDATE"] | "CREATE" | Yes |
| upload_mode | Upload mode to perform: - Append - Delete | enums ["APPEND", "DELETE"] | "APPEND" | Yes |
| target | Audience target: AMC AMC and DSP | enums ["AMC", "AMC_AND_DSP"] | "AMC" | Yes |
| dsp_advertiser_id | The DSP Advertiser ID | Yes - if target is "AMC_AND_DSP" | ||
| external_audience_id | The user-specified external ID for their new audience | Yes - if action is "CREATE" | ||
| audience_id | Amazon Audience ID. The ID that was returned when the Audience was created. | Yes - if action is "UPDATE" | ||
| audience_name | Audience name | Yes - if action is "CREATE" | ||
| audience_description | Audience description | Must be an alphanumeric, non-null string between 0 to 1000 characters in length. | No | |
| audience_fee | Audience metadata's fee | Format: currency:cpmCents | No | |
| time_to_live | Audience metadata's time to live in seconds | Must be from 0 - 34300800 | No | |
| country_code | Country Code ISO 3166-1 alpha-2 Codes | Yes | ||
| wait_until_finish | Should the integration wait until all the export jobs are complete | true or false | No | |
| max_wait_time | How long (in minutes) the integration should wait until all the export jobs are complete. | Must be from 1 - 1380 (23 hours) | Yes, if wait_until_finish is TRUE |
This example executes a single manual export.
td query \
--database ${database_name} \
--wait "SELECT * FROM ${table_name}" \
--type presto \
--result '{"type":"amazon_ads","td_authentication_id":"${authentication_id_from_td_console}","amc_instance_id":"amc_instance_id","amc_account_id":"amc_account_id","region":"NA","action":"CREATE","upload_mode":"APPEND","target":"AMC_AND_DSP","dsp_advertiser_id":"dsp_advertiser_id","external_audience_id":"external_audience_id","audience_name":"audience_name","time_to_live":34300800,"country_code":"US","wait_until_finish":false,"max_wait_time":1}'This example executes at a scheduled time.
td sched:create \
result_to_amazon_ads '0 0 * * *' \
--database ${database_name} 'SELECT * FROM ${table_name}' \
--result '{"type":"amazon_ads","td_authentication_id":"${authentication_id_from_td_console}","amc_instance_id":"amc_instance_id","amc_account_id":"amc_account_id","region":"NA","action":"CREATE","upload_mode":"APPEND","target":"AMC_AND_DSP","dsp_advertiser_id":"dsp_advertiser_id","external_audience_id":"external_audience_id","audience_name":"audience_name","time_to_live":34300800,"country_code":"US","wait_until_finish":false,"max_wait_time":1}'See Amazon Advertiser Audience APIs for additional information.