<commit_before># lambda-mqtt-test

AWS Lambda which function as a brdge between custom events and MQTT Broker.

We use this public MQTT broker for testing:
- http://test.mosquitto.org/

We use following npm module which implements MQTT client for Node.js:
- https://www.npmjs.org/package/mqtt

We'll need an MQTT CLI client.
We can use one that comes with Mosquitto MQTT broker:
- http://mosquitto.org/download/

Or we can use the MQTT CLI client that comes with `mqtt` npm module (which is much easier to install):

``` bash
npm install -g mqtt
```

Test that it works:

``` bash
mqtt_sub 1883 test.mosquitto.org '#'
...
<topic> <value>
...
CTRL-C
```

or same thing with mosquitto CLI client:

``` bash
mosquitto_sub -h test.mosquitto.org -t '#' -v
```


You should receive a bunch of messages. Press CTRL-C to kill the client.



Replace lambda execution role for the script `upload.sh`:

``` bash
export lambda_execution_role_arn="arn:aws:iam::************:role/lambda_exec_role"
```

Prepare and upload function to the AWS Lambda service with:

``` bash
./upload.sh
```

Now in one terminal window run:

``` bash
mqtt_sub 1883 test.mosquitto.org my-topic
```

or alternatively using mosquitto CLI client:

``` bash
mosquitto_sub -h test.mosquitto.org -t my-topic -v
```


We subscribed and listening to all messages published to MQTT topic `my-topic`. 


The lambda function expects custom events like this (see `event-mqtt.json` file):

``` json
{
	"topic": "my-topic",
	"value": "hello, lambda!",
	"retain": false
}
```

In another terminal window let's invoke lambda function with:

``` bash
aws lambda invoke-async --function-name "lambda-mqtt-test" --invoke-args event-mqtt.json
```

You should receive the message in the first terminal.

Testing lambda function locally (using CoffeeScript):

``` bash
coffee index.coffee
```

or using Javascript:

``` bash
node index.js
```
<commit_msg>use correct filenames for test scripts<commit_after># lambda-mqtt-test

AWS Lambda which function as a brdge between custom events and MQTT Broker.

We use this public MQTT broker for testing:
- http://test.mosquitto.org/

We use following npm module which implements MQTT client for Node.js:
- https://www.npmjs.org/package/mqtt

We'll need an MQTT CLI client.
We can use one that comes with Mosquitto MQTT broker:
- http://mosquitto.org/download/

Or we can use the MQTT CLI client that comes with `mqtt` npm module (which is much easier to install):

``` bash
npm install -g mqtt
```

Test that it works:

``` bash
mqtt_sub 1883 test.mosquitto.org '#'
...
<topic> <value>
...
CTRL-C
```

or same thing with mosquitto CLI client:

``` bash
mosquitto_sub -h test.mosquitto.org -t '#' -v
```


You should receive a bunch of messages. Press CTRL-C to kill the client.



Replace lambda execution role for the script `upload.sh`:

``` bash
export lambda_execution_role_arn="arn:aws:iam::************:role/lambda_exec_role"
```

Prepare and upload function to the AWS Lambda service with:

``` bash
./upload.sh
```

Now in one terminal window run:

``` bash
mqtt_sub 1883 test.mosquitto.org my-topic
```

or alternatively using mosquitto CLI client:

``` bash
mosquitto_sub -h test.mosquitto.org -t my-topic -v
```


We subscribed and listening to all messages published to MQTT topic `my-topic`. 


The lambda function expects custom events like this (see `event-mqtt.json` file):

``` json
{
	"topic": "my-topic",
	"value": "hello, lambda!",
	"retain": false
}
```

In another terminal window let's invoke lambda function with:

``` bash
aws lambda invoke-async --function-name "lambda-mqtt-test" --invoke-args event-mqtt.json
```

You should receive the message in the first terminal.

Testing lambda function locally (using CoffeeScript):

``` bash
coffee index_test.coffee
```

or using Javascript:

``` bash
node index_test.js
```

{'fraction_non_alphanumeric': 0.11948865118705974, 'fraction_numerical': 0.004174276024002087, 'mean_word_length': 4.031496062992126, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3328953', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1225, 'n_words': 473}