-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eugene Freiman
committed
Nov 30, 2020
1 parent
cd1a0db
commit 488822c
Showing
7 changed files
with
86 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,40 @@ | ||
package service; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.LambdaLogger; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
import com.amazonaws.services.lambda.runtime.events.ScheduledEvent; | ||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; | ||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; | ||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.inject.Guice; | ||
import com.google.inject.Injector; | ||
|
||
/** | ||
* Handler for requests to Lambda function. | ||
*/ | ||
public class Handler implements RequestHandler<ScheduledEvent, String> { | ||
public class Handler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { | ||
|
||
private Injector injector = Guice.createInjector(new GuiceModule()); | ||
private Service service = injector.getInstance(Service.class); | ||
|
||
@Override | ||
public String handleRequest(ScheduledEvent event, Context context) { | ||
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) { | ||
|
||
final LambdaLogger logger = context.getLogger(); | ||
logger.log(String.format("Input event: %s", event.toString())); | ||
try { | ||
service.serve(context, logger); | ||
service.serve(event, context, logger); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
throw new RuntimeException(e.getMessage(), e); | ||
} | ||
return "200 OK"; | ||
|
||
return new APIGatewayProxyResponseEvent() | ||
.withStatusCode(200) | ||
.withHeaders(Collections.emptyMap()) | ||
.withBody("{\"message\":\"success\"}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters