-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_client.cpp
52 lines (40 loc) · 1.37 KB
/
http_client.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <cstdlib>
#include <iostream>
#include <memory>
#include <vector>
#include <argparse/argparse.hpp>
#include <cppless/provider/aws/lambda.hpp>
#include <cppless/utils/beast/http_request_session.hpp>
#include <cppless/utils/tracing.hpp>
#include <nlohmann/json.hpp>
auto main(int argc, char* argv[]) -> int
{
std::string function_name = "echo";
std::string qualifier = "$LATEST";
std::string payload = R"({"test":42})";
cppless::aws::lambda::client lambda_client;
auto key = lambda_client.create_derived_key_from_env();
boost::asio::io_context ioc;
boost::system::error_code ec;
boost::asio::ssl::context tls(boost::asio::ssl::context::tlsv12_client);
tls.set_default_verify_paths();
cppless::beast::resolver_session resolver(ioc);
resolver.run(lambda_client.hostname(), "443");
cppless::aws::lambda::beast_invocation_request req {
function_name,
qualifier,
payload,
};
auto cb = [](const cppless::aws::lambda::invocation_response& res)
{
std::cout << "request_id: " << res.request_id << std::endl;
std::cout << res.body << std::endl;
};
req.on_result(cb);
cppless::tracing_span_container span_container;
auto root = span_container.create_root("lambda_invocation");
req.submit(resolver, ioc, tls, lambda_client, key, root);
ioc.run();
nlohmann::json j = span_container;
std::cout << j.dump(2) << std::endl;
}