Sono disponibili altri esempi per SDK AWS nel repository GitHub della documentazione degli esempi per SDK AWS
Utilizzare PutRecords con un SDK AWS o una CLI
Gli esempi di codice seguenti mostrano come utilizzare PutRecords.
- CLI
-
- AWS CLI
-
Come scrivere più record in un flusso di dati
L’esempio
put-recordsseguente scrive un record di dati utilizzando la chiave di partizione specificata e un altro record di dati utilizzando una chiave di partizione diversa in un’unica chiamata.aws kinesis put-records \ --stream-namesamplestream\ --recordsData=blob1,PartitionKey=partitionkey1Data=blob2,PartitionKey=partitionkey2Output:
{ "FailedRecordCount": 0, "Records": [ { "SequenceNumber": "49600883331171471519674795588238531498465399900093808706", "ShardId": "shardId-000000000004" }, { "SequenceNumber": "49600902273357540915989931256902715169698037101720764562", "ShardId": "shardId-000000000009" } ], "EncryptionType": "KMS" }Per ulteriori informazioni, consulta Sviluppo di producer utilizzando l’API per il flusso di dati Amazon Kinesis con AWS SDK per Java nella Guida per gli sviluppatori di Flusso di dati Amazon Kinesis.
-
Per informazioni dettagliate sull’API, consulta PutRecords
nella documentazione di riferimento dei comandi della AWS CLI.
-
- JavaScript
-
- SDK per JavaScript (v3)
-
Nota
Ulteriori informazioni su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel Repository di esempi di codice AWS
. import { PutRecordsCommand, KinesisClient } from "@aws-sdk/client-kinesis"; /** * Put multiple records into a Kinesis stream. * @param {{ streamArn: string }} config */ export const main = async ({ streamArn }) => { const client = new KinesisClient({}); try { await client.send( new PutRecordsCommand({ StreamARN: streamArn, Records: [ { Data: new Uint8Array(), /** * Determines which shard in the stream the data record is assigned to. * Partition keys are Unicode strings with a maximum length limit of 256 * characters for each key. Amazon Kinesis Data Streams uses the partition * key as input to a hash function that maps the partition key and * associated data to a specific shard. */ PartitionKey: "TEST_KEY", }, { Data: new Uint8Array(), PartitionKey: "TEST_KEY", }, ], }), ); } catch (caught) { if (caught instanceof Error) { // } else { throw caught; } } }; // Call function if run directly. import { fileURLToPath } from "node:url"; import { parseArgs } from "node:util"; if (process.argv[1] === fileURLToPath(import.meta.url)) { const options = { streamArn: { type: "string", description: "The ARN of the stream.", }, }; const { values } = parseArgs({ options }); main(values); }-
Per informazioni dettagliate sull’API, consulta PutRecords nella documentazione di riferimento dell’API AWS SDK per JavaScript.
-