Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Use PutItems
with an Amazon SDK or CLI
The following code example shows how to use PutItems
.
- JavaScript
-
- SDK for JavaScript (v3)
-
// Get service clients module and commands using ES6 syntax.
import { PutItemsCommand } from "@aws-sdk/client-personalize-events";
import { personalizeEventsClient } from "./libs/personalizeClients.js";
// Or, create the client here.
// const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION"});
// Set the put items parameters. For string properties and values, use the \ character to escape quotes.
var putItemsParam = {
datasetArn: "DATASET_ARN" /* required */,
items: [
/* required */
{
itemId: "ITEM_ID" /* required */,
properties:
'{"PROPERTY1_NAME": "PROPERTY1_VALUE", "PROPERTY2_NAME": "PROPERTY2_VALUE", "PROPERTY3_NAME": "PROPERTY3_VALUE"}' /* optional */,
},
],
};
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();
For a complete list of Amazon SDK developer guides and code examples, see
Using Amazon Personalize with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.