I try aws rekognition.I want to request and response through apigateway and lambda function.
Up: image down json of result which be trough rekognition.detectFaces.
detectFace method is bytes or S3Object as condition.
So I choose bytes which encoded by Buffer
.
lambda function code by node.js is under. Result is null(return(data) of rekognition.detectFaces)
It is sure of 'bytes' is.
What does I do now?
2021-01-10T01:23:56.087Z ab357778-9513-4988-8616-4fda1250a14e INFO { Attributes: [ 'DEFAULT' ], Image: { Bytes: <Buffer 2d 2d 2d 2d 2d 2d 57 65 62 4b 69 74 46 6f 72 6d 42 6f 75 6e 64 61 72 79 37 33 51 4b 39 44 51 55 6b 58 79 4c 58 42 59 47 0d 0a 43 6f 6e 74 65 6e 74 2d ... 1861180 more bytes> }}
const aws = require('aws-sdk');
const rekognition = new aws.Rekognition();
exports.handler = async (event) => {
//console.log(event.body);
const buf = new Buffer.from(event.body,'base64');
console.log(Buffer.byteLength(buf)); //under 5mbytes
console.log(Buffer.isBuffer(buf)); //true
//regix for cut 'Buffer<>' not working
//const re = "/^<Buffer$/";
//const reLast = "/>$/";
//const encode1 = buf.toString().replace(re, "");
//const encode = encode1.replace(reLast, "");
//console.log(encode);
//console.log(parseInt(encode,16));
const params = {
"Attributes": [ "DEFAULT" ],
"Image": {
"Bytes": buf,
}
};
console.log(params);
rekognition.detectFaces(params, function(err, data) {
console.log("Is it in this function?");
if (err) console.log(err, err.stack);
else console.log(data);
const faceData = data;
const response = {
statusCode: 200,
body: JSON.stringify(faceData),
};
return response;
});
};