Importing items individually - Amazon Personalize

Importing items individually

After you complete Creating a dataset and a schema to create an Items dataset, you can individually import one or more new items into the dataset. Individually importing items allows you to keep your Items dataset current with small batch imports as your catalog grows. You can import up to 10 items at a time. If you have a large amount of new items, we recommend that you first import data in bulk and then import item data individually as necessary. See Importing data directly into Amazon Personalize datasets.

You can use the Amazon Personalize console, the AWS Command Line Interface (AWS CLI), or AWS SDKs to import items. If you import an item with the same itemId as an item that's already in your Items dataset, Amazon Personalize replaces it with the new item.

For information about how Amazon Personalize updates filters for new records and how new records influence recommendations, see Importing individual records.

Importing items individually (console)

You can import up to 10 items to an Items dataset at a time. This procedure assumes that you have already created an Items dataset. For information about creating datasets, see Creating a dataset and a schema.

To import items individually (console)
  1. Open the Amazon Personalize console at https://console.aws.amazon.com/personalize/home and sign in to your account.

  2. On the Dataset groups page, choose the dataset group with the Items dataset that you want to import the items to.

  3. In the navigation pane, choose Datasets.

  4. On the Datasets page, choose the Items dataset.

  5. At the top right of the dataset details page, choose Modify dataset, and then choose Create record.

  6. In Create item record(s) page, for Record input, enter the item details in JSON format. The item's field names and values must match the schema you used when you created the Items dataset. Amazon Personalize provides a JSON template with field names and data types from this schema.

  7. Choose Create record(s). In Response, the result of the import is listed and a success or failure message is displayed.

Importing items individually (AWS CLI)

Add one or more items to your Items dataset using the PutItems operation. You can import up to 10 items with a single PutItems call. This section assumes that you have already created an Items dataset. For information about creating datasets, see Creating a dataset and a schema.

Use the following put-items command to add one or more items with the AWS CLI. Replace dataset arn with the Amazon Resource Name (ARN) of your dataset and item Id with the ID of the item. If an item with the same itemId is already in your Items dataset, Amazon Personalize replaces it with the new one.

For properties, for each field in your Items dataset, replace the propertyName with the field name from your schema in camel case. For example, GENRES would be genres and CREATION_TIMESTAMP would be creationTimestamp. Replace item data with the data for the item. CREATION_TIMESTAMP data must be in Unix epoch time format and in seconds. For categorical string data, to include multiple categories for a single property, separate each category with a pipe (|). For example \"Horror|Action\".

aws personalize-events put-items \ --dataset-arn dataset arn \ --items '[{ "itemId": "item Id", "properties": "{\"propertyName\": "\item data\"}" }, { "itemId": "item Id", "properties": "{\"propertyName\": "\item data\"}" }]'

Importing items individually (AWS SDKs)

Add one or more items to your Items dataset using the PutItems operation. You can import up to 10 items with a single PutItems call. If an item with the same itemId is already in your Items dataset, Amazon Personalize replaces it with the new one. This section assumes that you have already created an Items dataset. For information about creating datasets, see Creating a dataset and a schema.

The following code shows how to add one or more items to your Items dataset. For each property name parameter, pass the field name from your schema in camel case. For example, GENRES would be genres and CREATION_TIMESTAMP would be creationTimestamp. For each property value parameter, pass the data for the item. CREATION_TIMESTAMP data must be in Unix epoch time format and in seconds.

For categorical string data, to include multiple categories for a single property, separate each category with a pipe (|). For example "Horror|Action".

SDK for Python (Boto3)
import boto3 personalize_events = boto3.client(service_name='personalize-events') personalize_events.put_items( datasetArn = 'dataset arn', items = [{ 'itemId': 'item ID', 'properties': "{\"propertyName\": \"item data\"}" }, { 'itemId': 'item ID', 'properties': "{\"propertyName\": \"item data\"}" }] )
SDK for Java 2.x
public static int putItems(PersonalizeEventsClient personalizeEventsClient, String datasetArn, String item1Id, String item1PropertyName, String item1PropertyValue, String item2Id, String item2PropertyName, String item2PropertyValue) { int responseCode = 0; ArrayList<Item> items = new ArrayList<>(); try { Item item1 = Item.builder() .itemId(item1Id) .properties(String.format("{\"%1$s\": \"%2$s\"}", item1PropertyName, item1PropertyValue)) .build(); items.add(item1); Item item2 = Item.builder() .itemId(item2Id) .properties(String.format("{\"%1$s\": \"%2$s\"}", item2PropertyName, item2PropertyValue)) .build(); items.add(item2); PutItemsRequest putItemsRequest = PutItemsRequest.builder() .datasetArn(datasetArn) .items(items) .build(); responseCode = personalizeEventsClient.putItems(putItemsRequest).sdkHttpResponse().statusCode(); System.out.println("Response code: " + responseCode); return responseCode; } catch (PersonalizeEventsException e) { System.out.println(e.awsErrorDetails().errorMessage()); } return responseCode; }
SDK for JavaScript v3
import { PutItemsCommand, PersonalizeEventsClient, } from "@aws-sdk/client-personalize-events"; const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION", }); // set the put items parameters var putItemsParam = { datasetArn: "DATASET ARN", items: [ { itemId: "itemId", properties: '{"column1Name": "value", "column2Name": "value"}', }, { itemId: "itemId", properties: '{"column1Name": "value", "column2Name": "value"}', }, ], }; export const run = async () => { try { const response = await personalizeEventsClient.send( new PutItemsCommand(putItemsParam) ); console.log("Success!", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();