use of com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage in project aws-doc-sdk-examples by awsdocs.
the class SQSEventDeserializer method deserialize.
@Override
public SQSEvent deserialize(JsonElement eventJson, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
SQSEvent event = new SQSEvent();
logger.info("DESERIALIZING TEST EVENT");
logger.info("EVENT JSON: " + eventJson.toString());
// Records key is capitalized in test event, but lowercase in type
JsonArray recordsArray = eventJson.getAsJsonObject().get("Records").getAsJsonArray();
ArrayList<SQSMessage> records = gson.fromJson(recordsArray, sqsMessageArray);
event.setRecords(records);
return event;
}
use of com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage in project aws-doc-sdk-examples by awsdocs.
the class Handler method handleRequest.
@Override
public String handleRequest(SQSEvent event, Context context) {
String response = new String();
// call Lambda API
logger.info("Getting account settings");
CompletableFuture<GetAccountSettingsResponse> accountSettings = lambdaClient.getAccountSettings(GetAccountSettingsRequest.builder().build());
// log execution details
logger.info("ENVIRONMENT VARIABLES: {}", gson.toJson(System.getenv()));
logger.info("CONTEXT: {}", gson.toJson(context));
logger.info("EVENT: {}", gson.toJson(event));
// process event
for (SQSMessage msg : event.getRecords()) {
logger.info(msg.getBody());
}
// process Lambda API response
try {
GetAccountSettingsResponse settings = accountSettings.get();
response = gson.toJson(settings.accountUsage());
logger.info("Account usage: {}", response);
} catch (Exception e) {
e.getStackTrace();
}
return response;
}
Aggregations