Skip to content

Instantly share code, notes, and snippets.

@cyuste
Created November 29, 2022 14:33
Show Gist options
  • Save cyuste/70b4570f80694b10b6e3303c69daac18 to your computer and use it in GitHub Desktop.
Save cyuste/70b4570f80694b10b6e3303c69daac18 to your computer and use it in GitHub Desktop.
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { IoTDataPlaneClient, PublishCommand } from '@aws-sdk/client-iot-data-plane';
import { TextEncoder } from 'util';
export const dynamoClient = new DynamoDBClient({});
export const iotClient = new IoTDataPlaneClient({});
export const sendCommand = async (args: { id: string; command: string }) => {
const enc = new TextEncoder();
const publishCommand = new PublishCommand({
topic: `${args.id}/commands`,
qos: 1,
retain: false,
payload: enc.encode(args.command),
});
return await iotClient.send(publishCommand);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment