エンドポイントを Amazon Pinpoint にインポートする - Amazon Pinpoint

サポート終了通知: 2026 年 10 月 30 日、 AWS は Amazon Pinpoint のサポートを終了します。2026 年 10 月 30 日を過ぎると、Amazon Pinpoint コンソールまたは Amazon Pinpoint のリソース (エンドポイント、セグメント、キャンペーン、ジャーニー、分析) にアクセスできなくなります。詳細については、「Amazon Pinpoint のサポート終了」を参照してください。注: SMS、音声、モバイルプッシュ、OTP、電話番号の検証に関連する APIs は、この変更の影響を受けず、 AWS エンドユーザーメッセージングでサポートされています。

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

エンドポイントを Amazon Pinpoint にインポートする

多数のエンドポイントを追加または更新するには、Amazon S3 バケットからインポートします。対象者に関するレコードが Amazon Pinpoint の外部にあり、この情報を Amazon Pinpoint プロジェクトに追加する場合は、エンドポイントをインポートすることをお勧めします。この場合は、以下のように行います。

  1. 独自の対象者データに基づくエンドポイント定義を作成します。

  2. これらのエンドポイント定義を 1 つ以上のファイルに保存し、そのファイルを Amazon S3 バケットにアップロードします。

  3. バケットからそれらをインポートして、エンドポイントを Amazon Pinpoint プロジェクトに追加します。

インポートジョブごとに最大 1 GB のデータを転送できます。各エンドポイントが 4 KB 以下の一般的なジョブでは、約 250,000 のエンドポイントをインポートできます。AWS アカウントごとに最大 2 つのインポートジョブを同時に実行できます。インポートジョブで帯域幅を追加する必要がある場合は、サービスクォータの引き上げリクエストを サポート に送信できます。詳細については、「クォータ引き上げのリクエスト」を参照してください。

開始する前に

エンドポイントをインポートする前に、AWS アカウントの次のリソースが必要です。

次の例では、Amazon S3 バケットにエンドポイント定義を追加し、Amazon Pinpoint プロジェクトにそれらのエンドポイントをインポートする方法を示します。

エンドポイント定義を含むファイル

エンドポイント定義は、CSV または改行で区切られた JSON ファイルで、Amazon S3 バケットに追加するファイルに含めることができます。エンドポイントのバッチの定義に使用する属性については、「Amazon Pinpoint API リファレンスの」の「EndpointRequest JSON スキーマ」を参照してください。

CSV

以下の例のように、CSV ファイルで定義されたエンドポイントをインポートできます。

ChannelType,Address,Location.Country,Demographic.Platform,Demographic.Make,User.UserId SMS,12065550182,CN,Android,LG,example-user-id-1 APNS,1a2b3c4d5e6f7g8h9i0j1a2b3c4d5e6f,US,iOS,Apple,example-user-id-2 EMAIL,john.stiles@example.com,US,iOS,Apple,example-user-id-2

最初の行はヘッダーで、エンドポイント属性が含まれています。入れ子の属性を指定するには、ドット表記を指定します (例: Location.Country)。

以下の行では、ヘッダーの属性ごとの値を指定することでエンドポイントを定義しています。

カンマ、または二重引用符を値に含めるには、"aaa,bbb" のように値を二重引用符で囲みます。

CSV 内の値は、改行はサポートされていません。

JSON

以下の例のように、改行で区切られた JSON ファイルで定義されたエンドポイントをインポートできます。

{"ChannelType":"SMS","Address":"12065550182","Location":{"Country":"CN"},"Demographic":{"Platform":"Android","Make":"LG"},"User":{"UserId":"example-user-id-1"}} {"ChannelType":"APNS","Address":"1a2b3c4d5e6f7g8h9i0j1a2b3c4d5e6f","Location":{"Country":"US"},"Demographic":{"Platform":"iOS","Make":"Apple"},"User":{"UserId":"example-user-id-2"}} {"ChannelType":"EMAIL","Address":"john.stiles@example.com","Location":{"Country":"US"},"Demographic":{"Platform":"iOS","Make":"Apple"},"User":{"UserId":"example-user-id-2"}}

この形式で、各行は個別のエンドポイント定義を含む完全な JSON オブジェクトです。

Import Job リクエスト

