| 1 | import type * as Firehose from "@distilled.cloud/aws/firehose"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { DeliveryStream } from "./DeliveryStream.ts"; |
| 5 | |
| 6 | export interface PutRecordBatchRequest extends Omit< |
| 7 | Firehose.PutRecordBatchInput, |
| 8 | "DeliveryStreamName" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Writes multiple data records into a Firehose delivery stream in a single |
| 13 | * call, achieving higher throughput per producer than single-record puts. |
| 14 | * |
| 15 | * Grants `firehose:PutRecordBatch` on the bound delivery stream. Each request |
| 16 | * supports up to 500 records and 4 MiB total (limits are AWS-enforced, not |
| 17 | * client-enforced). Even a 200 response can carry per-record failures — |
| 18 | * check `FailedPutCount` and retry the failed entries from |
| 19 | * `RequestResponses`. |
| 20 | * ### Putting Records |
| 21 | * **Example:** Put a batch of records |
| 22 | * ```typescript |
| 23 | * // init |
| 24 | * const putRecordBatch = yield* AWS.Firehose.PutRecordBatch(deliveryStream); |
| 25 | * |
| 26 | * // runtime |
| 27 | * const response = yield* putRecordBatch({ |
| 28 | * Records: lines.map((line) => ({ |
| 29 | * Data: new TextEncoder().encode(`${line}\n`), |
| 30 | * })), |
| 31 | * }); |
| 32 | * if (response.FailedPutCount > 0) { |
| 33 | * // retry entries whose RequestResponses[i].ErrorCode is set |
| 34 | * } |
| 35 | * ``` |
| 36 | * |
| 37 | * @binding |
| 38 | */ |
| 39 | export interface PutRecordBatch extends Binding.Service< |
| 40 | PutRecordBatch, |
| 41 | "AWS.Firehose.PutRecordBatch", |
| 42 | ( |
| 43 | deliveryStream: DeliveryStream, |
| 44 | ) => Effect.Effect< |
| 45 | ( |
| 46 | request: PutRecordBatchRequest, |
| 47 | ) => Effect.Effect< |
| 48 | Firehose.PutRecordBatchOutput, |
| 49 | Firehose.PutRecordBatchError |
| 50 | > |
| 51 | > |
| 52 | > {} |
| 53 | |
| 54 | export const PutRecordBatch = Binding.Service<PutRecordBatch>( |
| 55 | "AWS.Firehose.PutRecordBatch", |
| 56 | ); |