Receive only one parameter from aws IoT rule's json data - json

I am receiveing data from AWS IoT and the incomming data looks like:
{
"desired": {
"status": "ON",
"Temperature": 4,
},
"reported": {
"status": "ON",
"Temperature": 4
}
}
I have set up a text message alert every time that new data comes in. With the text message I only want to receive the temperature. The current query string is:
SELECT * FROM '$aws/things/MyDashButton/shadow/update'
I am assuming that I have to change the star to Temperature, but when I do the text message I receive is blank. I tried looking through the documentation, but cannot find an answer for this.
EDIT:
If I use
SELECT state.desired.Temperature FROM '$aws/things/MyDashButton/shadow/update'
I get {"Temperature": 4} is there a way just to get the value?

There is no way to just get a value by using only the AWS IoT rule engine.
You can instead write some code in AWS Lambda to send you just the value (or with other cosmetics you desire) via AWS SES. Use the Rule Engine to invoke the Lambda function.

Related

Character limit on an attribute in JSON response

I have an attribute which can store 1024 characters in the column of my table in db. Let's assume the name of attribute is statusMessage.
The value of statusMessage attribute in the column of table is:
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaa..."
}
So my observation is that the db is storing the complete 1024 characters in the column of its table but the JSON response is not able to show the complete data in its response for the given attribute.
What could be the possible reason for this? And how can it be rectified?
Note: Using SQL database and hybris platform for my web application and this scenario is only happening for v1 rest web API's. For v2 rest web API, it renders all 1024 characters.

AWS CLI create multiple users

I am trying to create multiple users using the AWS CLI. This is just an exercise in learning.
I get different errors depending on what changes I make. After a bit of searching, I changed the encoding and used file:// which elimated the Invalid JSON received errors.
I've tried this with a json file that is ASCII encoded and only one user.
aws iam create-user --cli-input-json file://aws-ec2.json --profile MyProf
I get:
Parameter validation failed: Invalid length for parameter Path, value:
0, valid range: 1-inf Invalid length for parameter
PermissionsBoundary, value: 0, valid range: 20-inf Invalid length for
parameter Tags[0].Key, value: 0, valid range: 1-inf
If I add another user, so change the UserName line to "MyEC2","SecondEC2", it just gives me Invalid JSON received.
Here's the JSON I am using:
{
"Path": "",
"UserName": "MyEC2",
"PermissionsBoundary": "",
"Tags": [
{
"Key": "",
"Value": ""
}
]
}
I know I'm doing something wrong, I just can't figure out what it is!
Thank you John. No one had anything to add. A friend of mine, networking person, suggested that I copy the command into Excel, concatenate the columns and then copy and paste the commands into the CLI.
I was hoping for a different response, but as I wrote in my question, this was just an exercise in learning. Your answer is an answer, and apparently a correct answer.
Thanks again for your time.

Pact Consumer / Provider based in data type and not in data value

We are currently using Pact-Broker in our Spring Boot application with really good results for our integration tests.
Our tests using Pact-Broker are base in a call to a REST API and comparing the response with the value in our provider, always using JSON format.
Our problem is that the values to compare are in a DB where the data is changing quite often, which make us update the tests really often.
Do you know if it is possible to just validate by the data type?
What we would like to try is to validate that the JSON is properly formed and the data type match, for example, if our REST API gives this output:
[
{
"action": "VIEW",
"id": 1,
"module": "A",
"section": "pendingList",
"state": null
},
{
"action": "VIEW",
"id": 2,
"module": "B",
"section": "finished",
"state": null
}
}
]
For example, what we would like to validate from the previous output is the following:
The JSON is well formed.
All the keys / value pair exists based in the model.
The value match a specific data type, for example, that the key action exist in all the entries and contains a string data type.
Do you know if this is possible to be accomplished with Pact-Broker? I was searching in the documentation but I did not found any example of how to do it.
Thanks a lot in advance.
Best regards.
Absolutely! The first 2 things Pact will always do without any extra work.
What you are talking about is referred to as flexible matching [1]. You don't want to match the value, but the type (or a regex). Given you are using Spring Boot, you may want to look at the various matchers available for Pact JVM [2].
I'm not sure if you meant it, but just for clarity, Pact and Pact Broker are separate things. Pact is the Open Source contract-testing framework, and Pact Broker [3] is a tool to help share and collaborate on those contracts with the team.
[1] https://docs.pact.io/getting_started/matching
[2] https://github.com/DiUS/pact-jvm/tree/master/consumer/pact-jvm-consumer#dsl-matching-methods
[3] https://github.com/pact-foundation/pact_broker/