以下の例では、ローカルファイルをバケットにアップロードし、エンドポイント定義を Amazon S3 に追加する方法を示します。また、この例では、エンドポイント定義を Amazon Pinpoint プロジェクトにインポートします。

AWS CLI

Amazon Pinpoint を使用するには、AWS CLI でコマンドを実行します。

例 S3 CP コマンド

ローカルファイルを Amazon S3 バケットにアップロードするには、Amazon S3 cp コマンドを使用します。

$ aws s3 cp ./endpoints-file s3://bucket-name/prefix/

コードの説明は以下のとおりです。

  • /endpoints-file は、エンドポイント定義を含むローカルファイルへのファイルパスを表します。

  • bucket-name/prefix/ は、Amazon S3 バケットの名前です。また、バケットのオブジェクトを階層別に整理するのに役立つプレフィックスでもあります。例えば、このようなプレフィックスには pinpoint/imports/endpoints/ があります。

例 Create Import Job コマンド

Amazon S3 バケットからエンドポイント定義をインポートするには、create-import-job コマンドを使用します。

$ aws pinpoint create-import-job \ > --application-id application-id \ > --import-job-request \ > S3Url=s3://bucket-name/prefix/key,\ > RoleArn=iam-import-role-arn,\ > Format=format,\ > RegisterEndpoints=true

コードの説明は以下のとおりです。

  • application-id は、エンドポイントをインポートする Amazon Pinpoint プロジェクトの ID です。

  • bucket-name/prefix/key は、インポートする 1 つ以上のオブジェクトを含む、Amazon S3 内の場所です。この場所を表す末尾は、各オブジェクトのキー、または複数のオブジェクトを指定するプレフィックスになります。

  • iam-import-role-arn は、Amazon Pinpoint の読み込みのアクセス許可をバケットに付与する IAM ロールの Amazon リソースネーム (ARN) です。

  • 形式は、エンドポイントの定義に使用した形式に基づき、JSON または CSV になります。Amazon S3 の場所にさまざまな形式のオブジェクトが複数含まれている場合、Amazon Pinpoint では、指定した形式に一致するオブジェクトのみインポートします。

  • RegisterEndpoints は、true または false のどちらかに設定できます。true に設定すると、エンドポイント定義がインポートされるときに、インポートジョブにより、エンドポイントが Amazon Pinpoint に登録されます。

    RegisterEndpoints と DefineSegments の組み合わせ

    RegisterEndpoints

    DefineSegments 説明
    true true Amazon Pinpoint では、エンドポイントがインポートされ、エンドポイントが含まれたセグメントが作成されます。
    true false Amazon Pinpoint では、エンドポイントはインポートされますが、セグメントは作成されません。
    false true Amazon Pinpoint では、エンドポイントがインポートされ、エンドポイントが含まれたセグメントが作成されます。エンドポイントは保存されず、既存のエンドポイントが上書きされることもありません。
    false false Amazon Pinpoint では、このリクエストは拒否されます。

このレスポンスには、インポートジョブに関する詳細が含まれます。

{ "ImportJobResponse": { "CreationDate": "2018-05-24T21:26:33.995Z", "Definition": { "DefineSegment": false, "ExternalId": "463709046829", "Format": "JSON", "RegisterEndpoints": true, "RoleArn": "iam-import-role-arn", "S3Url": "s3://bucket-name/prefix/key" }, "Id": "d5ecad8e417d498389e1d5b9454d4e0c", "JobStatus": "CREATED", "Type": "IMPORT" } }

このレスポンスでは、Id 属性のジョブ ID が返ります。この ID を使用して、インポートジョブの現在のステータスを確認できます。

例 Get Import Job コマンド

インポートジョブの現在のステータスを確認するには、get-import-job コマンドを使用します。

$ aws pinpoint get-import-job \ > --application-id application-id \ > --job-id job-id

コードの説明は以下のとおりです。

  • application-id は、インポートジョブを開始した Amazon Pinpoint プロジェクトの ID です。

  • job-id は、確認中のインポートジョブの ID です。

このコマンドのレスポンスには、インポートジョブの現在の状態が含まれます。

