use of software.amazon.lambda.powertools.logging.Logging in project di-ipv-cri-address-api by alphagov.
the class SessionHandler method handleRequest.
@Override
@Logging(correlationIdPath = CorrelationIdPathConstants.API_GATEWAY_REST)
@Metrics(captureColdStart = true)
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
try {
SessionRequest sessionRequest = addressSessionService.validateSessionRequest(input.getBody());
eventProbe.addDimensions(Map.of("issuer", sessionRequest.getClientId()));
UUID sessionId = addressSessionService.createAndSaveAddressSession(sessionRequest);
eventProbe.counterMetric(EVENT_SESSION_CREATED).auditEvent(sessionRequest);
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_CREATED, Map.of(SESSION_ID, sessionId.toString()));
} catch (SessionValidationException e) {
eventProbe.log(INFO, e).counterMetric(EVENT_SESSION_CREATED, 0d);
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_BAD_REQUEST, ErrorResponse.SESSION_VALIDATION_ERROR);
} catch (ClientConfigurationException e) {
eventProbe.log(ERROR, e).counterMetric(EVENT_SESSION_CREATED, 0d);
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorResponse.SERVER_CONFIG_ERROR);
}
}
use of software.amazon.lambda.powertools.logging.Logging in project aws-lambda-powertools-java by awslabs.
the class TracingLoggingStreamMessageHandler method handleRequest.
@Logging(logEvent = true)
@Tracing
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(output, mapper.readValue(input, Map.class));
}
use of software.amazon.lambda.powertools.logging.Logging in project serverless-webapp-mono-repo-ci-cd-java by aws-samples.
the class CreateCollectionHandler method handleRequest.
@Logging(logEvent = true)
public APIGatewayProxyResponseEvent handleRequest(final Map<String, Object> input, final Context context) {
String collectionId = (String) ((Map) input.get("ResourceProperties")).get("CollectionName");
if ("Delete".equals(input.get("RequestType"))) {
callGracefully(input, context, () -> {
DeleteCollectionResponse deleteCollectionResponse = client.deleteCollection(DeleteCollectionRequest.builder().collectionId(collectionId).build());
if (deleteCollectionResponse.statusCode() == 200) {
LOG.info("Resource deleted");
sendResponse(input, context, "SUCCESS");
}
});
} else {
callGracefully(input, context, () -> {
CreateCollectionResponse response = client.createCollection(CreateCollectionRequest.builder().collectionId(collectionId).build());
if (response.statusCode() == 200) {
LOG.info("Resource created");
sendResponse(input, context, "SUCCESS");
}
});
}
return null;
}
use of software.amazon.lambda.powertools.logging.Logging in project aws-lambda-powertools-examples by aws-samples.
the class AppStream method handleRequest.
@Override
@Logging(logEvent = true)
@Metrics(namespace = "ServerlessAirline", service = "payment", captureColdStart = true)
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
Map map = mapper.readValue(input, Map.class);
System.out.println(map.size());
}
use of software.amazon.lambda.powertools.logging.Logging in project aws-lambda-powertools-examples by aws-samples.
the class SqsMessageSender method handleRequest.
@Logging(logEvent = true)
public String handleRequest(final ScheduledEvent input, final Context context) {
String queueUrl = System.getenv("QUEUE_URL");
// Push 5 messages on each invoke.
List<SendMessageBatchRequestEntry> batchRequestEntries = IntStream.range(0, 5).mapToObj(value -> {
Map<String, MessageAttributeValue> attributeValueHashMap = new HashMap<>();
attributeValueHashMap.put("Key" + value, MessageAttributeValue.builder().dataType("String").stringValue("Value" + value).build());
byte[] array = new byte[7];
random.nextBytes(array);
return SendMessageBatchRequestEntry.builder().messageAttributes(attributeValueHashMap).id(input.getId() + value).messageBody("Sample Message " + value).build();
}).collect(toList());
SendMessageBatchResponse sendMessageBatchResponse = sqsClient.sendMessageBatch(SendMessageBatchRequest.builder().queueUrl(queueUrl).entries(batchRequestEntries).build());
log.info("Sent Message {}", sendMessageBatchResponse);
return "Success";
}
Aggregations