CreateCampaign.java - AWS Code Sample

CreateCampaign.java

CreateCampaign.java demonstrates how to create an Amazon Personalize campaign.

/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ package com.example.personalize; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.personalize.PersonalizeClient; import software.amazon.awssdk.services.personalize.model.CreateCampaignRequest; import software.amazon.awssdk.services.personalize.model.CreateCampaignResponse; import software.amazon.awssdk.services.personalize.model.PersonalizeException; public class CreateCampaign { public static void main(String[] args) { final String USAGE = "\n" + "Usage:\n" + " CreateCampaign <solutionVersionArn> <name>\n\n" + "Where:\n" + " solutionVersionArn - The Amazon Resource Name (ARN) of the solution version.\n\n" + " name - The name of the Amazon Personalize campaign.\n\n" ; if (args.length < 2) { System.out.println(USAGE); System.exit(1); } /* Read the name from command args */ String solutionVersionArn = args[0]; String name = args[1]; Region region = Region.US_EAST_1; PersonalizeClient personalizeClient = PersonalizeClient.builder() .region(region) .build(); createPersonalCompaign(personalizeClient, solutionVersionArn, name); } public static void createPersonalCompaign(PersonalizeClient personalizeClient, String solutionVersionArn, String name) { try { CreateCampaignRequest createCampaignRequest = CreateCampaignRequest.builder() .minProvisionedTPS(1) .solutionVersionArn(solutionVersionArn) .name(name) .build(); CreateCampaignResponse campaignResponse = personalizeClient.createCampaign(createCampaignRequest); System.out.println("The campaign ARN is "+campaignResponse.campaignArn()); } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }

Sample Details

Service: Amazon Personalize

Last tested: 8/21/2020

Author: scmacdon AWS

Type: full-example