Search in sources :

Example 16 with LambdaLogger

use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-lambda-developer-guide by awsdocs.

the class Handler method handleRequest.

@Override
public String handleRequest(Map<String, String> event, Context context) {
    LambdaLogger logger = context.getLogger();
    String response = new String("200 OK");
    // log execution details
    logger.log("ENVIRONMENT VARIABLES: " + gson.toJson(System.getenv()));
    logger.log("CONTEXT: " + gson.toJson(context));
    // process event
    logger.log("EVENT: " + gson.toJson(event));
    logger.log("EVENT TYPE: " + event.getClass().toString());
    return response;
}
Also used : LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger)

Example 17 with LambdaLogger

use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-lambda-developer-guide by awsdocs.

the class HandlerDivide method handleRequest.

@Override
public Integer handleRequest(List<Integer> event, Context context) {
    LambdaLogger logger = context.getLogger();
    // process event
    if (event.size() != 2) {
        throw new InputLengthException("Input must be an array that contains 2 numbers.");
    }
    int numerator = event.get(0);
    int denominator = event.get(1);
    logger.log("EVENT: " + gson.toJson(event));
    logger.log("EVENT TYPE: " + event.getClass().toString());
    return numerator / denominator;
}
Also used : LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger)

Example 18 with LambdaLogger

use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-lambda-developer-guide by awsdocs.

the class HandlerList method handleRequest.

@Override
public Integer handleRequest(List<Integer> event, Context context) {
    LambdaLogger logger = context.getLogger();
    // process event
    logger.log("EVENT: " + gson.toJson(event));
    logger.log("EVENT TYPE: " + event.getClass().toString());
    return context.getRemainingTimeInMillis();
}
Also used : LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger)

Example 19 with LambdaLogger

use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-lambda-developer-guide by awsdocs.

the class HandlerStream method handleRequest.

@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
    LambdaLogger logger = context.getLogger();
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("US-ASCII")));
    PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream, Charset.forName("US-ASCII"))));
    try {
        HashMap event = gson.fromJson(reader, HashMap.class);
        logger.log("STREAM TYPE: " + inputStream.getClass().toString());
        logger.log("EVENT TYPE: " + event.getClass().toString());
        writer.write(gson.toJson(event));
        if (writer.checkError()) {
            logger.log("WARNING: Writer encountered an error.");
        }
    } catch (IllegalStateException | JsonSyntaxException exception) {
        logger.log(exception.toString());
    } finally {
        reader.close();
        writer.close();
    }
}
Also used : IllegalStateException(java.lang.IllegalStateException) JsonSyntaxException(com.google.gson.JsonSyntaxException) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 20 with LambdaLogger

use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-lambda-developer-guide by awsdocs.

the class HandlerWeatherData method handleRequest.

@Override
public WeatherData handleRequest(WeatherData event, Context context) {
    LambdaLogger logger = context.getLogger();
    // process event
    logger.log("EVENT: " + gson.toJson(event));
    logger.log("EVENT TYPE: " + event.getClass().toString());
    return event;
}
Also used : LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger)

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