Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where is lesson 3? #2

Open
ryanslabxyz opened this issue Mar 19, 2019 · 3 comments
Open

Where is lesson 3? #2

ryanslabxyz opened this issue Mar 19, 2019 · 3 comments

Comments

@ryanslabxyz
Copy link

Where is the code for the image-analiser-lambda?

@migueleiva
Copy link

migueleiva commented Mar 20, 2019

The code of lesson 3 has some small errors in the names of the variables.

var AWS = require('aws-sdk');

var rek = new AWS.Rekognition();

var sns = new AWS.SNS();

AWS.config.update({region: 'us-east-1'});

exports.handler = (event, context, callback) => {

console.log('Hello, this is nodejs!');

// Get the object from the event

var bucket = event['Records'][0]['s3']['bucket']['name'];

var imageName = event['Records'][0]['s3']['object']['key'];

detectLabels(bucket, imageName)

.then(function(response){

var params = {

Message: JSON.stringify(response['Labels']), /* required */

Subject: imageName,

TopicArn: 'arn:aws:sns:us-east-1:829788106713:extract-image-label-sns'

};

sns.publish(params, function(err, data) {

if (err) console.log(err, err.stack); // an error occurred

else console.log(data); // successful response

});

});

callback(null, 'Hello from Lambda');

};

function detectLabels(bucket, key) {

let params = {
Image: {
S3Object: {
Bucket: bucket,
Name: key
}
}
};
return rek.detectLabels(params).promise();
}

@ryanslabxyz
Copy link
Author

The code of lesson 3 has some small errors in the names of the variables.

var AWS = require('aws-sdk');

var rek = new AWS.Rekognition();

var sns = new AWS.SNS();

AWS.config.update({region: 'us-east-1'});

exports.handler = (event, context, callback) => {

console.log('Hello, this is nodejs!');

// Get the object from the event

var bucket = event['Records'][0]['s3']['bucket']['name'];

var imageName = event['Records'][0]['s3']['object']['key'];

detectLabels(bucket, imageName)

.then(function(response){

var params = {

Message: JSON.stringify(response['Labels']), /* required */

Subject: imageName,

TopicArn: 'arn:aws:sns:us-east-1:829788106713:extract-image-label-sns'

};

sns.publish(params, function(err, data) {

if (err) console.log(err, err.stack); // an error occurred

else console.log(data); // successful response

});

});

callback(null, 'Hello from Lambda');

};

function detectLabels(bucket, key) {

let params = {
Image: {
S3Object: {
Bucket: bucket,
Name: key
}
}
};
return rek.detectLabels(params).promise();
}

Does this code work?

@migueleiva
Copy link

Yes
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants