I tried to publish an event from Lambda function to IOT, which execution environment resides in VPC private subnets but it is not working.
- I have an IOT device which policy is configured to allow all connections.
- Created a VPC with two private subnets and configured Lambda function to run inside them
- Lambda function has required permissions to access IOT and also security group is configured to allow all the outbound traffic to any port and any type of protocal (0.0.0.0/0)
- Created a VPC endpoint(com.amazonaws.eu-central-1.iot.data)(selected both privatesubnets) and assigned a security group which has rule to allow any traffic from Lambda function security group
Tried to publish an event using public endpoint without adding NAT gateway and it was not working(Getting timeout error) Note:- Working fine if I add NAT gateway.
please find the following sample piece of code tried to connect to IOT for the reference
const region = 'eu-central-1';
const endpoint = 'xxxx'; //public endpoint;
const clientId = 'test' //random string;
const {IotData} = require('aws-sdk')
const params = {
topic: 'test_topic', /* required, subscribed to this topic */
payload: 'STRING_VALUE' /* Strings will be Base-64 encoded on your behalf */,
qos: 1
};
const iotdata = new IotData({endpoint, region});
iotdata.publish(params, (res, err) => {
console.log('res', res)
console.log('err', err)
});