Skip to content

Commit 4b891ee

Browse files
authored
4497 c++ legacy cleanup sns (awsdocs#4605)
* starting legacy cleanup * more legacy * all the functions done. * testing additions * some tests written * Finished tests * pretty much done * minor change * added some documentation * Editorial fixes
1 parent 2970d6e commit 4b891ee

37 files changed

+2100
-729
lines changed

cpp/example_code/aurora/tests/gtest_getting_started_with_db_clusters.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace AwsDocTest {
3131
}
3232

3333
// NOLINTNEXTLINE(readability-named-parameter)
34-
TEST_F(Aurora_GTests, gettingStartedWithDBInstances_3_) {
34+
TEST_F(Aurora_GTests, gettingStartedWithDBClusters_3_) {
3535
AddCommandLineResponses(RESPONSES);
3636

3737
MockHTTP mockHttp;
@@ -135,7 +135,7 @@ namespace AwsDocTest {
135135
if (!mockHttp.addResponseWithBody("mock_input/626-DeleteDBInstance.xml")) {
136136
return false;
137137
}
138-
if (!mockHttp.addResponseWithBody("mock_input/627-DeleteDBCLuster.xml")) {
138+
if (!mockHttp.addResponseWithBody("mock_input/627-DeleteDBCluster.xml")) {
139139
return false;
140140
}
141141
if (!mockHttp.addResponseWithBody("mock_input/628-DescribeDBInstances.xml")) {

cpp/example_code/sns/CMakeLists.txt

+35-126
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,64 @@
1-
# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
# This file is licensed under the Apache License, Version 2.0 (the "License").
3-
# You may not use this file except in compliance with the License. A copy of
4-
# the License is located at
5-
# http://aws.amazon.com/apache2.0/
6-
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7-
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
8-
# specific language governing permissions and limitations under the License.
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
93

104
# Set the minimum required version of CMake for this project.
115
cmake_minimum_required(VERSION 3.8)
126

7+
set(SERVICE_NAME sns)
8+
set(SERVICE_COMPONENTS sns)
9+
1310
# Set this project's name.
14-
project("sns-examples")
11+
project("${SERVICE_NAME}-examples")
1512

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

19-
# Enable CTest for testing these code examples.
20-
include(CTest)
21-
2216
# Build shared libraries by default.
23-
if(NOT BUILD_SHARED_LIBS)
24-
set(BUILD_SHARED_LIBS ON)
25-
endif()
17+
set(BUILD_SHARED_LIBS ON)
2618

27-
list(APPEND CMAKE_PREFIX_PATH "C:\\Program Files (x86)\\aws-cpp-sdk-all\\lib\\cmake")
28-
#Set the location of where Windows can find the installed libraries of the SDK.
29-
if(MSVC)
19+
# Set the location of where Windows can find the installed libraries of the SDK.
20+
if (MSVC)
3021
string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all")
3122
list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH})
32-
endif()
23+
endif ()
3324

34-
# Locate the aws sdk for c++ package.
35-
find_package(AWSSDK REQUIRED COMPONENTS sns)
25+
# Find the AWS SDK for C++ package.
26+
find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS})
3627

37-
# If the compiler is some version of Microsoft Visual C++,
28+
# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++,
3829
# and building as shared libraries, then dynamically link to those shared libraries.
39-
if(MSVC AND BUILD_SHARED_LIBS)
40-
add_definitions(-DUSE_IMPORT_EXPORT)
30+
if (MSVC)
31+
set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs.
32+
33+
list(APPEND SERVICE_LIST ${SERVICE_COMPONENTS})
34+
4135
# Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.
42-
list(APPEND SERVICE_LIST sns)
43-
44-
#For IDE's like Xcode and Visual Studio this line will be ignored because Release/Debug
45-
# is switched internally, but this is necessary for non-IDE builds.
46-
set(CMAKE_BUILD_TYPE Debug) #TODO: Set to your build type
47-
48-
#TODO:Choose appropriate one of the following two lines, you want to copy to the same folder where your executables are.
49-
AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) #Choose this line if your executables are in /build/Debug
50-
#AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}) #Choose this line for Visual Studio and possibly other IDEs
51-
52-
message(STATUS ">>CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}")
53-
message(STATUS ">>CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
54-
message(STATUS ">>EXECUTABLE_OUTPUT_PATH : ${EXECUTABLE_OUTPUT_PATH}")
55-
endif()
56-
57-
58-
#set(EXAMPLES "")
59-
#list(APPEND EXAMPLES "create_topic")
60-
#list(APPEND EXAMPLES "delete_topic")
61-
#list(APPEND EXAMPLES "get_sms_type")
62-
#list(APPEND EXAMPLES "get_topic_attributes")
63-
#list(APPEND EXAMPLES "list_subscriptions")
64-
#list(APPEND EXAMPLES "list_topics")
65-
#list(APPEND EXAMPLES "publish_sms")
66-
#list(APPEND EXAMPLES "publish_to_topic")
67-
#list(APPEND EXAMPLES "set_sms_type")
68-
#list(APPEND EXAMPLES "subscribe_app")
69-
#list(APPEND EXAMPLES "subscribe_email")
70-
#list(APPEND EXAMPLES "subscribe_lambda")
71-
#list(APPEND EXAMPLES "unsubscribe")
72-
73-
# Add the code example-specific header files. (none-currently, placeholder)
74-
file(GLOB AWSDOC_HEADERS
75-
"include/awsdoc/ex/*.h"
76-
)
77-
78-
# Add the code example-specific source files.
79-
file(GLOB AWSDOC_SOURCE
80-
"*.cpp"
81-
)
82-
83-
# Check whether the target system is Windows, including Win64.
84-
if(WIN32)
85-
# Check whether the compiler is some version of Microsoft Visual C++, or another compiler simulating C++.
86-
if(MSVC)
87-
source_group("Header Files\\awsdoc\\ex" FILES ${AWSDOC_HEADERS})
88-
source_group("Source Files" FILES ${AWSDOC_SOURCE})
89-
endif(MSVC)
90-
endif()
91-
92-
foreach(file ${AWSDOC_SOURCE})
36+
AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
37+
endif ()
38+
39+
# AWSDOC_SOURCE can be defined in the command line to limit the files in a build. For example,
40+
# you can limit files to one action.
41+
if (NOT DEFINED AWSDOC_SOURCE)
42+
file(GLOB AWSDOC_SOURCE
43+
"*.cpp"
44+
)
45+
endif ()
46+
47+
foreach (file ${AWSDOC_SOURCE})
9348
get_filename_component(EXAMPLE ${file} NAME_WE)
9449

9550
# Build the code example executables.
9651
set(EXAMPLE_EXE run_${EXAMPLE})
9752

98-
add_executable(${EXAMPLE_EXE} ${AWSDOC_HEADERS} ${file})
53+
add_executable(${EXAMPLE_EXE} ${file})
9954

100-
if(MSVC AND BUILD_SHARED_LIBS)
101-
target_compile_definitions(${EXAMPLE_EXE} PUBLIC "USE_IMPORT_EXPORT")
102-
target_compile_definitions(${EXAMPLE_EXE} PRIVATE "AWSDOC_EXPORTS")
103-
endif()
104-
105-
target_include_directories(${EXAMPLE_EXE} PUBLIC
106-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
107-
$<INSTALL_INTERFACE:include>)
10855
target_link_libraries(${EXAMPLE_EXE} ${AWSSDK_LINK_LIBRARIES}
109-
${AWSSDK_PLATFORM_DEPS})
110-
111-
if(BUILD_TESTING)
112-
# Enable testing for this directory and below.
113-
enable_testing()
114-
115-
# Build the code example libraries.
116-
set(EXAMPLE_LIB ${EXAMPLE})
117-
118-
add_library(${EXAMPLE_LIB} ${AWSDOC_HEADERS} ${file} )
119-
120-
if(MSVC AND BUILD_SHARED_LIBS)
121-
target_compile_definitions(${EXAMPLE_LIB} PUBLIC "USE_IMPORT_EXPORT")
122-
target_compile_definitions(${EXAMPLE_LIB} PRIVATE "AWSDOC_EXPORTS")
123-
endif()
124-
125-
target_include_directories(${EXAMPLE_LIB} PUBLIC
126-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
127-
$<INSTALL_INTERFACE:include>)
128-
target_link_libraries(${EXAMPLE_LIB} ${AWSSDK_LINK_LIBRARIES}
12956
${AWSSDK_PLATFORM_DEPS})
13057

131-
# Build the code example unit tests.
132-
set(EXAMPLE_TEST test_${EXAMPLE})
133-
set(EXAMPLE_TEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_${EXAMPLE}.cpp)
134-
135-
if(EXISTS ${EXAMPLE_TEST_FILE})
136-
add_executable(${EXAMPLE_TEST} ${EXAMPLE_TEST_FILE} )
137-
138-
target_include_directories(${EXAMPLE_TEST} PUBLIC
139-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
140-
$<INSTALL_INTERFACE:include>)
141-
target_link_libraries(${EXAMPLE_TEST} ${EXAMPLE_LIB} )
142-
add_test(${EXAMPLE_TEST} ${EXAMPLE_TEST})
143-
endif()
144-
145-
endif()
146-
endforeach()
147-
58+
endforeach ()
14859

14960

61+
if (BUILD_TESTS)
62+
add_subdirectory(tests)
63+
endif ()
15064

151-
# The executables to build.
152-
foreach(EXAMPLE IN LISTS EXAMPLES)
153-
add_executable(${EXAMPLE} ${EXAMPLE}.cpp)
154-
target_link_libraries(${EXAMPLE} ${AWSSDK_LINK_LIBRARIES})
155-
endforeach()

cpp/example_code/sns/README.md

+87-35
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,97 @@
1-
# Amazon SNS C++ SDK code examples
1+
<!--Generated by WRITEME on 2023-03-29 13:24:55.530150 (UTC)-->
2+
# Amazon SNS code examples for the SDK for C++
23

3-
## Purpose
4-
The code examples in this directory demonstrate how to work with the Amazon Simple Notification Service
5-
(Amazon SNS) using the AWS SDK for C++.
4+
## Overview
65

7-
Amazon SNS is a fully managed messaging service for both application-to-application (A2A) and application-to-person (A2P) communication.
6+
Shows how to use the AWS SDK for C++ to work with Amazon Simple Notification Service (Amazon SNS).
87

9-
## Code examples
10-
This is a workspace where you can find AWS SDK for C++ SNS examples.
11-
12-
- [Creating an Amazon SNS topic to which notifications can be published](./create_topic.cpp) (CreateTopic)
13-
- [Deleting an Amazon SNS topic and all its subscriptions](./delete_topic.cpp) (DeleteTopic)
14-
- [Retrieving the settings for sending Amazon SMS messages](./get_sms_type.cpp) (GetSMSAttributes)
15-
- [Retrieving the properties of an Amazon SNS topic](./get_topic_attributes.cpp) (GetTopicAttributes)
16-
- [Retrieving a list of Amazon SNS subscriptions](./list_subscriptions.cpp) (ListSubscriptions)
17-
- [Retrieving a list of Amazon SNS topics](./list_topics.cpp) (ListTopics)
18-
- [Sending an SMS text message to a phone number](./publish_sms.cpp) (Publish)
19-
- [Sending a message to an Amazon SNS topic](./publish_to_topic.cpp) (Publish)
20-
- [Setting default SMS attributes](./set_sms_type.cpp) (SetSMSAttributes)
21-
- [Subscribing to an Amazon SNS topic with delivery to a mobile app](./subscribe_app.cpp) (Subscribe)
22-
- [Subscribing to an Amazon SNS topic with delivery to an email address](./subscribe_email.cpp) (Subscribe)
23-
- [Subscribing to an Amazon SNS topic with delivery to an AWS Lambda function](./subscribe_lambda.cpp) (Subscribe)
24-
- [Unsubscribing to an Amazon SNS topic](./unsubscribe.cpp) (Unsubscribe)
8+
<!--custom.overview.start-->
9+
<!--custom.overview.end-->
10+
11+
*Amazon SNS is a web service that enables applications, end-users, and devices to instantly send and receive notifications from the cloud.*
2512

2613
## ⚠ Important
27-
- We recommend that you grant your code least privilege, or at most the minimum permissions required to perform the task. For more information, see [Grant Least Privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege) in the AWS Identity and Access Management User Guide.
28-
- This code has not been tested in all AWS Regions. Some AWS services are available only in specific [Regions](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).
29-
- Running this code might result in charges to your AWS account.
30-
- Running the unit tests might result in charges to your AWS account. [optional]
3114

32-
## Running the Examples
33-
Before using the code examples, first complete the installation and setup steps of [Getting Started](https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html) in the AWS SDK for C++ Developer Guide.
34-
The Getting Started section covers how to obtain and build the SDK, and how to build your own code utilizing the SDK with a sample "Hello World"-style application.
15+
* Running this code might result in charges to your AWS account.
16+
* Running the tests might result in charges to your AWS account.
17+
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege).
18+
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).
19+
20+
<!--custom.important.start-->
21+
<!--custom.important.end-->
22+
23+
## Code examples
24+
### Single actions
25+
26+
Code excerpts that show you how to call individual service functions.
27+
28+
* [Create a topic](create_topic.cpp#L23) (`CreateTopic`)
29+
* [Delete a subscription](unsubscribe.cpp#L23) (`Unsubscribe`)
30+
* [Delete a topic](delete_topic.cpp#L23) (`DeleteTopic`)
31+
* [Get the properties of a topic](get_topic_attributes.cpp#L25) (`GetTopicAttributes`)
32+
* [Get the settings for sending SMS messages](get_sms_type.cpp#L23) (`GetSMSAttributes`)
33+
* [List the subscribers of a topic](list_subscriptions.cpp#L23) (`ListSubscriptions`)
34+
* [List topics](list_topics.cpp#L23) (`ListTopics`)
35+
* [Publish an SMS text message](publish_sms.cpp#L23) (`Publish`)
36+
* [Publish to a topic](publish_to_topic.cpp#L23) (`Publish`)
37+
* [Set the default settings for sending SMS messages](set_sms_type.cpp#L24) (`SetSmsAttributes`)
38+
* [Subscribe a Lambda function to a topic](subscribe_lambda.cpp#L23) (`Subscribe`)
39+
* [Subscribe a mobile application to a topic](subscribe_app.cpp#L23) (`Subscribe`)
40+
* [Subscribe an email address to a topic](subscribe_email.cpp#L18) (`Subscribe`)
41+
42+
## Run the examples
43+
44+
### Prerequisites
45+
46+
47+
48+
Before using the code examples, first complete the installation and setup steps
49+
for [Getting started](https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html) in the AWS SDK for
50+
C++ Developer Guide.
51+
This section covers how to get and build the SDK, and how to build your own code by using the SDK with a
52+
sample Hello World-style application.
53+
54+
Next, for information on code example structures and how to build and run the examples, see [Getting started with the AWS SDK for C++ code examples](https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started-code-examples.html).
55+
56+
57+
<!--custom.prerequisites.start-->
58+
<!--custom.prerequisites.end-->
59+
60+
### Instructions
61+
62+
63+
<!--custom.instructions.start-->
64+
<!--custom.instructions.end-->
65+
66+
67+
### Tests
68+
69+
⚠ Running tests might result in charges to your AWS account.
70+
71+
72+
73+
```sh
74+
cd <BUILD_DIR>
75+
cmake <path-to-root-of-this-source-code> -DBUILD_TESTS=ON
76+
make
77+
ctest
78+
```
79+
80+
81+
<!--custom.tests.start-->
82+
<!--custom.tests.end-->
83+
84+
## Additional resources
85+
86+
* [Amazon SNS Developer Guide](https://docs.aws.amazon.com/sns/latest/dg/welcome.html)
87+
* [Amazon SNS API Reference](https://docs.aws.amazon.com/sns/latest/api/welcome.html)
88+
* [SDK for C++ Amazon SNS reference](https://sdk.amazonaws.com/cpp/api/LATEST/aws-cpp-sdk-sns/html/annotated.html)
3589

36-
Next, see [Getting started with the AWS SDK for C++ code examples](https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started-code-examples.html) for information on the structure of the code examples, building, and running the examples.
90+
<!--custom.resources.start-->
91+
<!--custom.resources.end-->
3792

38-
To run these code examples, your AWS user must have permissions to perform these actions with SNS.
39-
The AWS managed policy named "AmazonSNSFullAccess" may be used to bulk-grant the necessary permissions.
40-
For more information on attaching policies to IAM user groups,
41-
see [Attaching a policy to an IAM user group](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_groups_manage_attach-policy.html).
93+
---
4294

43-
## Resources
44-
- [AWS SDK for C++ Documentation](https://docs.aws.amazon.com/sdk-for-cpp/index.html)
95+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4596

97+
SPDX-License-Identifier: Apache-2.0

0 commit comments

Comments
 (0)