Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
The following code example shows how to add tags to Amazon EC2 resources.
- C++
-
- SDK for C++
-
Aws::EC2::EC2Client ec2Client(clientConfiguration);
Aws::EC2::Model::Tag nameTag;
nameTag.SetKey("Name");
nameTag.SetValue(instanceName);
Aws::EC2::Model::CreateTagsRequest createRequest;
createRequest.AddResources(instanceID);
createRequest.AddTags(nameTag);
Aws::EC2::Model::CreateTagsOutcome createOutcome = ec2Client.CreateTags(
createRequest);
if (!createOutcome.IsSuccess()) {
std::cerr << "Failed to tag ec2 instance " << instanceID <<
" with name " << instanceName << ":" <<
createOutcome.GetError().GetMessage() << std::endl;
return false;
}
For a complete list of Amazon SDK developer guides and code examples, see
Using this service with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.