Skip to content

Publish

Source: src/AWS/IoT/Publish.ts

A capability that lets a Function publish MQTT messages to AWS IoT Core topics via the IoT data plane.

Binding to a topic filter grants the host iot:Publish on matching topics (or on all topics when the filter is omitted) and returns a runtime callable for the data-plane Publish API. Provide the PublishHttp layer on the Function.

export default TelemetryFunction.make(
{ main: import.meta.url, url: true },
Effect.gen(function* () {
// grants iot:Publish on sensors/* to this function
const publish = yield* AWS.IoT.Publish("sensors/*");
return {
fetch: Effect.gen(function* () {
yield* publish({
topic: "sensors/1/telemetry",
payload: JSON.stringify({ t: 22.5 }),
});
return HttpServerResponse.json({ ok: true });
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(AWS.IoT.PublishHttp)),
);