AWS Rekognition Validation Error when trying to use RecognizeCelebrities - amazon-web-services

I have been trying to experiment with the AWS Rekognition but I have been encountering a really weird bug. I keep getting a validation error but I have no Idea why.
Here is my code:
const client = new RekognitionClient({
region: "us-east-2",
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
});
const image = await imageToBase64("../tests/photos/testImage.jpg");
// const image = fs.readFileSync("../tests/photos/testImage.jpg");
// console.log(image);
const params = {
Image: {
Bytes: image,
},
};
console.log(JSON.stringify(params));
const command = new RecognizeCelebritiesCommand(JSON.stringify(params));
console.log(command);
try {
const data = await client.send(command);
} catch (e) {
console.log(e.message);
}
Here is the console log of the command variable:
RecognizeCelebritiesCommand {
middlewareStack: {
add: [Function: add],
addRelativeTo: [Function: addRelativeTo],
clone: [Function: clone],
use: [Function: use],
remove: [Function: remove],
removeByTag: [Function: removeByTag],
concat: [Function: concat],
applyToStack: [Function: cloneTo],
identify: [Function: identify],
resolve: [Function: resolve]
},
input: '{"Image":{"Bytes":"/9j/4AAQSkZJRgABAQEAeAB4AAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAFCAecDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW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b8qK8B+MXhkJM8ioAc+le8W+tI0HJHSvPPieYry0ZsA8V2VYqUDKEtUfKdynlyMvcGrOh3Qtb6NyejZp2vRiG8k2+tZayFTmvnpaM9ZH2V8I/iTBZwwq0gxgc5r2e8+MGmrYgPMucetfnRpniy60vHlSED61dn+JGpzY3ytge9JTsdC2PrPxd8RbbULhvKcHnsa5ubxlcxx/upGB9QcV4B4c8ayT3o89iefWvY9DuLXVLUAlQ2OM1zylzPU9KjrHQbb/ABt1vwvqhlW5kMfQqxJr0G0/bTNjpoLo7zAfd7V8/eP4RHM+3jFeVXbyLIfmJGavRq5wVeaMrNnr3xG/aU1jxnqE7MgWBmyFrze78ZXN5ksu3Nc+3zdaFWrUjmN/TtWfztxbnNeo+E/FHCqWOceteO6dA80mErrtMs7qyYSYOKiT0NqN+ZHsd9ff2hbY+9xXnOvaWJX27c5NamlaszKAzEH0qYMlxexgjOTXEr8x61azgUfDvgGS7kQhTXr3h/wI1na5KHOOldF8N/DcNwkbMnUV7JJ4OiGl7kXnbX1uHp+4mfI1pPnsfNfiG1a1VYz1orq/F/h9/thHGAaKctyEfG2tXjzSHJ/WsdY2fOBV1lN1JgGuh8P+FXvmGFOPpXzHMon0Kpyqu6OesLeRZASpwa+gvgTcz2GoRyxZUg9a4VPBrIQApI+leqfDPSZNMmiAUj6iuOvWtGyOzD4Zqa5j7M8H/ECW10+FZJcHHU1rX3xMTax8zdXkmk21xcWqcbRirkmjyNyc15Wsj6FRSWh02ofEJ7hm2cLWd/wmj+pNYc2nmFcFfxqW18PtMm4DiupPSxlbUbr/AImN3avuOe1eKeMLe'... 26614 more characters
}
I am getting "validation error detected: Value null at 'image' failed to satisfy constraint: Member must not be null" when I run this code. I have tried passing the image in as a bitmap and base64 string to no avail. The image that I am using is less than 5Mbs and is a jpg file.
Thanks!

Look at the JS rekognition example in AWS Github. This shows you how to successfully pass an image to a rekognition operation using the AWS SDK for JavaScript version 3 API.
See:
https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/rekognition/estimate-age-example/src/estimate-age.js

Related

aws-sdk in android react native setup

I came across a strange issue while using aws-sdk package in my app in android. We are using this in order to sign and upload pictures to S3. In iOS everything is working as expected but on android it return with this error
[MissingRequiredParameter: Missing required key 'Bucket' in params]
This is our setup
export const s3bucket = new S3({
accessKeyId: S3_ACCESS_KEY,
secretAccessKey: S3_SECRET_KEY,
Bucket: 'assets',
signatureVersion: 'v4',
});
Here we call the function
s3bucket.createBucket(e => {
// With this setup, each time the user uploads an image, will be overwritten
// To prevent this, use a different Key each time.
// This won't be needed if they're uploading their avatar, hence the filename, userAvatar.js.
const params = {
Bucket: 'assets',
Key: file.name, // type is not required
Body: base64Data,
ACL: 'public-read',
ContentEncoding: 'base64', // required
ContentType: contentType, // required. Notice the back ticks
};
s3bucket.upload(params, (err, data) => {
console.log(err, data);
if (err) {
alert('We are sorry there seem to be a problem. Please try again!');
}
if (currentIndex === -1) {
const newDocument = {
path: data.Location,
page: allDocumentPages.length + 1,
status: '',
id_type: allDocumentPages[0].id_type,
};
setAllDocumentPages([...allDocumentPages, newDocument]);
} else {
const documentToUpdate = allDocumentPages[currentIndex];
documentToUpdate.path = data.Location;
documentToUpdate.status = '';
}
setLoadingIndex(null);
});
});
Is there anything I miss?
I believe the missing 'Bucket' parameter is coming from the createBucket method, where its params object was not defined, as seen from the S3 documentation. You should re-define it as such.
export const s3bucket = new S3({
accessKeyId: S3_ACCESS_KEY,
secretAccessKey: S3_SECRET_KEY,
// Bucket: 'assets', <-- this will be ignored while defining the S3 options.
signatureVersion: 'v4',
});
// added a `params1` variable since `params` has been taken up.
var params1 = {
Bucket: 'assets'
};
s3bucket.createBucket(params1, e => {
...
};

The correct way to use new DocumentClient()

I see the following error occasionally in my ec2 instance that uses DynamoDB heavily
{ message: 'Could not load credentials from any providers',
code: 'CredentialsError',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2018-07-05T10:02:37.690Z,
originalError:
{ code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
message: 'connect ECONNREFUSED 169.254.169.254:80' } } }
The way I am using the AWS sdk to connect and get data from DynamoDB is like the following
'use strict'
const BluebirdPromise = require('bluebird')
AWS.config.setPromisesDependency(BluebirdPromise)
const DocumentClient = AWS.DynamoDB.DocumentClient
class DynamoOne {
get({
key
}) {
return new DocumentClient().get({ // creating new instance every time i want to get Item
Key: key,
TableName: 'TABLE_NAME',
ConsistentRead: consistent,
})
.promise()
.catch(e => console.trace(key, e))
}
}
new DynamoOne.get({
id: 1
}).then((item) => {
console.log(1, item)
})
Is this the correct way to use it ? or I should create new DocumentClient() once and use it all over , like the following code
'use strict'
const BluebirdPromise = require('bluebird')
AWS.config.setPromisesDependency(BluebirdPromise)
const DocumentClient = new AWS.DynamoDB.DocumentClient() // creating new instance once
class DynamoTwo {
get({
key
}) {
return DocumentClient.get({ // reuse DocumentClient
Key: key,
TableName: 'TABLE_NAME',
ConsistentRead: consistent,
})
.promise()
.catch(e => console.trace(key, e))
}
}
new DynamoTwo.get({
id: 1
}).then((item) => {
console.log(1, item)
})
Which one is the correct one DynamoOne or DynamoTwo ?
After researching and asking in github aws repo
I found that the correct way is to use DynamoTwo

"Converting circular structure to JSON" while reading data from MYSQL and putting it in DynamoDB

I am reading data from read replica of Aurora and putting it into the DynamoDB. I getting data from RDS correctly but facing problems while inserting it into DynamoDB. I am sharing my code and error message please guide me....
var AWS = require("aws-sdk");
var mysql = require('mysql');
const client = new AWS.DynamoDB.DocumentClient({region : 'eu-west-1'});
var connection = mysql.createPool({
host : "**********",
user : "****",
password : "*****",
database : "mydb",
port : "3306"
});
exports.handler = (event, context, callback) => {
connection.query('select * from demo where id=2;', function (error, results, fields) {
if (error) {
if (error) throw error;
} else {
var data = {results};
var params = {
Item:{
test_id:data.id,
name:data.name,
result:data.result
},
TableName: 'demo_rds_dynamoDB'
};
connection.end(function (err) {
callback(err, client.put(params, function(error,data){
if(error){
callback(error,null);
}else{
callback(null,data);
}
})
);
});
}
});
};
Following is the data I am getting from Aurora and I want to put in DynamoDB
Response:
[
{
"id": 2,
"name": "Display",
"result": "Pass"
}
]
And the response m getting is as follow and sometimes i get error as Cannot read property "id" undefined,
Response:
{
"errorMessage": "Converting circular structure to JSON",
"errorType": "TypeError",
"stackTrace": []
}
Request ID:
"896a64e3-573e-11e8-bb94-67c4be71eb3d"
Function Logs:
START RequestId: 896a64e3-573e-11e8-bb94-67c4be71eb3d Version: $LATEST
Unable to stringify response body as json: Converting circular structure to JSON: TypeError
at Object.stringify (native)
Item:{
test_id:results[0].id,
name:results[0].name,
result:results[0].result
}
results[0].columnname

