Perspectium DataSync Agents support the replication of data from your app to an Amazon Web Services (AWS) S3 bucket, or an AWS S3 Subscriber Agent. By configuring your AWS S3 Subscriber Agent, data from your app can be replicated and then saved as either .json or .xml file(s) in your AWS S3 bucket.
Prerequisites
First, you will need to set up the Perspectium DataSync Agent.
You should also stop running your DataSync Agent before making any Agent configuration changes.
Procedure
To configure your DataSync Agent to run as an AWS S3 Subscriber Agent, follow these steps:
Add the following .jar files to your DataSync Agent's extlib directory:
joda-time (v2.10.3)
aws-java-sdk-core (v1.11.729)
aws-java-sdk-kms (v1.11.729)
aws-java-sdk-s3 (v1.11.729)
While newer versions may work, they have not been tested and it is suggested you use the versions listed above which have been confirmed to work with this release.
Navigate to the directory where you saved your agent.xml file when installing your DataSync Agent.
Open your agent.xml file in a text editing application and delete the following directives nested within the <task> tag:
- <database_type>
- <database_server>
- <database_port>
- <database_user>
- <database_password>
- <database_parms>
- <database_column_max_size>
- <database>
Locate the <task_name> and <handler> directives nested within the <task> tag and update their values as follows:
Directive | Update value to... |
---|---|
<task_name> | s3_agent_subscribe |
<handler> | com.perspectium.replicator.file.S3Subscriber |
Within the <task> tag, nest the following directives for how you want to configure saving to AWS S3. You can configure to save one record per file, multiple records per file and all records in one file. See the Sample Configurations below for a sample configuration for each option.
Directive | Description | Required? |
---|---|---|
<access_key> | Access Key associated with your AWS account NOTE: Cannot be used with <use_instance_credentials/> directive | Yes, ONLY when the DataSync Agent is not installed on an EC2 instance. |
<secret_access_key> | Secret Access Key associated with your AWS account NOTE: Cannot be used with <use_instance_credentials/> directive | Yes, ONLY when the DataSync Agent is not installed on an EC2 instance. |
<use_instance_credentials/> | Checks the IAM roles on an EC2 instance and uploads to the S3 bucket if the instance has the correct permissions NOTE: Cannot be used with <access_key> or <secret_access_key> directive | No |
<region> | Region that your AWS S3 bucket resides in NOTE: If a region is specified for an Agent on an EC2 instance, then the region must match the region of the EC2 instance and the region of the S3 bucket | No |
<s3_bucket> | Name of your AWS S3 bucket, including subdirectories if desired, to specify where the records will be uploaded e.g. bucketName/folder1/folder2. For example, with <s3_bucket>psp-bucket</s3_bucket> will save records into the psp-bucket S3 bucket. With <s3_bucket>psp-bucket/datasync-agent/tables/$table</s3_bucket> configured, if an incident record is being processed and uploaded to the AWS S3 bucket, then the record will be saved in the psp-bucket S3 bucket and in the /datasync-agent/tables/incident directory in that bucket, creating the directories datasync-agent, tables and incident automatically. NOTE: Adding the $table token indicates this token will be replaced by the table name of the record. | Yes |
<file_format> | Format you want to save your data records in e.g., json or xml | Yes |
<s3_bucket_encryption/> | To use AWS server-side encryption when pushing files to the S3 bucket. Configuring this option will have the Agent request S3 to encrypt the data at rest using S3's built-in functionality. | No |
Additional directives supported:
Directive | Example | Use | Required? |
<file_prefix> | <file_prefix>record_</file_prefix> NOTE: Use the value $table_$d{yyyyMMdd}_ to set a dynamic file name where table will be the record's table and yyyyMMdd will be the date format i.e. problem_20200530_00b470b7-901c-4447-9316-023a265d632f.json where 00b470b7-901c-4447-9316-023a265d632f is the <randomized_unique_identifier> value to ensure there are no file naming collisions when saving to the S3 bucket You can modify yyyyMMdd with another date format of your choice. For example, hourly will need a yyyyMMddHH value. For other date format, see Date Format. <file_prefix>$table_$d{yyyyMMdd}_</file_prefix> | A prefix for the file name of each record. If this directive is not specified, “psp.replicator.” will be used as the prefix. This configuration is used for saving one record per file as well as multiple records per file. | No |
<file_suffix> | <file_suffix>.xml</file_suffix> | A suffix for the file name of each record. If this directive is not specified, “.json” will be used as the suffix. | No |
Save the changes you've made to your agent.xml and close the file.
After configuring your agent.xml file to support your AWS S3 Subscriber Agent, start running your DataSync Agent again.
Sample Configurations
You have three different ways of saving files that are then pushed to AWS S3 buckets. Below is a sample configurations for each along with details. In all examples, files will be named with a <randomized_unique_identifier> value (such as 00b470b7-901c-4447-9316-023a265d632f) to ensure there are no file naming collisions when saving to the S3 bucket.
One Record Per File
In this setup, each record is saved into its own file that is then pushed into the AWS S3 bucket.
<?xml version="1.0" encoding="UTF-8"?> <config> <agent> <share /> <subscribe> <task> <task_name>s3_agent_subscribe</task_name> <message_connection password="password" user="user">https://<customer>.perspectium.net</message_connection> <instance_connection password="password" user="user">https://<instance>.service-now.com</instance_connection> <handler>com.perspectium.replicator.file.S3Subscriber</handler> <decryption_key>My special key for decrypting the data</decryption_key> <access_key>AccessKey</access_key> <secret_access_key>SecretAccessKey</secret_access_key> <region>us-west-2</region> <s3_bucket>examples3bucket</s3_bucket> <file_format>json</file_format> <file_prefix>record_</file_prefix> <file_suffix>.json</file_suffix> <one_record_per_file/> </task> </subscribe> <polling_interval>40</polling_interval> </agent> </config>
In this case, each record will be saved in its own file named <file_prefix><randomized_unique_identifier><file_suffix>. Using the above configuration example, a file would be named record_00b470b7-901c-4447-9316-023a265d632f.xml.
Multiple Records Per File
In this setup, multiple records are saved into a file before a new file is created. This way we're creating batches of records in one file so we're not creating too many files while also not creating files that are too large as well. This option also allows you to specify multiple records of one table into their own files so each file can only contain multiple records of the same table i.e. one file only contains incident records, one file only contains ticket records, etc.
<?xml version="1.0" encoding="UTF-8"?> <config> <agent> <share /> <subscribe> <task> <task_name>s3_agent_subscribe</task_name> <message_connection password="password" user="user">https://<customer>.perspectium.net</message_connection> <instance_connection password="password" user="user">https://<instance>.service-now.com</instance_connection> <handler>com.perspectium.replicator.file.S3Subscriber</handler> <decryption_key>My special key for decrypting the data</decryption_key> <access_key>AccessKey</access_key> <secret_access_key>SecretAccessKey</secret_access_key> <region>us-west-2</region> <s3_bucket>examples3bucket</s3_bucket> <file_format>json</file_format> <file_prefix>$table_$d{yyyyMMddHH_}</file_prefix> <file_suffix>.json</file_suffix> <buffered_writes>300</buffered_writes> </task> </subscribe> <polling_interval>40</polling_interval> </agent> </config>
In the above example, we specify the files to be named <file_prefix><randomized_unique_identifier><file_suffix> which in this case will be based on the table and a datetime value that is today's date with the current hour, while saving up to 300 records per file using the <buffered_writes> configuration. Once the <buffered_writes> maximum has been reached, a new file at that datetime with a new randomized_unique identifier. For example, if incident records are shared, this will result in files named:
incident_2025011322_4d747761-62d0-49ae-87fc-4998e259727d.json
incident_2025011322_5af73396-5bd9-49e1-8ac5-da8fb8a12047.json
incident_2025011323_6445a8ab-f694-482c-a315-01192cc84d7a.json
One File for All Records
In this setup, when the Agent receives a batch of records from MBS, all the records, regardless of which ServiceNow table it belongs to, will be saved into one file that is then pushed to AWS S3. This process is repeated each time the Agent receives a new batch of records from MBS (which is controlled by your <polling_interval> configuration for how often the Agent polls MBS for another batch of records).
<?xml version="1.0" encoding="UTF-8"?> <config> <agent> <share /> <subscribe> <task> <task_name>s3_agent_subscribe</task_name> <message_connection password="password" user="user">https://mesh.perspectium.net</message_connection> <instance_connection password="password" user="user">https://myinstance.service-now.com</instance_connection> <handler>com.perspectium.replicator.file.S3Subscriber</handler> <decryption_key>My special key for decrypting the data</decryption_key> <access_key>AccessKey</access_key> <secret_access_key>SecretAccessKey</secret_access_key> <region>us-west-2</region> <s3_bucket>examples3bucket</s3_bucket> <file_format>json</file_format> </task> </subscribe> <polling_interval>40</polling_interval> </agent> </config>
The files saved in the AWS S3 bucket will be named <task_name>.<randomized_unique_identifier>.<file_format>. Using the above configuration example, a file would be named s3_agent_subscribe.00b470b7-901c-4447-9316-023a265d632f.json and then this file would be pushed into your AWS S3 bucket.