1import * as iotdata from "@distilled.cloud/aws/iot-data-plane";
2import * as Layer from "effect/Layer";
3import { makeIotTopicHttpBinding } from "./BindingHttp.ts";
4import { Publish } from "./Publish.ts";
5
6/**
7 * HTTP implementation of the {@link Publish} capability.
8 *
9 * At deploy time it attaches an IAM policy statement granting `iot:Publish`
10 * on the bound topic filter (`arn:aws:iot:...:topic/{filter}`); at runtime it
11 * calls the IoT data-plane `Publish` API over HTTPS.
12 *
13 * @example Provide the layer on a Lambda Function
14 * ```typescript
15 * export default TelemetryFunction.make(
16 * { main: import.meta.url },
17 * Effect.gen(function* () {
18 * const publish = yield* AWS.IoT.Publish("sensors/*");
19 * // ... handlers that call `publish({ topic, payload })`
20 * }).pipe(Effect.provide(AWS.IoT.PublishHttp)),
21 * );
22 * ```
23 */
24export const PublishHttp = Layer.effect(
25 Publish,
26 makeIotTopicHttpBinding({
27 tag: "AWS.IoT.Publish",
28 operation: iotdata.publish,
29 // RetainPublish authorizes `retain: true` publishes (a separate IAM
30 // action from plain Publish) on the same topic filter.
31 actions: ["iot:Publish", "iot:RetainPublish"],
32 }),
33);