What is @aws-sdk/client-resource-groups-tagging-api?
The @aws-sdk/client-resource-groups-tagging-api package is part of the AWS SDK for JavaScript. It provides a client for interacting with the AWS Resource Groups Tagging API, which allows you to manage and query tags for your AWS resources. This can be useful for organizing, searching, and managing resources based on their tags.
What are @aws-sdk/client-resource-groups-tagging-api's main functionalities?
ListTagsForResource
This feature allows you to list the tags for a specific AWS resource. The code sample demonstrates how to use the GetResourcesCommand to retrieve tags for a given resource ARN.
const { ResourceGroupsTaggingAPIClient, GetResourcesCommand } = require('@aws-sdk/client-resource-groups-tagging-api');
const client = new ResourceGroupsTaggingAPIClient({ region: 'us-west-2' });
const params = {
ResourceARNList: ['arn:aws:s3:::example-bucket']
};
const run = async () => {
try {
const data = await client.send(new GetResourcesCommand(params));
console.log('Tags for resource:', data.ResourceTagMappingList);
} catch (err) {
console.error(err);
}
};
run();
TagResources
This feature allows you to add or update tags for specified AWS resources. The code sample demonstrates how to use the TagResourcesCommand to tag a resource with key-value pairs.
const { ResourceGroupsTaggingAPIClient, TagResourcesCommand } = require('@aws-sdk/client-resource-groups-tagging-api');
const client = new ResourceGroupsTaggingAPIClient({ region: 'us-west-2' });
const params = {
ResourceARNList: ['arn:aws:s3:::example-bucket'],
Tags: {
'Environment': 'Production',
'Department': 'Finance'
}
};
const run = async () => {
try {
const data = await client.send(new TagResourcesCommand(params));
console.log('Resources tagged successfully:', data);
} catch (err) {
console.error(err);
}
};
run();
UntagResources
This feature allows you to remove tags from specified AWS resources. The code sample demonstrates how to use the UntagResourcesCommand to remove specific tags from a resource.
const { ResourceGroupsTaggingAPIClient, UntagResourcesCommand } = require('@aws-sdk/client-resource-groups-tagging-api');
const client = new ResourceGroupsTaggingAPIClient({ region: 'us-west-2' });
const params = {
ResourceARNList: ['arn:aws:s3:::example-bucket'],
TagKeys: ['Environment', 'Department']
};
const run = async () => {
try {
const data = await client.send(new UntagResourcesCommand(params));
console.log('Tags removed successfully:', data);
} catch (err) {
console.error(err);
}
};
run();
GetTagKeys
This feature allows you to retrieve all tag keys in your AWS account. The code sample demonstrates how to use the GetTagKeysCommand to list all tag keys.
const { ResourceGroupsTaggingAPIClient, GetTagKeysCommand } = require('@aws-sdk/client-resource-groups-tagging-api');
const client = new ResourceGroupsTaggingAPIClient({ region: 'us-west-2' });
const run = async () => {
try {
const data = await client.send(new GetTagKeysCommand({}));
console.log('Tag keys:', data.TagKeys);
} catch (err) {
console.error(err);
}
};
run();
GetTagValues
This feature allows you to retrieve all tag values for a specific tag key in your AWS account. The code sample demonstrates how to use the GetTagValuesCommand to list all values for a given tag key.
const { ResourceGroupsTaggingAPIClient, GetTagValuesCommand } = require('@aws-sdk/client-resource-groups-tagging-api');
const client = new ResourceGroupsTaggingAPIClient({ region: 'us-west-2' });
const params = {
Key: 'Environment'
};
const run = async () => {
try {
const data = await client.send(new GetTagValuesCommand(params));
console.log('Tag values for key:', data.TagValues);
} catch (err) {
console.error(err);
}
};
run();
Other packages similar to @aws-sdk/client-resource-groups-tagging-api
aws-sdk
The aws-sdk package is the official AWS SDK for JavaScript. It provides a comprehensive set of tools for interacting with all AWS services, including the Resource Groups Tagging API. Compared to @aws-sdk/client-resource-groups-tagging-api, the aws-sdk package is more monolithic and includes support for all AWS services in a single package.
aws-cdk
The aws-cdk (AWS Cloud Development Kit) is a framework for defining cloud infrastructure in code and provisioning it through AWS CloudFormation. While it is not specifically focused on tagging, it allows you to define tags as part of your infrastructure code. Compared to @aws-sdk/client-resource-groups-tagging-api, aws-cdk is more focused on infrastructure as code and less on direct API interactions.
serverless
The serverless framework is a toolkit for deploying and operating serverless architectures. It supports tagging of resources as part of its configuration. Compared to @aws-sdk/client-resource-groups-tagging-api, the serverless framework is more focused on serverless application deployment and management, with tagging being a secondary feature.
@aws-sdk/client-resource-groups-tagging-api
Description
AWS SDK for JavaScript ResourceGroupsTaggingAPI Client for Node.js, Browser and React Native.
Resource Groups Tagging API
Installing
To install the this package, simply type add or install @aws-sdk/client-resource-groups-tagging-api
using your favorite package manager:
npm install @aws-sdk/client-resource-groups-tagging-api
yarn add @aws-sdk/client-resource-groups-tagging-api
pnpm add @aws-sdk/client-resource-groups-tagging-api
Getting Started
Import
The AWS SDK is modulized by clients and commands.
To send a request, you only need to import the ResourceGroupsTaggingAPIClient
and
the commands you need, for example DescribeReportCreationCommand
:
const {
ResourceGroupsTaggingAPIClient,
DescribeReportCreationCommand,
} = require("@aws-sdk/client-resource-groups-tagging-api");
import {
ResourceGroupsTaggingAPIClient,
DescribeReportCreationCommand,
} from "@aws-sdk/client-resource-groups-tagging-api";
Usage
To send a request, you:
- Initiate client with configuration (e.g. credentials, region).
- Initiate command with input parameters.
- Call
send
operation on client with command object as input. - If you are using a custom http handler, you may call
destroy()
to close open connections.
const client = new ResourceGroupsTaggingAPIClient({ region: "REGION" });
const params = {
};
const command = new DescribeReportCreationCommand(params);
Async/await
We recommend using await
operator to wait for the promise returned by send operation as follows:
try {
const data = await client.send(command);
} catch (error) {
} finally {
}
Async-await is clean, concise, intuitive, easy to debug and has better error handling
as compared to using Promise chains or callbacks.
Promises
You can also use Promise chaining
to execute send operation.
client.send(command).then(
(data) => {
},
(error) => {
}
);
Promises can also be called using .catch()
and .finally()
as follows:
client
.send(command)
.then((data) => {
})
.catch((error) => {
})
.finally(() => {
});
Callbacks
We do not recommend using callbacks because of callback hell,
but they are supported by the send operation.
client.send(command, (err, data) => {
});
v2 compatible style
The client can also send requests using v2 compatible style.
However, it results in a bigger bundle size and may be dropped in next major version. More details in the blog post
on modular packages in AWS SDK for JavaScript
import * as AWS from "@aws-sdk/client-resource-groups-tagging-api";
const client = new AWS.ResourceGroupsTaggingAPI({ region: "REGION" });
try {
const data = await client.describeReportCreation(params);
} catch (error) {
}
client
.describeReportCreation(params)
.then((data) => {
})
.catch((error) => {
});
client.describeReportCreation(params, (err, data) => {
});
Troubleshooting
When the service returns an exception, the error will include the exception information,
as well as response metadata (e.g. request id).
try {
const data = await client.send(command);
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$metadata;
console.log({ requestId, cfId, extendedRequestId });
}
Getting Help
Please use these community resources for getting help.
We use the GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them.
To test your universal JavaScript code in Node.js, browser and react-native environments,
visit our code samples repo.
Contributing
This client code is generated automatically. Any modifications will be overwritten the next time the @aws-sdk/client-resource-groups-tagging-api
package is updated.
To contribute to client you can check our generate clients scripts.
License
This SDK is distributed under the
Apache License, Version 2.0,
see LICENSE for more information.