Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
cmake-build*/
.vs/
build_tests
build_tests
CMakeSettings.json
14 changes: 10 additions & 4 deletions cpp/example_code/aurora/getting_started_with_db_clusters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,15 +767,18 @@ bool AwsDoc::Aurora::describeDBCluster(const Aws::String &dbClusterIdentifier,
if (outcome.IsSuccess()) {
clusterResult = outcome.GetResult().GetDBClusters()[0];
}
// This example does not log an error if the DB cluster does not exist.
// Instead, it returns false.
else if (outcome.GetError().GetErrorType() !=
Aws::RDS::RDSErrors::D_B_CLUSTER_NOT_FOUND_FAULT) {
result = false;
std::cerr << "Error with Aurora::GDescribeDBClusters. "
<< outcome.GetError().GetMessage()
<< std::endl;
}
// This example does not log an error if the DB cluster does not exist.
// Instead, clusterResult is set to empty.
else {
clusterResult = Aws::RDS::Model::DBCluster();
}

return result;

Expand Down Expand Up @@ -902,15 +905,18 @@ bool AwsDoc::Aurora::describeDBInstance(const Aws::String &dbInstanceIdentifier,
if (outcome.IsSuccess()) {
instanceResult = outcome.GetResult().GetDBInstances()[0];
}
// This example does not log an error if the DB instance does not exist.
// Instead, it returns false.
else if (outcome.GetError().GetErrorType() !=
Aws::RDS::RDSErrors::D_B_INSTANCE_NOT_FOUND_FAULT) {
result = false;
std::cerr << "Error with Aurora::DescribeDBInstances. "
<< outcome.GetError().GetMessage()
<< std::endl;
}
// This example does not log an error if the DB instance does not exist.
// Instead, instanceResult is set to empty.
else {
instanceResult = Aws::RDS::Model::DBInstance();
}

return result;
}
Expand Down
40 changes: 16 additions & 24 deletions cpp/example_code/iam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,33 @@ set(SERVICE_COMPONENTS iam s3 sts)
# Set this project's name.
project("${SERVICE_NAME}-examples")

# Set the location of where Windows can find the installed libraries of the SDK.
if(MSVC)
string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all")
list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH})
endif()

# Set the C++ standard to use to build this target.
set(CMAKE_CXX_STANDARD 11)

# Enable CTest for testing these code examples.
if(BUILD_TESTS)
include(CTest)
endif()

# Build shared libraries by default.
if(NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
set(BUILD_SHARED_LIBS ON)

# Use the MSVC variable to determine if this is a Windows build.
set(WINDOWS_BUILD ${MSVC})

# Set the location of where Windows can find the installed libraries of the SDK.
if(WINDOWS_BUILD)
string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all")
list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH})
endif()

# Find the AWS SDK for C++ package.
find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS})

# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++,
# and building as shared libraries, then dynamically link to those shared libraries.
if(MSVC AND BUILD_SHARED_LIBS)
add_definitions(-DUSE_IMPORT_EXPORT)
# Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.

set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in windows to copy dlls.

list(APPEND SERVICE_LIST ${SERVICE_COMPONENTS})
if(WINDOWS_BUILD)
# Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.

AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
endif()
# set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this
# and set the proper subdirectory to the executables' location.

AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR})
endif()

# AWSDOC_SOURCE can be defined in the command line to limit the files in a build. For example,
# you can limit files to one action.
Expand Down Expand Up @@ -79,6 +71,6 @@ endforeach()


if(BUILD_TESTS)
add_subdirectory(gtests)
add_subdirectory(tests)
endif()

