

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 示例：以编程方式将 S3 与 Amazon Connect Customer Profiles 集成
<a name="customerprofiles-s3-integration"></a>

使用客户档案 [PutIntegration](https://docs.aws.amazon.com/customerprofiles/latest/APIReference/API_PutIntegration.html)API，您可以通过编程方式为 S3、Salesforce、Marketo 等创建集成。

在本主题中，我们将介绍如何创建同步间隔为 15 分钟（当前支持的最小值）的 S3 集成。

## 步骤 1：创建 JSON 文件
<a name="step1-cpintegration"></a>

使用以下内容创建 JSON 文件：

```
{
    "DomainName": "{{your-domain}}",
    "ObjectTypeName": "{{your-object-name}}", 
    "FlowDefinition": {
        "FlowName": "{{your-flow-name}}",
        "KmsArn": "{{the key ARN is the same as your domain's key}}",
        "Description": "Created by Customer Profiles",
        "TriggerConfig": {
            "TriggerType": "Scheduled",
            "TriggerProperties": {
                "Scheduled": {
                    "ScheduleExpression": "rate(15minutes)",
                    "DataPullMode": "Incremental",
                    "ScheduleStartTime": {{1634244800.435}},
                    "FirstExecutionFrom": {{1594166400}}
                }
            }
        },
        "SourceFlowConfig": {
            "ConnectorType":"S3",
            "SourceConnectorProperties": {
                "S3": {
                    "BucketName": "{{your-bucket}}",
                    "BucketPrefix": "{{your-prefix}}"
                }
            }
        },
        "Tasks": [
            {"TaskType":"{{Filter}}","SourceFields":["{{colA}}","{{colB}}"],"ConnectorOperator":{"{{S3}}":"{{PROJECTION}}"}},
            {"ConnectorOperator":{"{{S3}}":"{{NO_OP}}"},"DestinationField":"{{colA}}","TaskProperties":{},"SourceFields":["{{colA}}"],"TaskType":"{{Map}}"},
            {"ConnectorOperator":{"{{S3}}":"{{NO_OP}}"},"DestinationField":"{{colB}}","TaskProperties":{},"SourceFields":["{{colB}}"],"TaskType":"{{Map}}"}
        ]
    }
}
```

要使用您自己的值自定义 JSON，请遵循以下准则：
+ `FlowName`：可以是 STRING [a-zA-Z0-9][\\w\!@\#.-]\+
+ `ScheduleStartTime`：设置为当前的 `DateTime` \+ 5 分钟（采用纪元时间）。
+ `FirstExecutionFrom`：转到 S3，查看文件日期，然后使用最早日期之前的日期。
+ `Tasks`：定义 `TaskType`。在 `Sourcefields` 字段中，您必须提供该数组中 CSV 中的所有列。然后，对于该数组中的每个项目，您需要指定 `ConnectorOperator`。此示例适用于包含两个列的 CSV 文档：`colA` 和 `colB`。

## 第 2 步：调用 PutIntegration API
<a name="step2-cpintegration"></a>

使用您的值创建并自定义 JSON 文件后，调用 [PutIntegration](https://docs.aws.amazon.com/customerprofiles/latest/APIReference/API_PutIntegration.html)API，如以下示例所示：

```
aws customer-profiles put-integration --cli-input-json file:///{{put_integration_s3_cli.json}} --region {{us-west-2}}                    
```

来自 `PutIntegration` 的响应返回一个流 URI。例如：

```
{
    "DomainName": "testDomain",
    "Uri": "arn:aws:appflow:us-west-2:9999999999999:flow/Customer_Profiles_testDomain_S3_Salesforce-Account_1634244122247",
    "ObjectTypeName": "your objec type",
    "CreatedAt": "2021-10-14T13:51:57.748000-07:00",
    "LastUpdatedAt": "2021-10-14T13:51:57.748000-07:00",
    "Tags": {}
}
```

## 第 3 步：调用亚马逊 AppFlow StartFlow API
<a name="step3-cpintegration"></a>

使用流程 URI 调用亚马逊 AppFlow [StartFlow](https://docs.aws.amazon.com/appflow/1.0/APIReference/API_StartFlow.html)API。例如：

```
aws appflow start-flow —flow-name {{uri}} --region {{us-west-2}}
```