SIGN IN SIGN UP

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.

0 0 97 Java
// 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.
*
**/
2021-11-15 13:15:43 +00:00
// snippet-start:[ec2.cpp.delete_security_group.inc]
#include <aws/ec2/EC2Client.h>
#include <aws/ec2/model/DeleteSecurityGroupRequest.h>
#include <iostream>
// snippet-end:[ec2.cpp.delete_security_group.inc]
#include "ec2_samples.h"
2021-11-15 13:15:43 +00:00
2024-08-02 10:24:50 -04:00
// snippet-start:[cpp.example_code.ec2.DeleteSecurityGroup]
//! Delete a security group.
/*!
\param securityGroupID: A security group ID.
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
2021-11-15 13:15:43 +00:00
*/
2024-08-02 10:24:50 -04:00
bool AwsDoc::EC2::deleteSecurityGroup(const Aws::String &securityGroupID,
const Aws::Client::ClientConfiguration &clientConfiguration) {
// snippet-start:[ec2.cpp.delete_security_group.code]
Aws::EC2::EC2Client ec2Client(clientConfiguration);
Aws::EC2::Model::DeleteSecurityGroupRequest request;
request.SetGroupId(securityGroupID);
2024-08-02 10:24:50 -04:00
Aws::EC2::Model::DeleteSecurityGroupOutcome outcome = ec2Client.DeleteSecurityGroup(request);
if (!outcome.IsSuccess()) {
std::cerr << "Failed to delete security group " << securityGroupID <<
":" << outcome.GetError().GetMessage() << std::endl;
2024-08-02 10:24:50 -04:00
} else {
std::cout << "Successfully deleted security group " << securityGroupID <<
std::endl;
}
// snippet-end:[ec2.cpp.delete_security_group.code]
return outcome.IsSuccess();
}
2024-08-02 10:24:50 -04:00
// snippet-end:[cpp.example_code.ec2.DeleteSecurityGroup]
/*
* main function
*
* Usage: 'run_delete_security_group <group_id>'
*
* Prerequisites: A security group to delete.
*
*/
#ifndef TESTING_BUILD
int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "run_delete_security_group <group_id>"
<< std::endl;
2021-11-15 13:15:43 +00:00
return 1;
}
Aws::SDKOptions options;
Aws::InitAPI(options);
{
Aws::Client::ClientConfiguration clientConfig;
// Optional: Set to the AWS Region (overrides config file).
// clientConfig.region = "us-east-1";
Aws::String groupID = argv[1];
2024-08-02 10:24:50 -04:00
AwsDoc::EC2::deleteSecurityGroup(groupID, clientConfig);
2021-11-15 13:15:43 +00:00
}
Aws::ShutdownAPI(options);
return 0;
}
#endif // TESTING_BUILD