MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / my_handler

Function my_handler

examples/dynamodb/main.cpp:164–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162
163
164aws::lambda_runtime::invocation_response my_handler(
165 aws::lambda_runtime::invocation_request const& req,
166 Aws::DynamoDB::DynamoDBClient const& client)
167{
168 using namespace Aws::Utils::Json;
169 AWS_LOGSTREAM_DEBUG(TAG, "received payload: " << req.payload);
170 JsonValue eventJson(req.payload);
171 assert(eventJson.WasParseSuccessful());
172 const criteria cr(eventJson);
173 if (cr.error_msg) {
174 JsonValue response;
175 response.WithString("body", cr.error_msg).WithInteger("statusCode", 400);
176 auto apig_response = response.View().WriteCompact();
177 AWS_LOGSTREAM_ERROR(TAG, "Validation failed. " << apig_response);
178 return aws::lambda_runtime::invocation_response::success(std::move(apig_response), "application/json");
179 }
180
181 auto result = query(cr, client);
182 auto const query_response = result.View().WriteCompact();
183 AWS_LOGSTREAM_DEBUG(TAG, "query response: " << query_response);
184
185 JsonValue response;
186 if (result.View().ValueExists("product")) {
187 response.WithString("body", query_response).WithInteger("statusCode", 200);
188 }
189 else {
190 response.WithString("body", "No data found for this product.").WithInteger("statusCode", 400);
191 }
192
193 auto apig_response = response.View().WriteCompact();
194 AWS_LOGSTREAM_DEBUG(TAG, "api gateway response: " << apig_response);
195
196 return aws::lambda_runtime::invocation_response::success(std::move(apig_response), "application/json");
197}
198
199std::function<std::shared_ptr<Aws::Utils::Logging::LogSystemInterface>()> GetConsoleLoggerFactory()
200{

Callers 1

mainFunction · 0.70

Calls 1

queryFunction · 0.85

Tested by

no test coverage detected