@@ -42,6 +42,7 @@ static constexpr auto COGNITO_IDENTITY_HEADER = "lambda-runtime-cognito-identity
4242static constexpr auto DEADLINE_MS_HEADER = " lambda-runtime-deadline-ms" ;
4343static constexpr auto FUNCTION_ARN_HEADER = " lambda-runtime-invoked-function-arn" ;
4444static constexpr auto TENANT_ID_HEADER = " lambda-runtime-aws-tenant-id" ;
45+ static constexpr auto INVOCATION_ID_HEADER = " lambda-runtime-invocation-id" ;
4546struct curl_handle_wrapper {
4647 CURL * handle;
4748 curl_handle_wrapper () : handle(curl_easy_init()) {}
@@ -318,6 +319,11 @@ runtime::next_outcome runtime::get_next()
318319 req.tenant_id = std::move (out).get_result ();
319320 }
320321
322+ out = resp.get_header (INVOCATION_ID_HEADER );
323+ if (out.is_success ()) {
324+ req.invocation_id = std::move (out).get_result ();
325+ }
326+
321327 out = resp.get_header (DEADLINE_MS_HEADER );
322328 if (out.is_success ()) {
323329 auto const & deadline_string = std::move (out).get_result ();
@@ -335,18 +341,32 @@ runtime::next_outcome runtime::get_next()
335341 return {req};
336342}
337343
338- runtime::post_outcome runtime::post_success (std::string const & request_id, invocation_response const & handler_response)
344+ runtime::post_outcome runtime::post_success (
345+ std::string const & request_id,
346+ invocation_response const & handler_response,
347+ std::string const & invocation_id)
339348{
340349 std::string const url = m_endpoints[Endpoints::RESULT ] + request_id + " /response" ;
341350 return do_post (
342- url, handler_response.get_content_type (), handler_response.get_payload (), handler_response.get_xray_response ());
351+ url,
352+ handler_response.get_content_type (),
353+ handler_response.get_payload (),
354+ handler_response.get_xray_response (),
355+ invocation_id);
343356}
344357
345- runtime::post_outcome runtime::post_failure (std::string const & request_id, invocation_response const & handler_response)
358+ runtime::post_outcome runtime::post_failure (
359+ std::string const & request_id,
360+ invocation_response const & handler_response,
361+ std::string const & invocation_id)
346362{
347363 std::string const url = m_endpoints[Endpoints::RESULT ] + request_id + " /error" ;
348364 return do_post (
349- url, handler_response.get_content_type (), handler_response.get_payload (), handler_response.get_xray_response ());
365+ url,
366+ handler_response.get_content_type (),
367+ handler_response.get_payload (),
368+ handler_response.get_xray_response (),
369+ invocation_id);
350370}
351371
352372runtime::post_outcome runtime::post_init_error (runtime_response const & init_error_response)
@@ -363,7 +383,8 @@ runtime::post_outcome runtime::do_post(
363383 std::string const & url,
364384 std::string const & content_type,
365385 std::string const & payload,
366- std::string const & xray_response)
386+ std::string const & xray_response,
387+ std::string const & invocation_id)
367388{
368389 set_curl_post_result_options ();
369390 curl_easy_setopt (lambda_runtime::m_curl_handle, CURLOPT_URL , url.c_str ());
@@ -382,6 +403,10 @@ runtime::post_outcome runtime::do_post(
382403 headers = curl_slist_append (headers, " transfer-encoding:" );
383404 headers = curl_slist_append (headers, m_user_agent_header.c_str ());
384405
406+ if (!invocation_id.empty ()) {
407+ headers = curl_slist_append (headers, (std::string (INVOCATION_ID_HEADER ) + " : " + invocation_id).c_str ());
408+ }
409+
385410 logging::log_debug (
386411 LOG_TAG , " calculating content length... %s" , (" content-length: " + std::to_string (payload.length ())).c_str ());
387412 headers = curl_slist_append (headers, (" content-length: " + std::to_string (payload.length ())).c_str ());
@@ -479,13 +504,13 @@ void run_handler(std::function<invocation_response(invocation_request const&)> c
479504 logging::log_info (LOG_TAG , " Invoking user handler completed." );
480505
481506 if (res.is_success ()) {
482- const auto post_outcome = rt.post_success (req.request_id , res);
507+ const auto post_outcome = rt.post_success (req.request_id , res, req. invocation_id );
483508 if (!handle_post_outcome (post_outcome, req.request_id )) {
484509 return ; // TODO: implement a better retry strategy
485510 }
486511 }
487512 else {
488- const auto post_outcome = rt.post_failure (req.request_id , res);
513+ const auto post_outcome = rt.post_failure (req.request_id , res, req. invocation_id );
489514 if (!handle_post_outcome (post_outcome, req.request_id )) {
490515 return ; // TODO: implement a better retry strategy
491516 }
0 commit comments