tagResource method

Future<TagResourceResult> tagResource({
  1. required String resourceName,
  2. required List<Tag> tags,
  3. String? resourceArn,
})

Adds one or more tags to the specified Amazon Lightsail resource. Each resource can have a maximum of 50 tags. Each tag consists of a key and an optional value. Tag keys must be unique per resource. For more information about tags, see the Lightsail Dev Guide.

The tag resource operation supports tag-based access control via request tags and resource tags applied to the resource identified by resource name. For more information, see the Lightsail Dev Guide.

May throw ServiceException. May throw InvalidInputException. May throw NotFoundException. May throw OperationFailureException. May throw AccessDeniedException. May throw AccountSetupInProgressException. May throw UnauthenticatedException.

Parameter resourceName : The name of the resource to which you are adding tags.

Parameter tags : The tag key and optional value.

Parameter resourceArn : The Amazon Resource Name (ARN) of the resource to which you want to add a tag.

Implementation

Future<TagResourceResult> tagResource({
  required String resourceName,
  required List<Tag> tags,
  String? resourceArn,
}) async {
  ArgumentError.checkNotNull(resourceName, 'resourceName');
  ArgumentError.checkNotNull(tags, 'tags');
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Lightsail_20161128.TagResource'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'resourceName': resourceName,
      'tags': tags,
      if (resourceArn != null) 'resourceArn': resourceArn,
    },
  );

  return TagResourceResult.fromJson(jsonResponse.body);
}