Uploading data from matlab to firebase

Firebase creates a name for the data i upload from matlab.
is there a way to cancel this name? or set it to something constant so the next time i upload ill overwrite it?
Example:
https://cdn1.imggmi.com/uploads/2019/3/24/0cb9e3c19155a8b338806121aed42ea2-full.jpg
(i want the data from matlab to be the same structure like the adc sample)
This is the code I use:
Firebase_Url = 'https://***.firebaseio.com/data_from_matlab.json/';
response = webwrite(Firebase_Url,'{ "first": "Jack", "last": "Sparrow" }')
It looks like Matlab's webwrite function sends a HTTP POST request, which Firebase's REST API translates to create a new node with a new unique ID.
It looks like you can pass RequestMethod: 'put' in the weboptions parameter to send a PUT request, which Firebase translation to a direct write at the location. So something like:
webwrite(Firebase_Url,'{ "first": "Jack", "last": "Sparrow" }',
weboptions("RequestMethod", "put"))
I actually was having a similar problem but I wanted to add multiple objects with different names and when I used RequestMethod: 'put' in weboptions Firebase deleted my old objects. I looked into the link given above I discovered that using RequestMethod: 'patch' I could add multiple objects under the same category without getting the randomly generated key.

Structuring json data in GET call query parameters

I'm trying to pass a list of the following objects as query params to a GET call to my Java service:
{
"id": "123456",
"country": "US",
"locale": "en_us"
}
As a url, this would like like
GET endpoint.com/entity?id1=123456&country1=US&locale1=en_us&id2=...
What's the best way to handle this as a service? If I'm passing potentially 15 of these objects, is there a concise way to take in these parameters and convert them to Java objects on the server side?
I imagine with a URL like this, the service controller would have a lot of #QueryParams...
Create the entire dataset as JSON array, e.g.
[
{
"id": "123456",
"country": "US",
"locale": "en_us"
},
{
"id": "7890",
"country": "UK",
"locale": "en_gb"
}
]
base64 encode it and pass it as a parameter, e.g.
GET endpoint.com/entity?set=BASE64_ENCODED_DATASET
then decode on the server and parse the JSON array into Java objects using perhaps Spring Boot.
Based on the valid URL size comment (although 2000 is usable), you could put the data in a header instead, which can be from 8-16kb depending on the server. GETting multiple resources at once is going to involve compromise somewhere in the design.
As Base64 can contain +/= you can url encode it too although I haven't found the need to do this in practice when using this technique in SAML.
Another approach would be to compromise on searching via country and locale specific IDs:
GET endpoint.com/entity/{country}/{locale}/{id_csv}
so you would search like this:
GET endpoint.com/entity/US/en_us/123456,0349,23421
your backend handles (if using Spring) as #PathParam for {country} and {locale} and it splits {id_csv} to get the list of IDs for that country/locale combination.
To get another country/locale search:
GET endpoint.com/entity/UK/en_gb/7890,234,123232
URLs are much smaller but you can't query the entire dataset in one go as you need to query based on country/locale each time.
It looks like your GET is getting multiple resources from the server. I'd consider refactoring to GET 1 resource from the server per GET request. If this causes performance issues, consider using HTTP caching.