use of com.amazonaws.services.lambda.runtime.LambdaLogger in project formkiq-core by formkiq.
the class DocumentsS3Update method handleRequest.
@Override
public Void handleRequest(final Map<String, Object> map, final Context context) {
LambdaLogger logger = context.getLogger();
try {
boolean debug = "true".equals(System.getenv("DEBUG"));
if (debug) {
String json = this.gson.toJson(map);
logger.log(json);
}
List<Map<String, Object>> list = processRecords(logger, map);
for (Map<String, Object> e : list) {
Object eventName = e.getOrDefault("eventName", null);
Object bucket = e.getOrDefault("s3bucket", null);
Object key = e.getOrDefault("s3key", null);
if (bucket != null && key != null) {
boolean create = eventName != null && eventName.toString().toLowerCase().contains("objectcreated");
boolean remove = eventName != null && eventName.toString().toLowerCase().contains("objectremove");
if (debug) {
logger.log(String.format("processing event %s for file %s in bucket %s", eventName, bucket, key));
}
if (remove) {
processS3Delete(logger, bucket.toString(), key.toString());
} else {
processS3File(logger, create, bucket.toString(), key.toString(), debug);
}
}
}
} catch (Exception e) {
e.printStackTrace();
sendToDlq(map);
}
return null;
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project formkiq-core by formkiq.
the class StagingS3Create method copyFile.
/**
* Copies Documentid to a new file that is a {@link UUID}.
*
* @param s3Client {@link S3Client}
* @param logger {@link LambdaLogger}
* @param bucket {@link String}
* @param originalkey {@link String}
* @param date {@link Date}
*/
private void copyFile(final S3Client s3Client, final LambdaLogger logger, final String bucket, final String originalkey, final Date date) {
String siteId = getSiteId(originalkey);
String key = resetDatabaseKey(siteId, originalkey);
boolean uuid = isUuid(key);
String documentId = uuid ? key : UUID.randomUUID().toString();
String destKey = createDatabaseKey(siteId, documentId);
logger.log(String.format("Copying %s from bucket %s to %s in bucket %s.", originalkey, bucket, destKey, this.documentsBucket));
S3ObjectMetadata metadata = this.s3.getObjectMetadata(s3Client, bucket, originalkey);
String username = metadata.getMetadata().entrySet().stream().filter(s -> s.getKey().equalsIgnoreCase("userid")).findFirst().map(s -> s.getValue()).orElse("System");
DynamicDocumentItem doc = new DynamicDocumentItem(Collections.emptyMap());
doc.setDocumentId(documentId);
doc.setContentLength(metadata.getContentLength());
doc.setContentType(metadata.getContentType());
doc.setUserId(username);
doc.setChecksum(metadata.getEtag());
doc.setInsertedDate(date);
if (!uuid) {
doc.setPath(key);
}
this.service.saveDocumentItemWithTag(siteId, doc);
this.s3.copyObject(s3Client, bucket, originalkey, this.documentsBucket, destKey, metadata.getContentType());
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project formkiq-core by formkiq.
the class WebhooksTagsRequestHandler method get.
@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsServices) throws Exception {
String siteId = authorizer.getSiteId();
String id = getPathParameter(event, "webhookId");
PaginationResults<DynamicObject> list = awsServices.webhookService().findTags(siteId, id, null);
List<Map<String, Object>> tags = list.getResults().stream().map(m -> {
Map<String, Object> map = new HashMap<>();
map.put("insertedDate", m.getString("inserteddate"));
map.put("webhookId", id);
map.put("type", m.getString("type"));
map.put("userId", m.getString("userId"));
map.put("value", m.getString("tagValue"));
map.put("key", m.getString("tagKey"));
return map;
}).collect(Collectors.toList());
return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(Map.of("tags", tags)));
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project formkiq-core by formkiq.
the class AbstractApiRequestHandler method handleRequest.
@Override
public void handleRequest(final InputStream input, final OutputStream output, final Context context) throws IOException {
LambdaLogger logger = context.getLogger();
ApiGatewayRequestEvent event = getApiGatewayEvent(input, logger, getAwsServices());
ApiAuthorizer authorizer = new ApiAuthorizer(event);
try {
ApiRequestHandlerResponse object = processRequest(logger, event, authorizer);
processResponse(authorizer, event, object);
buildResponse(logger, output, object.getStatus(), object.getHeaders(), object.getResponse());
} catch (NotFoundException e) {
buildResponse(logger, output, SC_NOT_FOUND, Collections.emptyMap(), new ApiResponseError(e.getMessage()));
} catch (TooManyRequestsException e) {
buildResponse(logger, output, SC_TOO_MANY_REQUESTS, Collections.emptyMap(), new ApiResponseError(e.getMessage()));
} catch (BadException | InvalidConditionsException | DateTimeException e) {
buildResponse(logger, output, SC_BAD_REQUEST, Collections.emptyMap(), new ApiResponseError(e.getMessage()));
} catch (ForbiddenException e) {
buildResponse(logger, output, SC_FORBIDDEN, Collections.emptyMap(), new ApiResponseError(e.getMessage()));
} catch (UnauthorizedException e) {
buildResponse(logger, output, SC_UNAUTHORIZED, Collections.emptyMap(), new ApiResponseError(e.getMessage()));
} catch (NotImplementedException e) {
buildResponse(logger, output, SC_NOT_IMPLEMENTED, Collections.emptyMap(), new ApiResponseError(e.getMessage()));
} catch (Exception e) {
logError(logger, e);
buildResponse(logger, output, SC_ERROR, Collections.emptyMap(), new ApiResponseError("Internal Server Error"));
}
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-lambda-developer-guide by awsdocs.
the class HandlerApiGateway method handleRequest.
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) {
LambdaLogger logger = context.getLogger();
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent();
response.setIsBase64Encoded(false);
response.setStatusCode(200);
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "text/html");
response.setHeaders(headers);
response.setBody("<!DOCTYPE html><html><head><title>AWS Lambda sample</title></head><body>" + "<h1>Welcome</h1><p>Page generated by a Lambda function.</p>" + "</body></html>");
// log execution details
Util.logEnvironment(event, context, gson);
return response;
}
Aggregations