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();
Gson gson = new GsonBuilder().create();
// log execution details
logger.log("ENVIRONMENT VARIABLES: " + gson.toJson(System.getenv()));
logger.log("CONTEXT: " + gson.toJson(context));
// process event
logger.log("EVENT Data: " + gson.toJson(event));
String myCaseID = event.get("inputCaseID");
logger.log("CaseId44: " + myCaseID);
return myCaseID;
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project aws-doc-sdk-examples by awsdocs.
the class DocumentHandler method handleRequest.
public String handleRequest(Map<String, String> event, Context context) throws IOException, BiffException {
LambdaLogger logger = context.getLogger();
logger.log("Getting excel doc from the Amazon S3 bucket");
// Get the Amazon S3 bucket name and MS Excel file name.
String bucketName = event.get("bucketname");
String object = event.get("objectname");
// Get the XML that contains the Pop data.
ExcelService excel = new ExcelService();
String xml = excel.getData(bucketName, object);
return xml;
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project djl-demo by deepjavalibrary.
the class Handler method handleRequest.
@Override
public void handleRequest(InputStream is, OutputStream os, Context context) throws IOException {
LambdaLogger logger = context.getLogger();
String input = Utils.toString(is);
try {
Request request = GSON.fromJson(input, Request.class);
String base64Img = request.getImageData().split(",")[1];
byte[] imgBytes = Base64.getDecoder().decode(base64Img);
Image img;
try (ByteArrayInputStream bis = new ByteArrayInputStream(imgBytes)) {
ImageFactory factory = ImageFactory.getInstance();
img = factory.fromInputStream(bis);
}
Translator<Image, Classifications> translator = ImageClassificationTranslator.builder().addTransform(new ToTensor()).optFlag(Image.Flag.GRAYSCALE).optApplySoftmax(true).build();
Criteria<Image, Classifications> criteria = Criteria.builder().setTypes(Image.class, Classifications.class).optModelUrls("https://djl-ai.s3.amazonaws.com/resources/demo/pytorch/doodle_mobilenet.zip").optTranslator(translator).build();
ZooModel<Image, Classifications> model = ModelZoo.loadModel(criteria);
try (Predictor<Image, Classifications> predictor = model.newPredictor()) {
List<Classifications.Classification> result = predictor.predict(img).topK(5);
os.write(GSON.toJson(result).getBytes(StandardCharsets.UTF_8));
}
} catch (RuntimeException | ModelException | TranslateException e) {
logger.log("Failed handle input: " + input);
logger.log(e.toString());
String msg = "{\"status\": \"invoke failed: " + e.toString() + "\"}";
os.write(msg.getBytes(StandardCharsets.UTF_8));
}
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project amazon-neptune-tools by awslabs.
the class RunNeptuneExportSvc method run.
@Override
public void run() {
InputStream input = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
try {
new NeptuneExportLambda(rootPath, cleanRootPath, maxFileDescriptorCount).handleRequest(input, System.out, new Context() {
@Override
public String getAwsRequestId() {
throw new NotImplementedException();
}
@Override
public String getLogGroupName() {
throw new NotImplementedException();
}
@Override
public String getLogStreamName() {
throw new NotImplementedException();
}
@Override
public String getFunctionName() {
throw new NotImplementedException();
}
@Override
public String getFunctionVersion() {
throw new NotImplementedException();
}
@Override
public String getInvokedFunctionArn() {
throw new NotImplementedException();
}
@Override
public CognitoIdentity getIdentity() {
throw new NotImplementedException();
}
@Override
public ClientContext getClientContext() {
throw new NotImplementedException();
}
@Override
public int getRemainingTimeInMillis() {
throw new NotImplementedException();
}
@Override
public int getMemoryLimitInMB() {
throw new NotImplementedException();
}
@Override
public LambdaLogger getLogger() {
return new LambdaLogger() {
@Override
public void log(String s) {
System.out.println(s);
}
@Override
public void log(byte[] bytes) {
throw new NotImplementedException();
}
};
}
});
} catch (Exception e) {
e.printStackTrace();
System.err.println("An error occurred while exporting from Neptune: " + e.getMessage());
System.exit(-1);
}
System.exit(0);
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project amazon-neptune-tools by awslabs.
the class NeptuneEndpointsInfoLambda method handleRequest.
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
LambdaLogger logger = context.getLogger();
EndpointsType endpointsType = EndpointsType.ReadReplicas;
Scanner scanner = new Scanner(input);
if (scanner.hasNext()) {
String param = scanner.next().replace("\"", "");
if (!param.isEmpty()) {
endpointsType = EndpointsType.valueOf(param);
}
}
logger.log("EndpointsType: " + endpointsType);
Map<EndpointsSelector, Collection<String>> addressesMap = addresses.get();
for (Map.Entry<EndpointsSelector, Collection<String>> entry : addressesMap.entrySet()) {
logger.log(entry.getKey() + ": " + entry.getValue());
}
String results = String.join(",", addressesMap.get(endpointsType));
logger.log("Results: " + results);
try (Writer writer = new BufferedWriter(new OutputStreamWriter(output, UTF_8))) {
writer.write(results);
writer.flush();
}
}
Aggregations