How to check AWS IoT Device connection status on the web console? - amazon-web-services

I just started playing with AWS IoT. I created a thing and use mqtt-spy to connect to AWS server. All is ok.
Now I'd like to check the status of each thing in the web console, however I couldn't find such useful info near the device.

By enabling AWS IoT Fleet Indexing Service, you can get the connectivity status of a thing. Also, you can query for currently connected/disconnected devices.
First, you have to enable indexing (thingConnectivityIndexingMode) by aws-cli or through the console.
aws iot update-indexing-configuration --thing-indexing-configuration thingIndexingMode=REGISTRY_AND_SHADOW,thingConnectivityIndexingMode=STATUS
Then you can query a thing's connectivity status like the following
aws iot search-index --index-name "AWS_Things" --query-string "thingName:mything1"
{
"things":[{
"thingName":"mything1",
"thingGroupNames":[
"mygroup1"
],
"thingId":"a4b9f759-b0f2-4857-8a4b-967745ed9f4e",
"attributes":{
"attribute1":"abc"
},
"connectivity": {
"connected":false,
"timestamp":1641508937
}
}
}
Note: Fleet Indexing Service index connectivity data with device lifecycle events ($aws/events/presence/connected/). In some cases it may take a minute or so for the service to update indexing after a connect or disconnect event occurs.
EDIT: The javascript version of this:
var iot = new AWS.Iot({
apiVersion: "2015-05-28"
});
...
var params = {
queryString: "thingName:" + data.Item.thingName, // using result from DynamoDB
indexName: 'AWS_Things'
// maxResults: 'NUMBER_VALUE',
// nextToken: 'STRING_VALUE',
// queryVersion: 'STRING_VALUE'
};
iot.searchIndex(params, function(err, data) {
if (err) {
console.log("error from iot.searchIndex");
console.log(err, err.stack); // an error occurred
} else {
console.log("success from iot.searchIndex");
console.log(data.things[0].connectivity.connected); // t/f
}
});

You need to subscribe to the topic on the aws iot console , test section on the right corner of AWS IoT-core. for example you to subscribe to this topic replace your client with the .
$aws/events/presence/connected/<Your_clientId>
if you have more than one thing then you have to subscribe using your ClientID
for reference check this link https://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html

Related

Service Bus topics

I have a springboot micrservices application that needs to subscribe to topic and all copies of the container should get the message. I am used to activemq where you can connect directly to the topic and all containers get the message.
I set my appliation.yaml like:
servicebus:
connection-string: ${AZURE_SERVICE_BUS_URL}
idle-timeout: 1800000
pricing-tier: standard
topic-client-id: ${AZURE_SERVICE_BUS_TOPIC_CLIENT_ID}
listener:
subscription-durable: false
I set the listener as:
#JmsListener(destination = "edge-bindermgmt-request-state", containerFactory = "topicJmsListenerContainerFactory")
public void receiveMessage(RequestProcessingStateChange requestProcessingStateChange){
log.info("Received: {}", requestProcessingStateChange);
}
With the following I am only getting the message in one copy of the service:
#JmsListener(destination = "edge-bindermgmt-request-state", containerFactory = "topicJmsListenerContainerFactory",
subscription = "edge-bindermgmt-request-state-subscription")
public void receiveMessage(RequestProcessingStateChange requestProcessingStateChange){
log.info("Received: {}", requestProcessingStateChange);
}
So what I want is to setup the subscription on the fly, rather than having to set it up in:
screenshot of subscriptions page
If anyone else is wondering, you need the premium subscription for Service Bus for that. I ended up going with ActiveMQ instead.

Using AWS SDK functions in Lambda

I would like to use AWS Lambda to restart an app server in an elastic beanstalk instance.
After extensive googling and not finding anything, I finally found an article that I have now lost that described how to do what I want. I used it to set up a Lambda function and an EventBridge cron schedule to run the function. Looking at my the cloudwatch logs for the eventbridge, I can see the function is successfully running. However, it is definitely not restarting my app server. When I use the console button to restart, the data I pulled in with another cron gets updated and I can see the date on my main page update. This does not happen when the lambda function runs, though it should.
Here is my function:
const AWS = require('aws-sdk');
const eb = new AWS.ElasticBeanstalk({apiVersion: '2010-12-01'});
exports.handler = async (event) => {
const params = {
EnvironmentName: 'my-prod-environment'
};
eb.restartAppServer(params, function(err, data) {
if (err) {
console.log(err, err.stack);
return err;
}
else {
console.log(data);
return data;
}
});
};
The logs, unfortunately, tell me nothing. Despite the console.log statement, no error or data appears in my logs, so I don't know if the function is even completing. Does anyone have any idea why this won't work?

