// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 /** * Before running this C++ code example, set up your development environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html * * For information on the structure of the code examples and how to build and run the examples, see * https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started-code-examples.html. * **/ #include #include #include #include #include "secretsmanager_samples.h" // snippet-start:[cpp.example_code.secrets_manager.get_secret_value] //! Retrieve an AWS Secrets Manager encrypted secret. /*! \param secretID: The ID for the secret. \return bool: Function succeeded. */ bool AwsDoc::SecretsManager::getSecretValue(const Aws::String &secretID, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::SecretsManager::SecretsManagerClient secretsManagerClient(clientConfiguration); Aws::SecretsManager::Model::GetSecretValueRequest request; request.SetSecretId(secretID); Aws::SecretsManager::Model::GetSecretValueOutcome getSecretValueOutcome = secretsManagerClient.GetSecretValue( request); if (getSecretValueOutcome.IsSuccess()) { std::cout << "Secret is: " << getSecretValueOutcome.GetResult().GetSecretString() << std::endl; } else { std::cerr << "Failed with Error: " << getSecretValueOutcome.GetError() << std::endl; } return getSecretValueOutcome.IsSuccess(); } // snippet-end:[cpp.example_code.secrets_manager.get_secret_value] /* * * main function * * Usage: 'Usage: run_get_secret_value ' * * Prerequisites: A SecretsManager secret. * */ #ifndef TESTING_BUILD int main(int argc, char **argv) { if (argc < 2) { std::cout << "Usage: run_get_secret_value "; return 1; } Aws::SDKOptions options; Aws::InitAPI(options); { Aws::String secretId(argv[1]); Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; AwsDoc::SecretsManager::getSecretValue(secretId, clientConfig); } Aws::ShutdownAPI(options); return 0; } #endif // TESTING_BUILD