| 5 | using namespace aws::lambda_runtime; |
| 6 | |
| 7 | invocation_response my_handler(invocation_request const& request) |
| 8 | { |
| 9 | |
| 10 | using namespace Aws::Utils::Json; |
| 11 | |
| 12 | JsonValue json(request.payload); |
| 13 | if (!json.WasParseSuccessful()) { |
| 14 | return invocation_response::failure("Failed to parse input JSON", "InvalidJSON"); |
| 15 | } |
| 16 | |
| 17 | auto v = json.View(); |
| 18 | Aws::SimpleStringStream ss; |
| 19 | ss << "Good "; |
| 20 | |
| 21 | if (v.ValueExists("body") && v.GetObject("body").IsString()) { |
| 22 | auto body = v.GetString("body"); |
| 23 | JsonValue body_json(body); |
| 24 | |
| 25 | if (body_json.WasParseSuccessful()) { |
| 26 | auto body_v = body_json.View(); |
| 27 | ss << (body_v.ValueExists("time") && body_v.GetObject("time").IsString() ? body_v.GetString("time") : ""); |
| 28 | } |
| 29 | } |
| 30 | ss << ", "; |
| 31 | |
| 32 | if (v.ValueExists("queryStringParameters")) { |
| 33 | auto query_params = v.GetObject("queryStringParameters"); |
| 34 | ss << (query_params.ValueExists("name") && query_params.GetObject("name").IsString() |
| 35 | ? query_params.GetString("name") |
| 36 | : "") |
| 37 | << " of "; |
| 38 | ss << (query_params.ValueExists("city") && query_params.GetObject("city").IsString() |
| 39 | ? query_params.GetString("city") |
| 40 | : "") |
| 41 | << ". "; |
| 42 | } |
| 43 | |
| 44 | if (v.ValueExists("headers")) { |
| 45 | auto headers = v.GetObject("headers"); |
| 46 | ss << "Happy " |
| 47 | << (headers.ValueExists("day") && headers.GetObject("day").IsString() ? headers.GetString("day") : "") |
| 48 | << "!"; |
| 49 | } |
| 50 | |
| 51 | JsonValue resp; |
| 52 | resp.WithString("message", ss.str()); |
| 53 | |
| 54 | return invocation_response::success(resp.View().WriteCompact(), "application/json"); |
| 55 | } |
| 56 | |
| 57 | int main() |
| 58 | { |