How dis you get oauth-1.0a and crypto to work with WP-API

I am using crypto and oauth-1.0a from nmp in ionic2 application. I want to access WP-API which is correctly set to handle authentication, I tested this using Postman.
Http.Get results in the following error:
{
"_body": {
"isTrusted": true
},
"status": 0,
"ok": false,
"statusText": "",
"headers": {},
"type": 3,
"url": null
}
The options generated that I pass as argument to Http.Get are as follows:
{“method”:0,“headers”:{“Authorization”:“OAuth oauth_consumer_key=”",
oauth_nonce=“jSZGPwkj4quRGMb0bhBLYKwmc3BGfrQw”, oauth_signature=“x3zseS3XTFBLMsNDLXC4byn2UDI%3D”,
oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1522414816”,
oauth_token="",
oauth_version=“1.0"”},“body”:null,“url”:"",“params”:{“rawParams”:"",“queryEncoder”:{},“paramsMap”:{}},“withCredentials”:null,“responseType”:null}
Part of code:
this.oauth = new OAuth({
consumer: {
key: this.apiconstant.consumerkey,
secret: this.apiconstant.consumersecret
},
signature_method: ‘HMAC-SHA1’,
hash_function: hash_function_sha1,
realm:’’
});
let request_data = {
url: ‘’,
method: ‘GET’
};
let token={
key: this.apiconstant.token,
secret: this.apiconstant.tokensecret
}
//This part doesn’t seem to work
this.authkey = this.oauth.authorize(request_data,token);
this.keyoauth = new URLSearchParams();
for (let param in this.authkey) {
this.keyoauth.set(param, this.authkey[param]);
}
let options = new RequestOptions({
method: ‘GET’,//request_data.method
url: ‘’,
headers: this.oauth.toHeader(this.oauth.authorize(request_data,token)),
search: this.keyoauth
});
this.http.get(’’,options)
.map(res => res.json()).subscribe(data=>{
console.log(‘Resulting data’ + JSON.stringify(data));
},
error=>{
console.log(‘Got error’+JSON.stringify(error));
});
//Error part executed
What am I missing here? I’m testing my app on android device. Without authentication I get desired results from the WP-API (Wordpress), that is if the Oauth is disabled on WP-API.
Please help! This is my second day on this. I should also let you know I’m new on these technologies but I’m able to research and understand how they work.

Why is request.auth.session undefined?

I've created an auth strategy using bell and another using hapi-auth-cookie. However, when I try to set a session request.auth.session is undefined. Can someone help me figure out where I am going wrong?
My route:
module.exports = [
{
method: 'GET',
path: '/create-an-account',
config: {
auth: {
strategy: 'auth0',
mode: 'try'
}
},
handler: function(request, reply) {
var credentials = request.auth.credentials;
request.auth.session.set(credentials);
return reply.view('create-an-account');
}
}
]
My auth strategies:
exports.register = function (server, options, next) {
server.register([Bell, Cookie], function (err) {
server.auth.strategy('auth0', 'bell', {
provider: 'auth0',
config: {
domain: process.env.AUTH0_CLIENT_DOMAIN,
},
password: 'cookie_encryption_password_secure',
clientId: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
isSecure: false // For developing locally
});
server.auth.strategy('session', 'cookie', {
password: 'cookie_encryption_password_secure',
cookie: 'sid',
redirectTo: '/create-an-account',
redirectOnTry: false,
isSecure: false
});
});
return next();
};
We had this issue a little while ago on one of our projects. Hapi-auth-cookie have changed their documentation so they longer use request.auth.session.set(credentials);
Here's a link to the commit
If you change that line to request.cookieAuth.set() instead it should work. A lot of the examples online seem to use the old example which is how we missed it first time.
This was also picked up in another SO answer here > request.auth.session.set(user_info) not working HapiJS