{ "ImportJobResponse": { "ApplicationId": "application-id", "CompletedPieces": 1, "CompletionDate": "2018-05-24T21:26:45.308Z", "CreationDate": "2018-05-24T21:26:33.995Z", "Definition": { "DefineSegment": false, "ExternalId": "463709046829", "Format": "JSON", "RegisterEndpoints": true, "RoleArn": "iam-import-role-arn", "S3Url": "s3://s3-bucket-name/prefix/endpoint-definitions.json" }, "FailedPieces": 0, "Id": "job-id", "JobStatus": "COMPLETED", "TotalFailures": 0, "TotalPieces": 1, "TotalProcessed": 3, "Type": "IMPORT" } }

このレスポンスでは、JobStatus 属性のジョブステータスを返します。

AWS SDK for Java

AWS SDK for Java が提供するクライアントにより、Java アプリケーションで Amazon Pinpoint API を使用できます。

例コード

エンドポイント定義を含むファイルを Amazon S3 にアップロードするには、AmazonS3 クライアントの putObject メソッドを使用します。

エンドポイントを Amazon Pinpoint プロジェクトにインポートするには、CreateImportJobRequest オブジェクトを初期化します。次に、このオブジェクトを AmazonPinpoint クライアントの createImportJob メソッドに渡します。

