Search in sources :

Example 31 with LambdaLogger

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 "";
}
Also used : IOException(java.io.IOException) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger)

Example 32 with LambdaLogger

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;
}
Also used : LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger)

Example 33 with LambdaLogger

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;
}
Also used : ArrayList(java.util.ArrayList) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger)

Example 34 with LambdaLogger

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;
}
Also used : ArrayList(java.util.ArrayList) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger)

Example 35 with LambdaLogger

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);
}
Also used : GetLabelDetectionRequest(com.amazonaws.services.rekognition.model.GetLabelDetectionRequest) AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) GetLabelDetectionResult(com.amazonaws.services.rekognition.model.GetLabelDetectionResult) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger) VideoMetadata(com.amazonaws.services.rekognition.model.VideoMetadata) LabelDetection(com.amazonaws.services.rekognition.model.LabelDetection)

Aggregations

LambdaLogger (com.amazonaws.services.lambda.runtime.LambdaLogger)59 HashMap (java.util.HashMap)10 Date (java.util.Date)9 List (java.util.List)8 Map (java.util.Map)8 Context (com.amazonaws.services.lambda.runtime.Context)6 ApiAuthorizer (com.formkiq.lambda.apigateway.ApiAuthorizer)6 ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)6 ApiGatewayRequestEventUtil (com.formkiq.lambda.apigateway.ApiGatewayRequestEventUtil)6 ApiGatewayRequestHandler (com.formkiq.lambda.apigateway.ApiGatewayRequestHandler)6 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)6 IOException (java.io.IOException)6 SC_OK (com.formkiq.lambda.apigateway.ApiResponseStatus.SC_OK)5 AwsServiceCache (com.formkiq.lambda.apigateway.AwsServiceCache)5 BadException (com.formkiq.lambda.apigateway.exception.BadException)5 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)5 Collectors (java.util.stream.Collectors)5 ClientContext (com.amazonaws.services.lambda.runtime.ClientContext)4 CognitoIdentity (com.amazonaws.services.lambda.runtime.CognitoIdentity)4 ApiMapResponse (com.formkiq.lambda.apigateway.ApiMapResponse)4