Hello everyone! I deployed lambda function with serverless. The lambda has iot trigger:
events: [
{
iot: {
sql: "SELECT * as message FROM 'a/b/#' where meta.action='acton-type'",
description: 'MQTT triggered function',
sqlVersion: '2016-03-23' as '2016-03-23',
},
},
],
I send message to mqtt with the next code:
...
import { mqtt5, iot } from 'aws-iot-device-sdk-v2';
import axios from 'axios';
import { toUtf8 } from '@aws-sdk/util-utf8-browser';
...
const caCert = (await axios.get('http://localhost.localstack.cloud:4566/_aws/iot/LocalStackIoTRootCA.pem')).data;
const keysAndCertificate = await iotApi.createKeysAndCertificate();
const builder = iot.AwsIotMqtt5ClientConfigBuilder
.newDirectMqttBuilderWithMtlsFromMemory(
mqttEndpoint!,
keysAndCertificate.certificatePem,
keysAndCertificate.keyPair.privateKey,
)
.withCertificateAuthority(caCert);
const client : mqtt5.Mqtt5Client = new mqtt5.Mqtt5Client({
...builder.build(),
hostName: mqttEndpoint!.split(':')[0],
port: +mqttEndpoint!.split(':')[1],
});
const startPromise = new Promise<void>((resolve) => client.on('connectionSuccess', (_eventData: mqtt5.ConnectionSuccessEvent) => {
console.log('Connection Success event');
resolve();
}));
client.start();
await startPromise;
await client.publish({
topicName: 'a/b/test',
payloadFormat: 1,
payload: JSON.stringify({
meta: {
action: 'acton-type',
},
}),
qos: mqtt5.QoS.AtLeastOnce,
});
client.close();
And my lambda was not triggered. I also created subscriber with the code example above and successfully received published message. In localstack’s logs I only see message that client was connected.
Does localstack support Iot triggers for lambdas? If yes , could you show me what I am doing wrong.
Thank you!