Search in sources :

Example 21 with LambdaLogger

use of com.amazonaws.services.lambda.runtime.LambdaLogger in project tutorials by csh0034.

the class APIGatewayEventHandler method handleRequest.

@Override
public String handleRequest(APIGatewayProxyRequestEvent input, Context context) {
    LambdaLogger logger = context.getLogger();
    logger.log("invoke APIGatewayEventHandler::handleRequest");
    return input.getBody();
}
Also used : LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger)

Example 22 with LambdaLogger

use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-java-serverless by hermanlintvelt.

the class RoadmapsHandlerTest method setUp.

@BeforeEach
public void setUp() {
    subject = new RoadmapsHandler();
    testContext = new Context() {

        @Override
        public String getAwsRequestId() {
            return null;
        }

        @Override
        public String getLogGroupName() {
            return null;
        }

        @Override
        public String getLogStreamName() {
            return null;
        }

        // implement all methods of this interface and setup your test context.
        // For instance, the function name:
        @Override
        public String getFunctionName() {
            return "ExampleAwsLambda";
        }

        @Override
        public String getFunctionVersion() {
            return null;
        }

        @Override
        public String getInvokedFunctionArn() {
            return null;
        }

        @Override
        public CognitoIdentity getIdentity() {
            return null;
        }

        @Override
        public ClientContext getClientContext() {
            return null;
        }

        @Override
        public int getRemainingTimeInMillis() {
            return 0;
        }

        @Override
        public int getMemoryLimitInMB() {
            return 0;
        }

        @Override
        public LambdaLogger getLogger() {
            return null;
        }
    };
}
Also used : Context(com.amazonaws.services.lambda.runtime.Context) ClientContext(com.amazonaws.services.lambda.runtime.ClientContext) ClientContext(com.amazonaws.services.lambda.runtime.ClientContext) CognitoIdentity(com.amazonaws.services.lambda.runtime.CognitoIdentity) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 23 with LambdaLogger

use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-java-serverless by hermanlintvelt.

the class HandlerTest method setUp.

@BeforeEach
public void setUp() {
    subject = new Handler();
    testContext = new Context() {

        @Override
        public String getAwsRequestId() {
            return null;
        }

        @Override
        public String getLogGroupName() {
            return null;
        }

        @Override
        public String getLogStreamName() {
            return null;
        }

        // implement all methods of this interface and setup your test context.
        // For instance, the function name:
        @Override
        public String getFunctionName() {
            return "ExampleAwsLambda";
        }

        @Override
        public String getFunctionVersion() {
            return null;
        }

        @Override
        public String getInvokedFunctionArn() {
            return null;
        }

        @Override
        public CognitoIdentity getIdentity() {
            return null;
        }

        @Override
        public ClientContext getClientContext() {
            return null;
        }

        @Override
        public int getRemainingTimeInMillis() {
            return 0;
        }

        @Override
        public int getMemoryLimitInMB() {
            return 0;
        }

        @Override
        public LambdaLogger getLogger() {
            return null;
        }
    };
}
Also used : Context(com.amazonaws.services.lambda.runtime.Context) ClientContext(com.amazonaws.services.lambda.runtime.ClientContext) ClientContext(com.amazonaws.services.lambda.runtime.ClientContext) CognitoIdentity(com.amazonaws.services.lambda.runtime.CognitoIdentity) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with LambdaLogger

use of com.amazonaws.services.lambda.runtime.LambdaLogger in project preston by bio-guoda.

the class AWSEventHandler method handleRequest.

@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
    LambdaLogger logger = context.getLogger();
    RequestData requestData = gson.fromJson(IOUtils.toString(inputStream, StandardCharsets.UTF_8), RequestData.class);
    logger.log("Received request with body " + gson.toJson(requestData));
    CmdGet get = new CmdGet();
    get.setDisableCache(true);
    get.setInputStream(IOUtils.toInputStream(requestData.id, StandardCharsets.UTF_8));
    get.setRemotes(Collections.singletonList(requestData.remote));
    get.setOutputStream(outputStream);
    get.run();
}
Also used : LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger) CmdGet(bio.guoda.preston.cmd.CmdGet)

Example 25 with LambdaLogger

use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-ingesting-click-logs-using-terraform by aws-samples.

the class ClickLoggerHandler method handleRequest.

@Override
public ClickLogResponse handleRequest(final ClickLogRequest clickLogRequest, final Context context) {
    final LambdaLogger logger = context.getLogger();
    final String success_response = new String("200 OK");
    final String fail_response = new String("200 OK");
    ResponseBuilder responseBuilder = new ResponseBuilder();
    ClickLogResponse response = responseBuilder.badRequest(fail_response).build();
    String req = clickLogRequest.getRequestid() + " - " + clickLogRequest.getCallerid() + "  - " + clickLogRequest.getComponent() + " - " + clickLogRequest.getType() + " - " + clickLogRequest.getAction() + " - " + clickLogRequest.getUser() + " - " + clickLogRequest.getClientip() + " - " + clickLogRequest.getCreatedtime();
    logger.log("Incoming request variables - " + req);
    String env_stream_name = System.getenv("STREAM_NAME");
    if (!StringUtils.isBlank(env_stream_name)) {
        stream_name = env_stream_name;
    }
    // System.getenv("REGION");
    String env_region = System.getenv("AWS_REGION");
    logger.log("Environment region name - " + env_region);
    if (!StringUtils.isBlank(env_region)) {
        region = env_region;
    }
    if (clickLogRequest != null) {
        logger.log("Validating inputs");
        if (StringUtils.isBlank(clickLogRequest.getRequestid())) {
            logger.log("error occurred - requestid missing");
            return response;
        }
        if (StringUtils.isBlank(clickLogRequest.getContextid())) {
            logger.log("error occurred - contextid missing");
            return response;
        }
        if (StringUtils.isBlank(clickLogRequest.getCallerid())) {
            logger.log("error occurred - caller missing");
            return response;
        }
        if (StringUtils.isBlank(clickLogRequest.getType())) {
            logger.log("error occurred - type missing");
            return response;
        }
        if (StringUtils.isBlank(clickLogRequest.getAction())) {
            logger.log("error occurred - action missing");
            return response;
        }
        if (StringUtils.isBlank(clickLogRequest.getComponent())) {
            logger.log("error occurred - component missing");
            return response;
        }
        String user = "GUEST";
        if (StringUtils.isBlank(clickLogRequest.getUser())) {
            logger.log("setting default user");
            clickLogRequest.setUser(user);
        }
        String clientip = "APIGWY";
        if (StringUtils.isBlank(clickLogRequest.getClientip())) {
            logger.log("setting default clientip");
            clickLogRequest.setClientip(clientip);
        }
        String datetime = "";
        if (StringUtils.isBlank(clickLogRequest.getCreatedtime())) {
            logger.log("setting default createdtime");
            Format f = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");
            datetime = f.format(new Date());
            clickLogRequest.setCreatedtime(datetime);
        }
        logger.log("Validated inputs");
    }
    System.out.println("Calling updateclicklogs method for the received clicklogrequest");
    updateClickLogRequestToStream(clickLogRequest);
    logger.log(success_response);
    responseBuilder = new ResponseBuilder();
    responseBuilder.ok();
    response = responseBuilder.originHeader("*").build();
    return response;
}
Also used : Format(java.text.Format) SimpleDateFormat(java.text.SimpleDateFormat) ClickLogResponse(com.clicklogs.model.ClickLogResponse) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger) ResponseBuilder(com.clicklogs.model.ResponseBuilder) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

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