Pi4J + Amazon S3 REST API + S3 Lambda Trigger + DynamoDB [P022]
5) IoT_DataPlatform/Amazon AWS 2018. 6. 17. 01:05Pi4J + Amazon S3 REST API + S3 Lambda Trigger + DynamoDB [P022]
https://www.youtube.com/watch?v=LHZBQmybbqc
GitHub : https://github.com/rdiot/rdiot-p022
* Parts
- Pi4J + Amazon S3 REST API + Amazon Athena [P019]
- Raspberry Pi2
- Temperature and humidity DHT11 sensor module (KY-015) [S008]
* Contents
1. S3 Upload
- Reference : Pi4J + Amazon S3 REST API + Amazon Athena [P019]
2. Run Java Application (pi4j)
- Source :
$ java -Dpi4j.linking=dynamic -jar pi4j_s3rest-0.0.1-SNAPSHOT.jar
3. S3 Storage Monitoring
4. AWS Lambda Monitoring
5. AWS DynamoDB Monitoring
6. AWS Lambda Source (node.js) : S3toDynamoDB
- source code : https://github.com/rdiot/rdiot-p022/blob/master/S3toDynamoDB/index.js
'use strict';
console.log('RDIoT S3toDynamoDB Loading post function');
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
var dynamo = new AWS.DynamoDB.DocumentClient();
exports.handler = function(event, context, callback) {
console.log('Received event:', JSON.stringify(event, null, 2));
var bucket = event.Records[0]['s3']['bucket']['name'];
var en = event.Records[0]['eventName'];
var et = event.Records[0]['eventTime'];
var key = event.Records[0]['s3']['object']['key'];
var sip = event.Records[0]['requestParameters']['sourceIPAddress'];
var params1 = {Bucket: bucket, Key: key};
s3.getObject( params1, function(err,data) {
if(err) {
console.log(err.stack);
callback(err);
} else {
var value = data.Body.toString('ascii')
console.log(data);
console.log("Raw text:\n" + value);
var params2 = {
TableName: "pi-sensor",
Item:{
"id": et,
"event" : en,
"bucket": bucket,
"key" : key,
"sip": sip,
"value" : value
}
};
console.log("Gettings IoT device details...");
//S3 to DynamoDB
dynamo.put(params2, function(err, data) {
if(err) {
console.error("Unable to post devices. Error JSON:", JSON.stringify(err, null, 2));
context.fail();
} else {
console.log("keepet data:", JSON.stringify(data, null, 2));
context.succeed('success post');
}
});
}
});
}
7. Lambda : s3 put event sample
8. Lambda : Context Sample
9. Lambda : S3 Object GET Data Sample
'5) IoT_DataPlatform > Amazon AWS' 카테고리의 다른 글
DynamoDB Stream + Amazon ES (ElasticSearch, Kibana) [P024] (0) | 2019.04.02 |
---|---|
S3 Lambda Trigger + Amazon SQS + SQSReceiver + SparkStreaming [P023] (0) | 2018.10.17 |
AWS IoT Core + Raspberry Pi + AWS IoT Device SDK for Java [P021] (0) | 2018.06.15 |
Pi4J + Amazon S3 REST API + Amazon Athena [P019] (0) | 2018.04.11 |
Amazon Polly + Google Home + Sonoff wifi [P018] (0) | 2018.04.04 |