本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
在 Amazon Pinpoint 中匯入客群
您可以透過 Amazon Pinpoint,匯入客群所屬端點的相關資訊,以定義使用者客群。端點是單一簡訊目的地,例如行動推送裝置字符、行動電話號碼或電子郵件地址。
如果您已經在 Amazon Pinpoint 以外的地方建立了客群,但您希望透過 Amazon Pinpoint 行銷活動吸引用戶,那麼匯入客群很有用。
您匯入客群時,Amazon Pinpoint 會從 Amazon Simple Storage Service (Amazon S3) 取得客群的端點。在匯入之前,您可以將端點新增至 Amazon S3,並建立IAM角色,將 Amazon Pinpoint 存取權授予 Amazon S3。接著為 Amazon Pinpoint 提供儲存端點的 Amazon S3 位置,Amazon Pinpoint 會將每個端點加入客群。
若要建立 IAM 角色,請參閱IAM 用於匯入端點或區段的角色。如需使用 Amazon Pinpoint 主控台匯入客群的相關資訊,請參閱 Amazon Pinpoint 使用者指南中的匯入客群。
如需更多程式碼範例,請參閱程式碼範例 。
使用 匯入區段 AWS SDK for Java
以下範例示範如何使用 AWS SDK for Java匯入客群。
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;
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; } }
如需完整SDK範例,請參閱 上的 ImportingSegments.java