use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-doc-sdk-examples by awsdocs.
the class Handler3 method handleRequest.
@Override
public String handleRequest(String event, Context context) {
LambdaLogger logger = context.getLogger();
String email = event;
// log execution details
logger.log("Email value " + email);
SendMessage msg = new SendMessage();
try {
msg.sendMessage(email);
} catch (IOException e) {
e.getStackTrace();
}
return "";
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-doc-sdk-examples by awsdocs.
the class Handler method handleRequest.
public Void handleRequest(Context context) {
LambdaLogger logger = context.getLogger();
ScanEmployees scanEmployees = new ScanEmployees();
Boolean ans = scanEmployees.sendEmployeMessage();
if (ans)
logger.log("Messages sent: " + ans);
return null;
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-doc-sdk-examples by awsdocs.
the class PPEHandler method handleRequest.
@Override
public String handleRequest(Map<String, String> event, Context context) {
LambdaLogger logger = context.getLogger();
String bucketName = event.get("bucketName");
logger.log("Bucket name is: " + bucketName);
S3Service s3Service = new S3Service();
DynamoDBService ddb = new DynamoDBService();
AnalyzePhotos photos = new AnalyzePhotos();
SendEmail email = new SendEmail();
List<String> items = s3Service.listBucketObjects(bucketName);
List<ArrayList<GearItem>> myList = new ArrayList<>();
for (String item : items) {
byte[] keyData = s3Service.getObjectBytes(bucketName, item);
// Analyze the photo and return a list where each element is a WorkItem.
ArrayList<GearItem> gearItem = photos.detectLabels(keyData, item);
// Only add a list with items.
if (gearItem != null)
myList.add(gearItem);
}
ddb.persistItem(myList);
// Create a new list with only unique keys to email.
Set<String> unqiueKeys = createUniqueList(myList);
email.sendMsg(unqiueKeys);
logger.log("Updated the DynamoDB table with PPE data");
return bucketName;
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-doc-sdk-examples by awsdocs.
the class Handler method handleRequest.
@Override
public String handleRequest(Map<String, String> event, Context context) {
LambdaLogger logger = context.getLogger();
String delFag = event.get("flag");
logger.log("FLAG IS: " + delFag);
S3Service s3Service = new S3Service();
AnalyzePhotos photos = new AnalyzePhotos();
String bucketName = "<Enter your bucket name>";
List<String> myKeys = s3Service.listBucketObjects(bucketName);
if (delFag.compareTo("true") == 0) {
// Create a List to store the data.
List<ArrayList<WorkItem>> myList = new ArrayList<>();
// loop through each element in the List and tag the assets.
for (String key : myKeys) {
byte[] keyData = s3Service.getObjectBytes(bucketName, key);
// Analyze the photo and return a list where each element is a WorkItem.
ArrayList<WorkItem> item = photos.detectLabels(keyData, key);
myList.add(item);
}
s3Service.tagAssets(myList, bucketName);
logger.log("All Assets in the bucket are tagged!");
} else {
// Delete all object tags.
for (String key : myKeys) {
s3Service.deleteTagFromObject(bucketName, key);
logger.log("All Assets in the bucket are deleted!");
}
}
return delFag;
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-doc-sdk-examples by awsdocs.
the class JobCompletionHandler method GetResultsLabels.
void GetResultsLabels(String startJobId, Context context) throws Exception {
LambdaLogger logger = context.getLogger();
AmazonRekognition rek = AmazonRekognitionClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
int maxResults = 1000;
String paginationToken = null;
GetLabelDetectionResult labelDetectionResult = null;
String labels = "";
Integer labelsCount = 0;
String label = "";
String currentLabel = "";
// Get label detection results and log them.
do {
GetLabelDetectionRequest labelDetectionRequest = new GetLabelDetectionRequest().withJobId(startJobId).withSortBy(LabelDetectionSortBy.NAME).withMaxResults(maxResults).withNextToken(paginationToken);
labelDetectionResult = rek.getLabelDetection(labelDetectionRequest);
paginationToken = labelDetectionResult.getNextToken();
VideoMetadata videoMetaData = labelDetectionResult.getVideoMetadata();
// Add labels to log
List<LabelDetection> detectedLabels = labelDetectionResult.getLabels();
for (LabelDetection detectedLabel : detectedLabels) {
label = detectedLabel.getLabel().getName();
if (label.equals(currentLabel)) {
continue;
}
labels = labels + label + " / ";
currentLabel = label;
labelsCount++;
}
} while (labelDetectionResult != null && labelDetectionResult.getNextToken() != null);
logger.log("Total number of labels : " + labelsCount);
logger.log("labels : " + labels);
}
Aggregations