Destination
Source:
src/AWS/IoTWireless/Destination.ts
An AWS IoT Core for LoRaWAN destination — the routing rule that delivers uplink messages from wireless devices to an AWS IoT rule or MQTT topic.
The destination name is its identity (changing it replaces the destination); the expression, expression type, description, role, and tags all update in place.
Creating Destinations
Section titled “Creating Destinations”Route uplinks to an IoT rule
import * as IoTWireless from "alchemy/AWS/IoTWireless";
const destination = yield* IoTWireless.Destination("Uplinks", { expressionType: "RuleName", expression: "process_sensor_uplinks", roleArn: deliveryRole.roleArn,});Publish uplinks straight to an MQTT topic
const destination = yield* IoTWireless.Destination("Uplinks", { expressionType: "MqttTopic", expression: "sensors/uplinks", roleArn: deliveryRole.roleArn,});Delivery Role
Section titled “Delivery Role”const deliveryRole = yield* IAM.Role("IotWirelessDelivery", { assumeRolePolicyDocument: { Version: "2012-10-17", Statement: [{ Effect: "Allow", Principal: { Service: "iotwireless.amazonaws.com" }, Action: ["sts:AssumeRole"], }], }, policies: [{ policyName: "deliver", policyDocument: { Version: "2012-10-17", Statement: [{ Effect: "Allow", Action: ["iot:DescribeEndpoint", "iot:Publish"], Resource: ["*"], }], }, }],});Consuming Uplinks in a Function
Section titled “Consuming Uplinks in a Function”Uplinks are delivered through AWS IoT Core. For a RuleName destination,
IoTWireless.consumeUplinks (see DestinationEventSource) creates
the named IoT rule targeting the current Lambda and invokes the handler
for every uplink. Alternatively, point an MqttTopic destination at a
topic and consume it with AWS.IoT.consumeTopicMessages.
const destination = yield* IoTWireless.Destination("Uplinks", { expressionType: "RuleName", expression: "sensor_uplinks", roleArn: deliveryRole.roleArn,});
// inside the Function effect (provide Lambda.WirelessDestinationEventSource):yield* IoTWireless.consumeUplinks(destination, (uplinks) => uplinks.pipe( Stream.runForEach((uplink) => processUplink(uplink)), Effect.orDie, ),);