Skip to content

Commit

Permalink
Update delete_website_config.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
scmacdon authored Dec 15, 2021
1 parent 9c821ab commit 0c2e748
Showing 1 changed file with 41 additions and 43 deletions.
84 changes: 41 additions & 43 deletions cpp/example_code/s3/delete_website_config.cpp
Original file line number Diff line number Diff line change
@@ -1,74 +1,72 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX - License - Identifier: Apache - 2.0
//snippet-sourcedescription:[delete_website_config.cpp demonstrates how to remove the website configuration for an Amazon Simple Storage Service (Amazon S3) bucket.]
//snippet-keyword:[AWS SDK for C++]
//snippet-keyword:[Code Sample]
//snippet-service:[Amazon S3]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[12/15/2021]
//snippet-sourceauthor:[scmacdon - aws]

/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

// snippet-start:[s3.cpp.delete_website_config.inc]
#include <iostream>
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/DeleteBucketWebsiteRequest.h>
#include <awsdoc/s3/s3_examples.h>
// snippet-end:[s3.cpp.delete_website_config.inc]

/* ////////////////////////////////////////////////////////////////////////////
* Purpose: Removes the website configuration for a bucket in Amazon S3.
*
/*
* Prerequisites: The bucket containing the website configuration to
* be removed.
*
* Inputs:
* Input:
* - bucketName: The name of the bucket containing the website configuration to
* be removed.
* - region: The AWS Region of the bucket.
*
* Outputs: true if the website configuration was removed; otherwise, false.
* ///////////////////////////////////////////////////////////////////////// */
* To run this C++ code example, ensure that you have setup your development environment, including your credentials.
* For information, see this documentation topic:
* https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html
*/

// snippet-start:[s3.cpp.delete_website_config.code]
bool AwsDoc::S3::DeleteBucketWebsite(const Aws::String& bucketName,
const Aws::String& region)
{
Aws::Client::ClientConfiguration config;
config.region = region;

Aws::S3::S3Client s3_client(config);

Aws::S3::Model::DeleteBucketWebsiteRequest request;
request.SetBucket(bucketName);

Aws::S3::Model::DeleteBucketWebsiteOutcome outcome =
s3_client.DeleteBucketWebsite(request);

if (!outcome.IsSuccess())
{
auto err = outcome.GetError();
std::cout << "Error: DeleteBucketWebsite: " <<
err.GetExceptionName() << ": " << err.GetMessage() << std::endl;

return false;
}

return true;
}

using namespace Aws;
int main()
{
//TODO: Change bucket_name to the name of a bucket in your account.
const Aws::String bucket_name = "DOC-EXAMPLE-BUCKET";
const Aws::String bucketName = "<Enter bucket name>";
//TODO: Set to the AWS Region in which the bucket was created.
const Aws::String region = "us-east-1";


Aws::SDKOptions options;
Aws::InitAPI(options);
{
if (AwsDoc::S3::DeleteBucketWebsite(bucket_name, region))
// Create the bucket.
Aws::Client::ClientConfiguration clientConfig;
if (!region.empty())
clientConfig.region = region;

S3::S3Client client(clientConfig);
Aws::S3::Model::DeleteBucketWebsiteRequest request;
request.SetBucket(bucketName);

Aws::S3::Model::DeleteBucketWebsiteOutcome outcome =
client.DeleteBucketWebsite(request);

if (!outcome.IsSuccess())
{
std::cout << "Removed website configuration from '" <<
bucket_name << "'." << std::endl;
auto err = outcome.GetError();
std::cout << "Error: DeleteBucketWebsite: " <<
err.GetExceptionName() << ": " << err.GetMessage() << std::endl;
}
else
{
std::cout << "Website configuration was removed." << std::endl;
}
}
ShutdownAPI(options);

return 0;
}
// snippet-end:[s3.cpp.delete_website_config.code]
// snippet-end:[s3.cpp.delete_website_config.code]

0 comments on commit 0c2e748

Please sign in to comment.