CreateImportJob 搭配 使用 AWS SDK - Amazon Pinpoint

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

CreateImportJob 搭配 使用 AWS SDK

下列程式碼範例示範如何使用 CreateImportJob

Java
SDK 適用於 Java 2.x
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

匯入客群。

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.pinpoint.PinpointClient; import software.amazon.awssdk.services.pinpoint.model.CreateImportJobRequest; import software.amazon.awssdk.services.pinpoint.model.ImportJobResponse; import software.amazon.awssdk.services.pinpoint.model.ImportJobRequest; import software.amazon.awssdk.services.pinpoint.model.Format; import software.amazon.awssdk.services.pinpoint.model.CreateImportJobResponse; import software.amazon.awssdk.services.pinpoint.model.PinpointException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class ImportSegment { public static void main(String[] args) { final String usage = """ Usage: <appId> <bucket> <key> <roleArn>\s Where: appId - The application ID to create a segment for. bucket - The name of the Amazon S3 bucket that contains the segment definitons. key - The key of the S3 object. roleArn - ARN of the role that allows Amazon Pinpoint to access S3. You need to set trust management for this to work. See https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html """; if (args.length != 4) { System.out.println(usage); System.exit(1); } String appId = args[0]; String bucket = args[1]; String key = args[2]; String roleArn = args[3]; PinpointClient pinpoint = PinpointClient.builder() .region(Region.US_EAST_1) .build(); ImportJobResponse response = createImportSegment(pinpoint, appId, bucket, key, roleArn); System.out.println("Import job for " + bucket + " submitted."); System.out.println("See application " + response.applicationId() + " for import job status."); System.out.println("See application " + response.jobStatus() + " for import job status."); pinpoint.close(); } public static ImportJobResponse createImportSegment(PinpointClient client, String appId, String bucket, String key, String roleArn) { try { ImportJobRequest importRequest = ImportJobRequest.builder() .defineSegment(true) .registerEndpoints(true) .roleArn(roleArn) .format(Format.JSON) .s3Url("s3://" + bucket + "/" + key) .build(); CreateImportJobRequest jobRequest = CreateImportJobRequest.builder() .importJobRequest(importRequest) .applicationId(appId) .build(); CreateImportJobResponse jobResponse = client.createImportJob(jobRequest); return jobResponse.importJobResponse(); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; } }
  • 如需API詳細資訊,請參閱 參考 CreateImportJob中的 。 AWS SDK for Java 2.x API

如需開發人員指南和程式碼範例的完整清單 AWS SDK,請參閱 搭配 使用 Amazon Pinpoint AWS SDK。本主題也包含有關入門的資訊,以及先前SDK版本的詳細資訊。