There are more AWS SDK examples available in the AWS Doc SDK Examples
Use TagResource
with an AWS SDK or CLI
The following code examples show how to use TagResource
.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code examples:
- CLI
-
- AWS CLI
-
Example 1: To tag a data store
The following
tag-resource
code examples tags a data store.aws medical-imaging tag-resource \ --resource-arn
"arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012"
\ --tags '{"Deployment":"Development"}
'This command produces no output.
Example 2: To tag an image set
The following
tag-resource
code examples tags an image set.aws medical-imaging tag-resource \ --resource-arn
"arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012/imageset/18f88ac7870584f58d56256646b4d92b"
\ --tags '{"Deployment":"Development"}
'This command produces no output.
For more information, see Tagging resources with AWS HealthImaging in the AWS HealthImaging Developer Guide.
-
For API details, see TagResource
in AWS CLI Command Reference.
-
- Java
-
- SDK for Java 2.x
-
public static void tagMedicalImagingResource(MedicalImagingClient medicalImagingClient, String resourceArn, Map<String, String> tags) { try { TagResourceRequest tagResourceRequest = TagResourceRequest.builder() .resourceArn(resourceArn) .tags(tags) .build(); medicalImagingClient.tagResource(tagResourceRequest); System.out.println("Tags have been added to the resource."); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
-
For API details, see TagResource in AWS SDK for Java 2.x API Reference.
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. -
- JavaScript
-
- SDK for JavaScript (v3)
-
import { TagResourceCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} resourceArn - The Amazon Resource Name (ARN) for the data store or image set. * @param {Record<string,string>} tags - The tags to add to the resource as JSON. * - For example: {"Deployment" : "Development"} */ export const tagResource = async ( resourceArn = "arn:aws:medical-imaging:us-east-1:xxxxxx:datastore/xxxxx/imageset/xxx", tags = {}, ) => { const response = await medicalImagingClient.send( new TagResourceCommand({ resourceArn: resourceArn, tags: tags }), ); console.log(response); // { // '$metadata': { // httpStatusCode: 204, // requestId: '8a6de9a3-ec8e-47ef-8643-473518b19d45', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // } // } return response; };
-
For API details, see TagResource in AWS SDK for JavaScript API Reference.
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. -
- Python
-
- SDK for Python (Boto3)
-
class MedicalImagingWrapper: def __init__(self, health_imaging_client): self.health_imaging_client = health_imaging_client def tag_resource(self, resource_arn, tags): """ Tag a resource. :param resource_arn: The ARN of the resource. :param tags: The tags to apply. """ try: self.health_imaging_client.tag_resource(resourceArn=resource_arn, tags=tags) except ClientError as err: logger.error( "Couldn't tag resource. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
The following code instantiates the MedicalImagingWrapper object.
client = boto3.client("medical-imaging") medical_imaging_wrapper = MedicalImagingWrapper(client)
-
For API details, see TagResource in AWS SDK for Python (Boto3) API Reference.
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. -