package com.amazonaws.examples.pinpoint; import com.amazonaws.AmazonServiceException; import com.amazonaws.regions.Regions; import com.amazonaws.services.pinpoint.AmazonPinpoint; import com.amazonaws.services.pinpoint.AmazonPinpointClientBuilder; import com.amazonaws.services.pinpoint.model.CreateImportJobRequest; import com.amazonaws.services.pinpoint.model.CreateImportJobResult; import com.amazonaws.services.pinpoint.model.Format; import com.amazonaws.services.pinpoint.model.GetImportJobRequest; import com.amazonaws.services.pinpoint.model.GetImportJobResult; import com.amazonaws.services.pinpoint.model.ImportJobRequest; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.model.AmazonS3Exception; import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.concurrent.TimeUnit; public class ImportEndpoints { public static void main(String[] args) { final String USAGE = "\n" + "ImportEndpoints - Adds endpoints to an Amazon Pinpoint application by: \n" + "1.) Uploading the endpoint definitions to an Amazon S3 bucket. \n" + "2.) Importing the endpoint definitions from the bucket to an Amazon Pinpoint " + "application.\n\n" + "Usage: ImportEndpoints <endpointsFileLocation> <s3BucketName> <iamImportRoleArn> " + "<applicationId>\n\n" + "Where:\n" + " endpointsFileLocation - The relative location of the JSON file that contains the " + "endpoint definitions.\n" + " s3BucketName - The name of the Amazon S3 bucket to upload the JSON file to. If the " + "bucket doesn't exist, a new bucket is created.\n" + " iamImportRoleArn - The ARN of an IAM role that grants Amazon Pinpoint read " + "permissions to the S3 bucket.\n" + " applicationId - The ID of the Amazon Pinpoint application to add the endpoints to."; if (args.length < 1) { System.out.println(USAGE); System.exit(1); } String endpointsFileLocation = args[0]; String s3BucketName = args[1]; String iamImportRoleArn = args[2]; String applicationId = args[3]; Path endpointsFilePath = Paths.get(endpointsFileLocation); File endpointsFile = new File(endpointsFilePath.toAbsolutePath().toString()); uploadToS3(endpointsFile, s3BucketName); importToPinpoint(endpointsFile.getName(), s3BucketName, iamImportRoleArn, applicationId); } private static void uploadToS3(File endpointsFile, String s3BucketName) { // Initializes Amazon S3 client. final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); // Checks whether the specified bucket exists. If not, attempts to create one. if (!s3.doesBucketExistV2(s3BucketName)) { try { s3.createBucket(s3BucketName); System.out.format("Created S3 bucket %s.\n", s3BucketName); } catch (AmazonS3Exception e) { System.err.println(e.getErrorMessage()); System.exit(1); } } // Uploads the endpoints file to the bucket. String endpointsFileName = endpointsFile.getName(); System.out.format("Uploading %s to S3 bucket %s . . .\n", endpointsFileName, s3BucketName); try { s3.putObject(s3BucketName, "imports/" + endpointsFileName, endpointsFile); System.out.println("Finished uploading to S3."); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } } private static void importToPinpoint(String endpointsFileName, String s3BucketName, String iamImportRoleArn, String applicationId) { // The S3 URL that Amazon Pinpoint requires to find the endpoints file. String s3Url = "s3://" + s3BucketName + "/imports/" + endpointsFileName; // Defines the import job that Amazon Pinpoint runs. ImportJobRequest importJobRequest = new ImportJobRequest() .withS3Url(s3Url) .withRegisterEndpoints(true) .withRoleArn(iamImportRoleArn) .withFormat(Format.JSON); CreateImportJobRequest createImportJobRequest = new CreateImportJobRequest() .withApplicationId(applicationId) .withImportJobRequest(importJobRequest); // Initializes the Amazon Pinpoint client. AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard() .withRegion(Regions.US_EAST_1).build(); System.out.format("Importing endpoints in %s to Amazon Pinpoint application %s . . .\n", endpointsFileName, applicationId); try { // Runs the import job with Amazon Pinpoint. CreateImportJobResult importResult = pinpointClient.createImportJob(createImportJobRequest); String jobId = importResult.getImportJobResponse().getId(); GetImportJobResult getImportJobResult = null; String jobStatus = null; // Checks the job status until the job completes or fails. do { getImportJobResult = pinpointClient.getImportJob(new GetImportJobRequest() .withJobId(jobId) .withApplicationId(applicationId)); jobStatus = getImportJobResult.getImportJobResponse().getJobStatus(); System.out.format("Import job %s . . .\n", jobStatus.toLowerCase()); TimeUnit.SECONDS.sleep(3); } while (!jobStatus.equals("COMPLETED") && !jobStatus.equals("FAILED")); if (jobStatus.equals("COMPLETED")) { System.out.println("Finished importing endpoints."); } else { System.err.println("Failed to import endpoints."); System.exit(1); } // Checks for entries that failed to import. // getFailures provides up to 100 of the first failed entries for the job, if // any exist. List<String> failedEndpoints = getImportJobResult.getImportJobResponse().getFailures(); if (failedEndpoints != null) { System.out.println("Failed to import the following entries:"); for (String failedEndpoint : failedEndpoints) { System.out.println(failedEndpoint); } } } catch (AmazonServiceException | InterruptedException e) { System.err.println(e.getMessage()); System.exit(1); } } }
HTTP

HTTP リクエストを直接 REST API に送信して Amazon Pinpoint を使用することができます。

例 S3 PUT Object リクエスト

エンドポイント定義をバケットに追加するには、Amazon S3 の PUT object オペレーションを使用して、エンドポイント定義を本文として入力します。

PUT /prefix/key HTTP/1.1 Content-Type: text/plain Accept: application/json Host: bucket-name.s3.amazonaws.com X-Amz-Content-Sha256: c430dc094b0cec2905bc88d96314914d058534b14e2bc6107faa9daa12fdff2d X-Amz-Date: 20180605T184132Z Authorization: AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/20180605/us-east-1/s3/aws4_request, SignedHeaders=accept;cache-control;content-length;content-type;host;postman-token;x-amz-content-sha256;x-amz-date, Signature=c25cbd6bf61bd3b3667c571ae764b9bf2d8af61b875cacced95d1e68d91b4170 Cache-Control: no-cache {"ChannelType":"SMS","Address":"2065550182","Location":{"Country":"CAN"},"Demographic":{"Platform":"Android","Make":"LG"},"User":{"UserId":"example-user-id-1"}} {"ChannelType":"APNS","Address":"1a2b3c4d5e6f7g8h9i0j1a2b3c4d5e6f","Location":{"Country":"USA"},"Demographic":{"Platform":"iOS","Make":"Apple"},"User":{"UserId":"example-user-id-2"}} {"ChannelType":"EMAIL","Address":"john.stiles@example.com","Location":{"Country":"USA"},"Demographic":{"Platform":"iOS","Make":"Apple"},"User":{"UserId":"example-user-id-2"}}

コードの説明は以下のとおりです。

  • /prefix/key は、オブジェクトのプレフィックスおよびキーの名前であり、アップロード後にエンドポイント定義が含まれます。オブジェクトを階層的に整理するには、このプレフィックスを使用します。例えば、このようなプレフィックスには pinpoint/imports/endpoints/ があります。

  • bucket-name は、エンドポイント定義に追加する Amazon S3 バケットの名前です。

例 POST Import Job リクエスト

Amazon S3 バケットからエンドポイント定義をインポートするには、インポートジョブリソースに対して POST リクエストを発行します。リクエストに、必要なヘッダーを含め、ImportJobRequest JSON を本文として指定します。

POST /v1/apps/application_id/jobs/import HTTP/1.1 Content-Type: application/json Accept: application/json Host: pinpoint.us-east-1.amazonaws.com X-Amz-Date: 20180605T214912Z Authorization: AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/20180605/us-east-1/mobiletargeting/aws4_request, SignedHeaders=accept;cache-control;content-length;content-type;host;postman-token;x-amz-date, Signature=c25cbd6bf61bd3b3667c571ae764b9bf2d8af61b875cacced95d1e68d91b4170 Cache-Control: no-cache { "S3Url": "s3://bucket-name/prefix/key", "RoleArn": "iam-import-role-arn", "Format": "format", "RegisterEndpoints": true }

コードの説明は以下のとおりです。

  • application-id は、エンドポイントをインポートする Amazon Pinpoint プロジェクトの ID です。

  • bucket-name/prefix/key は、インポートする 1 つ以上のオブジェクトを含む、Amazon S3 内の場所です。この場所を表す末尾は、各オブジェクトのキー、または複数のオブジェクトを指定するプレフィックスになります。

  • iam-import-role-arn は、Amazon Pinpoint の読み込みのアクセス許可をバケットに付与する IAM ロールの Amazon リソースネーム (ARN) です。

  • 形式は、エンドポイントの定義に使用した形式に基づき、JSON または CSV になります。Amazon S3 の場所にさまざまな形式のファイルが複数含まれている場合、Amazon Pinpoint では、指定した形式に一致するファイルのみインポートします。

リクエストが成功すると、次のようなレスポンスが表示されます。

{ "Id": "a995ce5d70fa44adb563b7d0e3f6c6f5", "JobStatus": "CREATED", "CreationDate": "2018-06-05T21:49:15.288Z", "Type": "IMPORT", "Definition": { "S3Url": "s3://bucket-name/prefix/key", "RoleArn": "iam-import-role-arn", "ExternalId": "external-id", "Format": "JSON", "RegisterEndpoints": true, "DefineSegment": false } }

このレスポンスでは、Id 属性のジョブ ID が返ります。この ID を使用して、インポートジョブの現在のステータスを確認できます。

例 GET Import Job リクエスト

インポートジョブの現在のステータスを確認するには、GETImport Job リソースに対して リクエストを発行します。

GET /v1/apps/application_id/jobs/import/job_id HTTP/1.1 Content-Type: application/json Accept: application/json Host: pinpoint.us-east-1.amazonaws.com X-Amz-Date: 20180605T220744Z Authorization: AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/20180605/us-east-1/mobiletargeting/aws4_request, SignedHeaders=accept;cache-control;content-type;host;postman-token;x-amz-date, Signature=c25cbd6bf61bd3b3667c571ae764b9bf2d8af61b875cacced95d1e68d91b4170 Cache-Control: no-cache

コードの説明は以下のとおりです。

  • application_id は、インポートジョブを開始した Amazon Pinpoint プロジェクトの ID です。

  • job_id は、確認中のインポートジョブの ID です。

リクエストが成功すると、次のようなレスポンスが表示されます。

{ "ApplicationId": "application_id", "Id": "70a51b2cf442447492d2c8e50336a9e8", "JobStatus": "COMPLETED", "CompletedPieces": 1, "FailedPieces": 0, "TotalPieces": 1, "CreationDate": "2018-06-05T22:04:49.213Z", "CompletionDate": "2018-06-05T22:04:58.034Z", "Type": "IMPORT", "TotalFailures": 0, "TotalProcessed": 3, "Definition": { "S3Url": "s3://bucket-name/prefix/key.json", "RoleArn": "iam-import-role-arn", "ExternalId": "external-id", "Format": "JSON", "RegisterEndpoints": true, "DefineSegment": false } }

このレスポンスでは、JobStatus 属性のジョブステータスを返します。

Amazon Pinpoint API のインポートジョブリソースに関する詳細 (例: サポートされている HTTP メソッドやリクエストパラメータ) については、「Amazon Pinpoint API リファレンス」の「インポートジョブ」を参照してください。