Local: Message timed out error when using AWS MSK Cluster and Confluent.Kafka nuget Package

I have AWS MSK cluster with 2 broker nodes.
I am not able at all to produce any messages to the brokers always got Local: Message timed out error .
I can access the cluster normally in using AWS CLI
the cluster node doesn't have any authentication just the application should run in a certain AWS VPC
I have tried the simplest example and just replace the bootstrap servers with the AWS Cluster nodes
here is the code
string brokerList = "b-1.8.c2.kafka.eu-central-1.amazonaws.com:9092,b-2.8.c.c2.kafka.eu-central-1.amazonaws.com:9092"; // sample nodes examples
string topicName = "TestTopic";
var config = new ProducerConfig { BootstrapServers = brokerList };
using (var producer = new ProducerBuilder<string, string>(config).Build())
{
Console.WriteLine("\n-----------------------------------------------------------------------");
Console.WriteLine($"Producer {producer.Name} producing on topic {topicName}.");
Console.WriteLine("-----------------------------------------------------------------------");
try
{
var deliveryReport = await producer.ProduceAsync(
topicName, new Message<string, string> { Key = "MyKey", Value = "MyValue" });
Console.WriteLine($"delivered to: {deliveryReport.TopicPartitionOffset}");
}
catch (ProduceException<string, string> e)
{
Console.WriteLine($"failed to deliver message: {e.Message} [{e.Error.Code}]");
}
I have tried both of TLS and Plaintext which are both allowed in the cluster and got the same error message.
Also have change the cluster configuration from auto.create.topics.enable=false to auto.create.topics.enable=true and still the same result.
i am using the below configuration setup
Confluent.Kafka nuget version. - Confluent.Kafka 1.4.3
Apache Kafka version. - 2.4.1
Error Message: Local: Message timed out

Cannot send request to Twilio from AWS ECS Task (awsvpc network mode)

I am using AWS - ECS service and I have 5 running tasks on the cluster that has initiated as awsvpc network mode.
The problem is that the task is supposed to send request to Twilio for the SMS code but the request to Twilio is being timed out.
const twilioClient = require('twilio')(accountSid, authToken)
try {
await twilioClient.messages.create({
body: `${code}`,
from: phoneNumber,
to: userInput.phone
})
} catch (err) {
console.log('Twilio Error: ', err)
return false
}
The error below shows the error I have logged on CloudWatch.
Twilio Error: {
Error: ETIMEDOUT
at Timeout._onTimeout (/srv/node_modules/request/request.js:849:19)
ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10) code: 'ETIMEDOUT', connect: true
}
The problem is that the same code works in case of default network mode for Task on AWS ECS.
I am using EC2 mode, not Fargate mode.
Looking forward to the right help on this.
Cheers.

AWS App Sync Subscriptions are not working

I am using AppSync to update my DynamoDB.
I have subscribed to that particular row, updated based on the partition key but I'm not able to receive the notifications.
I was expecting the output something like below mentioned
{
"data": {
"Post": null
}
}
But, I'm getting output as
{ "mqttConnections":
[ { "url": "*****",
"topics": ["*******************************","*****************************"],
"client": "*************"
} ],
"newSubscriptions":
{ "UpdateDevTable":
{ "topic": "*****************************",
"expireTime": 1541598037000 }
}
}
Can someone look into this and help me out?
This is functioning as expected. Subscriptions in AWS AppSync run on MQTT over WebSockets and the actual subscription request in GraphQL is responsible for creating an MQTT topic and configuring a credential so your client can connect to the topic. The AppSync SDKs handle connecting to the topic and streaming results into your application but you can also build your own subscription client using any MQTT client such as paho (https://www.eclipse.org/paho/).
You can learn more about how to use subscriptions from JavaScript by searching for "Make Your Application RealTime" here https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-react.html