9 changes: 6 additions & 3 deletions cpp/example_code/iam/iam_create_user_assume_role_scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
// snippet-start:[cpp.example_code.iam.Scenario_CreateUserAssumeRole]
namespace AwsDoc {
namespace IAM {

//! Cleanup by deleting created entities.
/*!
\sa DeleteCreatedEntities
Expand All @@ -69,6 +70,8 @@ namespace AwsDoc {
const Aws::IAM::Model::Policy &policy);
}

static const int LIST_BUCKETS_WAIT_SEC = 20;

static const char ALLOCATION_TAG[] = "example_code";
}

Expand Down Expand Up @@ -320,7 +323,7 @@ bool AwsDoc::IAM::iamCreateUserAssumeRoleScenario(
// 7. List objects in the bucket (this should succeed).
// Repeatedly call ListBuckets, because there is often a delay
// before the policy with ListBucket permissions has been applied to the role.
// Repeat at most 20 times when access is denied.
// Repeat at most LIST_BUCKETS_WAIT_SEC times when access is denied.
while (true) {
Aws::S3::S3Client s3Client(
Aws::Auth::AWSCredentials(credentials.GetAccessKeyId(),
Expand All @@ -330,10 +333,10 @@ bool AwsDoc::IAM::iamCreateUserAssumeRoleScenario(
clientConfig);
Aws::S3::Model::ListBucketsOutcome listBucketsOutcome = s3Client.ListBuckets();
if (!listBucketsOutcome.IsSuccess()) {
if ((count > 20) ||
if ((count > LIST_BUCKETS_WAIT_SEC) ||
listBucketsOutcome.GetError().GetErrorType() !=
Aws::S3::S3Errors::ACCESS_DENIED) {
std::cerr << "Could not lists buckets after 20 seconds. " <<
std::cerr << "Could not lists buckets after " << LIST_BUCKETS_WAIT_SEC << " seconds. " <<
listBucketsOutcome.GetError().GetMessage() << std::endl;
DeleteCreatedEntities(client, role, user, policy);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ set(CMAKE_CXX_STANDARD 14)
# Build shared libraries by default.
set(BUILD_SHARED_LIBS ON)

enable_testing()

find_package(GTest)

if(NOT GTest_FOUND)
Expand All @@ -32,8 +34,12 @@ if(NOT GTest_FOUND)
FetchContent_MakeAvailable(googletest)
endif()


# Use the MSVC variable to determine if this is a Windows build.
set(WINDOWS_BUILD ${MSVC})

# Set the location for Windows to find the installed libraries of the SDK.
if(MSVC)
if(WINDOWS_BUILD)
string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all")
list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH})
endif()
Expand All @@ -47,26 +53,27 @@ add_executable(

# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++,
# and building as shared libraries, then dynamically link to those shared libraries.
if(MSVC AND BUILD_SHARED_LIBS)

set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs.
if(WINDOWS_BUILD)
# set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this
# and set the proper subdirectory to the executables' location.

# Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.
AWSSDK_CPY_DYN_LIBS(
CURRENT_TARGET_AWS_DEPENDENCIES
CURRENT_TARGET_AWS_DEPENDENCIES
""
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}
${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR}
)

add_custom_command(
TARGET
${CURRENT_TARGET}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${CMAKE_BUILD_TYPE}/gtest.dll
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}${BIN_SUB_DIR}/gtest.dll
${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR}
)
endif()
endif()


# GTEST_SOURCE_FILES can be defined in the command line to limit the files in a build. For example,
# you can limit files to one action.
Expand Down
7 changes: 5 additions & 2 deletions cpp/example_code/rds/getting_started_with_db_instances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,15 +758,18 @@ bool AwsDoc::RDS::describeDBInstance(const Aws::String &dbInstanceIdentifier,
if (outcome.IsSuccess()) {
instanceResult = outcome.GetResult().GetDBInstances()[0];
}
// This example does not log an error if the DB instance does not exist.
// Instead, it returns false.
else if (outcome.GetError().GetErrorType() !=
Aws::RDS::RDSErrors::D_B_INSTANCE_NOT_FOUND_FAULT) {
result = false;
std::cerr << "Error with RDS::DescribeDBInstances. "
<< outcome.GetError().GetMessage()
<< std::endl;
}
// This example does not log an error if the DB instance does not exist.
// Instead, instanceResult is set to empty.
else {
instanceResult = Aws::RDS::Model::DBInstance();
}

return result;
}
Expand Down
41 changes: 19 additions & 22 deletions cpp/example_code/s3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,39 @@
# Set the minimum required version of CMake for this project.
cmake_minimum_required(VERSION 3.8)

set(SERVICE_NAME)
set(SERVICE_COMPONENTS s3 sts iam)

# Set this project's name.
project("s3-examples")
project("${SERVICE_NAME}-examples")

# Set the location of where Windows can find the installed libraries of the SDK.
if(MSVC)
string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all")
list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH})
endif()
# Build shared libraries by default.
set(BUILD_SHARED_LIBS ON)

# Set the C++ standard to use to build this target.
set(CMAKE_CXX_STANDARD 11)

# Enable CTest for testing these code examples.
if(BUILD_TESTS)
include(CTest)
endif()
# Use the MSVC variable to determine if this is a Windows build.
set(WINDOWS_BUILD ${MSVC})

# Build shared libraries by default.
if(NOT BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
# Set the location of where Windows can find the installed libraries of the SDK.
if(WINDOWS_BUILD)
string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all")
list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH})
endif()

# Find the AWS SDK for C++ package.
find_package(AWSSDK REQUIRED COMPONENTS s3 sts iam)
find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS})


# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++,
# and building as shared libraries, then dynamically link to those shared libraries.
if(MSVC AND BUILD_SHARED_LIBS)
add_definitions(-DUSE_IMPORT_EXPORT)
# Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.

set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in windows to copy dlls.
if(WINDOWS_BUILD)
# Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.

list(APPEND SERVICE_LIST s3 sts iam)
# set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this
# and set the proper subdirectory to the executables' location.

AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR})
endif()

# Add the code example-specific header files.
Expand Down
2 changes: 1 addition & 1 deletion cpp/example_code/s3/list_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int main()
//TODO(user): Name of a bucket in your account.
//The bucket must have at least one object in it. One way to achieve
//this is to configure and run put_object.cpp's executable first.
const Aws::String bucket_name = "my-bucket-2f2730dd-0f5d-4dfa-b55d-8d36a3bfea39";
const Aws::String bucket_name = "<enter_bucket_name>";

Aws::Client::ClientConfiguration clientConfig;
// Optional: Set to the AWS Region in which the bucket was created (overrides config file).
Expand Down
29 changes: 16 additions & 13 deletions cpp/example_code/s3/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ set(CMAKE_CXX_STANDARD 14)
# Build shared libraries by default.
set(BUILD_SHARED_LIBS ON)

enable_testing()

find_package(GTest)

if(NOT GTest_FOUND)
Expand All @@ -33,8 +35,11 @@ if(NOT GTest_FOUND)
endif()


# Use the MSVC variable to determine if this is a Windows build.
set(WINDOWS_BUILD ${MSVC})

# Set the location for Windows to find the installed libraries of the SDK.
if(MSVC)
if(WINDOWS_BUILD)
string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all")
list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH})
endif()
Expand All @@ -46,28 +51,26 @@ add_executable(
${CURRENT_TARGET}
)

# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++,
# and building as shared libraries, then dynamically link to those shared libraries.
if(MSVC AND BUILD_SHARED_LIBS)
add_definitions(-DUSE_IMPORT_EXPORT)

set(CMAKE_BUILD_TYPE Debug) # Explicitly set this to support library copying and test automation.
if(WINDOWS_BUILD)
# set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this
# and set the proper subdirectory to the executables' location.

# Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.
AWSSDK_CPY_DYN_LIBS(
CURRENT_TARGET_AWS_DEPENDENCIES
CURRENT_TARGET_AWS_DEPENDENCIES
""
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}
)
${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR}
)

add_custom_command(
TARGET
${CURRENT_TARGET}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${CMAKE_BUILD_TYPE}/gtest.dll
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}${BIN_SUB_DIR}/gtest.dll
${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR}
)
endif()
endif()

# GTEST_SOURCE_FILES can be defined in the command line to limit the files in a build. For example,
# you can limit files to one action.
Expand Down
Loading