

# Add AWS resource tags to a configuration

You can add AWS resource tags to a configuration in two ways: by calling `TagResource` with the configuration's ARN and the tags to add, or by setting the `tags` parameter when you create or update a configuration with `PutStorageLensConfiguration`. `TagResource` adds the tags that you supply and leaves any other existing tags in place. You can add resource tags by using the Amazon S3 console, the AWS CLI, or the AWS SDKs.

## Using the S3 console
<a name="s3-tables-storage-lens-add-tags-console"></a>

In the Amazon S3 console, you add tags to an Amazon S3 Storage Lens for Tables configuration in the **General** step of the create or edit wizard. To add tags when you create a dashboard, see [Create an Amazon S3 Storage Lens for Tables dashboard](s3-tables-storage-lens-creating.md). To add tags to an existing dashboard, edit it:

**To add tags to an existing dashboard**

1. Sign in to the AWS Management Console and open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

1. In the left navigation pane, choose **Storage Lens**, and then choose the **Table buckets** tab.

1. Choose the dashboard that you want to tag, and then choose **Edit**.

1. In the **General** step, under **Tags - optional**, add a tag, and then enter a key and an optional value. You can add up to 50 tags.

1. Proceed through the remaining steps, and then on the **Review and create** step, choose **Submit**.

## Using the AWS CLI
<a name="s3-tables-storage-lens-add-tags-cli"></a>

**Example**  
The following example command adds tags to an Amazon S3 Storage Lens for Tables configuration. To use this example, replace the `{{user input placeholders}}` with your own information.  

```
aws s3tables tag-resource --resource-arn={{arn:aws:s3tables:us-east-1:222222222222:storage-lens/your-configuration-id}} --tags={{department=analytics,project=lakehouse}}
```

`tag-resource` adds or overwrites the keys that you supply and leaves other existing tags unchanged.

Alternatively, you can set tags inline when you create or update a configuration by passing the `tags` flag to the `put-storage-lens-configuration` command. The supplied tag set replaces the configuration's entire tag set. To use this example, replace the `{{user input placeholders}}` with your own information.

**Example**  

```
aws s3tables put-storage-lens-configuration --storage-lens-id={{your-configuration-id}} --storage-lens-configuration={{file://./config.json}} --tags={{department=analytics,project=lakehouse}}
```

## Using the AWS SDK for Java
<a name="s3-tables-storage-lens-add-tags-sdk-java"></a>

The following example adds tags to an Amazon S3 Storage Lens for Tables configuration in SDK for Java. To use this example, replace the `{{user input placeholders}}` with your own information.

**Example – Add tags to an Amazon S3 Storage Lens for Tables configuration**  

```Java
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3tables.S3TablesClient;
import software.amazon.awssdk.services.s3tables.model.TagResourceRequest;

import java.util.Map;

public class AddStorageLensTags {

    public static void main(String[] args) {
        String resourceArn = "{{arn:aws:s3tables:us-east-1:111122223333:storage-lens/your-configuration-id}}";

        try (S3TablesClient s3TablesClient = S3TablesClient.builder()
                .region(Region.{{US_EAST_1}})
                .build()) {

            s3TablesClient.tagResource(TagResourceRequest.builder()
                    .resourceArn(resourceArn)
                    .tags(Map.of(
                            "{{key-1}}", "{{value-1}}",
                            "{{key-2}}", "{{value-2}}"))
                    .build());
        }
    }
}
```

Alternatively, you can set tags inline when you create or update a configuration by passing the `tags` parameter to the `PutStorageLensConfiguration` operation. The supplied tag set replaces the configuration's entire tag set.

**Example – Set tags inline when you create or update a configuration**  

```Java
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3tables.S3TablesClient;
import software.amazon.awssdk.services.s3tables.model.PutStorageLensConfigurationRequest;
import software.amazon.awssdk.services.s3tables.model.StorageLensConfiguration;

import java.util.Map;

public class AddStorageLensTagsInline {

    public static void main(String[] args) {
        String configurationId = "{{your-configuration-id}}";

        try (S3TablesClient s3TablesClient = S3TablesClient.builder()
                .region(Region.{{US_EAST_1}})
                .build()) {

            StorageLensConfiguration configuration = StorageLensConfiguration.builder()
                    .id(configurationId)
                    .isEnabled(true)
                    // Set the remaining configuration fields for your dashboard.
                    .build();

            s3TablesClient.putStorageLensConfiguration(PutStorageLensConfigurationRequest.builder()
                    .storageLensId(configurationId)
                    .storageLensConfiguration(configuration)
                    .tags(Map.of(
                            "{{key-1}}", "{{value-1}}",
                            "{{key-2}}", "{{value-2}}"))
                    .build());
        }
    }
}
```