Skip to content

Commit 17aea21

Browse files
Add SDK+CRT build script, small example dir
1 parent c33def2 commit 17aea21

5 files changed

Lines changed: 153 additions & 0 deletions

File tree

build.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
BUILD_DIR=$(realpath ./build)
4+
INSTALL_DIR=$(realpath ./install)
5+
6+
mkdir -p $BUILD_DIR
7+
8+
pushd $BUILD_DIR
9+
10+
cmake \
11+
-DCMAKE_BUILD_TYPE=Debug \
12+
-DCMAKE_PREFIX_PATH=$INSTALL_DIR \
13+
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
14+
-DBUILD_ONLY="sts" \
15+
-DBUILD_DEPS=ON \
16+
-DUSE_CRT_HTTP_CLIENT=ON \
17+
-DUSE_OPENSSL=OFF \
18+
..
19+
20+
cmake --build . --config=Debug
21+
22+
cmake --install . --config=Debug
23+
24+
25+
popd #BUILD_DIR

example/CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Set the minimum required version of CMake for this project.
5+
cmake_minimum_required(VERSION 3.13)
6+
7+
set(SERVICE_NAME sts)
8+
set(SERVICE_COMPONENTS sts)
9+
10+
# Set this project's name.
11+
project("${SERVICE_NAME}-examples")
12+
13+
# Set the C++ standard to use to build this target.
14+
set(CMAKE_CXX_STANDARD 11)
15+
16+
# Build shared libraries by default.
17+
set(BUILD_SHARED_LIBS ON)
18+
19+
# Enable CTest for testing these code examples.
20+
if(BUILD_TESTS)
21+
include(CTest)
22+
endif()
23+
24+
25+
# Find the AWS SDK for C++ package.
26+
find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS})
27+
28+
# AWSDOC_SOURCE can be defined in the command line to limit the files in a build. For example,
29+
# you can limit files to one action.
30+
if(NOT DEFINED AWSDOC_SOURCE)
31+
file(GLOB AWSDOC_SOURCE
32+
"*.cpp"
33+
)
34+
endif()
35+
36+
foreach(file ${AWSDOC_SOURCE})
37+
get_filename_component(EXAMPLE ${file} NAME_WE)
38+
39+
# Build the code example executables.
40+
set(EXAMPLE_EXE run_${EXAMPLE})
41+
42+
add_executable(${EXAMPLE_EXE} ${file})
43+
44+
target_link_libraries(${EXAMPLE_EXE} ${AWSSDK_LINK_LIBRARIES}
45+
${AWSSDK_PLATFORM_DEPS})
46+
47+
endforeach()

example/build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
3+
BUILD_DIR=$(realpath ./build)
4+
5+
mkdir -p $BUILD_DIR
6+
7+
pushd $BUILD_DIR
8+
9+
cmake \
10+
-DCMAKE_INSTALL_PREFIX=../install \
11+
-DCMAKE_PREFIX_PATH=../install \
12+
..
13+
14+
cmake --build . --config=Debug
15+
16+
popd #BUILD_DIR

example/example.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <aws/sts/STSClient.h>
2+
#include <aws/sts/model/GetCallerIdentityRequest.h>
3+
#include <aws/core/auth/AWSCredentialsProvider.h>
4+
#include <iostream>
5+
6+
#include "example.h"
7+
8+
bool AwsDoc::STS::getCallerIdentity(const Aws::Client::ClientConfiguration &clientConfig) {
9+
Aws::STS::STSClient sts(clientConfig);
10+
const Aws::STS::Model::GetCallerIdentityRequest req;
11+
12+
const Aws::STS::Model::GetCallerIdentityOutcome outcome = sts.GetCallerIdentity(req);
13+
14+
if (!outcome.IsSuccess()) {
15+
std::cerr << "Error getting caller identity. " <<
16+
outcome.GetError().GetMessage() << std::endl;
17+
} else {
18+
std::cout << "Caller identtiy successfully retrieved." << std::endl;
19+
const Aws::STS::Model::GetCallerIdentityResult result = outcome.GetResult();
20+
const Aws::String &arn = result.GetArn();
21+
std::cout << "ARN: " << arn << std::endl;
22+
}
23+
24+
const auto& headers = req.GetHeaders();
25+
//const auto it = headers.find(Aws::String("User-Agent"));
26+
//assert(it != headers.end());
27+
//std::cout << "User-Agent: " << std::string(FromAwsString(it->second)) << std::endl;
28+
//std::cout << "User-Agent: " << it->second << std::endl;
29+
std::cout << "HEADERS COUNT: " << headers.size() << std::endl;
30+
for(const auto& elem : headers) {
31+
std::cout << elem.first << ": " << elem.second << std::endl;
32+
}
33+
//std::cout << "User-Agent: " << sts.ComputUserAgentString() << std::endl;
34+
35+
//const auto userAgent = headers.at(Aws::String("User-Agent"));
36+
//std::cout << "User-Agent: " << userAgent << std::endl;
37+
38+
return outcome.IsSuccess();
39+
}
40+
41+
42+
int main(int argc, char **argv)
43+
{
44+
Aws::SDKOptions options;
45+
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;
46+
Aws::InitAPI(options);
47+
{
48+
Aws::Client::ClientConfiguration clientConfig;
49+
// Optional: Set to the AWS Region in which the bucket was created (overrides config file).
50+
// clientConfig.region = "us-east-1";
51+
if (!AwsDoc::STS::getCallerIdentity(clientConfig))
52+
{
53+
return 1;
54+
}
55+
}
56+
Aws::ShutdownAPI(options);
57+
return 0;
58+
}

example/example.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <aws/core/Aws.h>
2+
3+
namespace AwsDoc {
4+
namespace STS {
5+
bool getCallerIdentity(const Aws::Client::ClientConfiguration &clientConfig);
6+
} // sts
7+
} // AwsDoc

0 commit comments

Comments
 (0)