

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Mengonfigurasi tag topik Amazon SNS
<a name="sns-tags-configuring"></a>

Topik ini menjelaskan cara mengonfigurasi tag untuk [topik Amazon SNS](sns-tags.md) menggunakan Konsol Manajemen AWS, AWS SDK, atau. AWS CLI

**penting**  
Jangan menambahkan informasi pengenal pribadi (PII) atau informasi rahasia atau sensitif lainnya dalam tag. Tag dapat diakses oleh Amazon Web Services lainnya, termasuk penagihan. Tag tidak dimaksudkan untuk digunakan dalam data sensitif atau privat.

## Membuat daftar, menambahkan, dan menghapus tag untuk topik Amazon SNS menggunakan Konsol Manajemen AWS
<a name="list-add-update-remove-tags-for-topic-aws-console"></a>

1. Masuk ke [Konsol Amazon SNS](https://console.aws.amazon.com/sns/home).

1. Di panel navigasi, pilih **Topics (Topik)**.

1. Di halaman **Topics (Topik)**, pilih topik dan kemudian pilih **Edit (Edit)**.

1. Perluas bagian **Tags (Tag)**.

   Tag yang ditambahkan ke topik terdaftar.

1. Modifikasi tag topik:
   + Untuk menambahkan tag, pilih **Tambah tag** dan masukkan **Kunci** dan **Nilai** (opsional).
   + Untuk menghapus tag, pilih **Remove tag (Hapus tag)** di samping pasangan nilai kunci.

1. Pilih **Simpan perubahan**.

## Menambahkan tag ke topik menggunakan AWS SDK
<a name="tag-resource-aws-sdks"></a>

Untuk menggunakan AWS SDK, Anda harus mengonfigurasinya dengan kredensi Anda. Untuk informasi selengkapnya, lihat [File konfigurasi dan kredensial bersama](https://docs.aws.amazon.com/sdkref/latest/guide/creds-config-files.html) di Panduan Referensi *Alat AWS SDKs dan Alat*.

Contoh kode berikut menunjukkan cara menggunakan`TagResource`.

------
#### [ CLI ]

**AWS CLI**  
**Untuk menambahkan tag ke topik**  
`tag-resource`Contoh berikut menambahkan tag metadata ke topik Amazon SNS yang ditentukan.  

```
aws sns tag-resource \
    --resource-arn arn:aws:sns:us-west-2:123456789012:MyTopic \
    --tags Key=Team,Value=Alpha
```
Perintah ini tidak menghasilkan output.  
+  Untuk detail API, lihat [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/tag-resource.html)di *Referensi AWS CLI Perintah*. 

------
#### [ Java ]

**SDK untuk Java 2.x**  
 Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di [Repositori Contoh Kode AWS](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/sns#code-examples). 

```
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.SnsException;
import software.amazon.awssdk.services.sns.model.Tag;
import software.amazon.awssdk.services.sns.model.TagResourceRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Before running this Java V2 code example, set up your development
 * environment, including your credentials.
 *
 * For more information, see the following documentation topic:
 *
 * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
 */
public class AddTags {
    public static void main(String[] args) {
        final String usage = """

                Usage:    <topicArn>

                Where:
                   topicArn - The ARN of the topic to which tags are added.

                """;

        if (args.length != 1) {
            System.out.println(usage);
            System.exit(1);
        }

        String topicArn = args[0];
        SnsClient snsClient = SnsClient.builder()
                .region(Region.US_EAST_1)
                .build();

        addTopicTags(snsClient, topicArn);
        snsClient.close();
    }

    public static void addTopicTags(SnsClient snsClient, String topicArn) {
        try {
            Tag tag = Tag.builder()
                    .key("Team")
                    .value("Development")
                    .build();

            Tag tag2 = Tag.builder()
                    .key("Environment")
                    .value("Gamma")
                    .build();

            List<Tag> tagList = new ArrayList<>();
            tagList.add(tag);
            tagList.add(tag2);

            TagResourceRequest tagResourceRequest = TagResourceRequest.builder()
                    .resourceArn(topicArn)
                    .tags(tagList)
                    .build();

            snsClient.tagResource(tagResourceRequest);
            System.out.println("Tags have been added to " + topicArn);

        } catch (SnsException e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
    }
}
```
+  Untuk detail API, lihat [TagResource](https://docs.aws.amazon.com/goto/SdkForJavaV2/sns-2010-03-31/TagResource)di *Referensi AWS SDK for Java 2.x API*. 

------
#### [ Kotlin ]

**SDK untuk Kotlin**  
 Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di [Repositori Contoh Kode AWS](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin/services/sns#code-examples). 

```
suspend fun addTopicTags(topicArn: String) {
    val tag =
        Tag {
            key = "Team"
            value = "Development"
        }

    val tag2 =
        Tag {
            key = "Environment"
            value = "Gamma"
        }

    val tagList = mutableListOf<Tag>()
    tagList.add(tag)
    tagList.add(tag2)

    val request =
        TagResourceRequest {
            resourceArn = topicArn
            tags = tagList
        }

    SnsClient.fromEnvironment { region = "us-east-1" }.use { snsClient ->
        snsClient.tagResource(request)
        println("Tags have been added to $topicArn")
    }
}
```
+  Untuk detail API, lihat [TagResource](https://sdk.amazonaws.com/kotlin/api/latest/index.html)di *AWS SDK untuk referensi API Kotlin*. 

------

## Mengelola tag dengan tindakan API Amazon SNS
<a name="manage-tags-with-sns-api-actions"></a>

Untuk mengelola tag menggunakan Amazon SNS API, gunakan tindakan API berikut:
+ [https://docs.aws.amazon.com/sns/latest/api/API_ListTagsForResource.html](https://docs.aws.amazon.com/sns/latest/api/API_ListTagsForResource.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_TagResource.html](https://docs.aws.amazon.com/sns/latest/api/API_TagResource.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_UntagResource.html](https://docs.aws.amazon.com/sns/latest/api/API_UntagResource.html)

## Tindakan API yang mendukung ABAC
<a name="api-actions-that-support-abac"></a>

Berikut ini adalah daftar tindakan API yang mendukung kontrol akses berbasis atribut (ABAC). Untuk detail lebih lanjut tentang ABAC, lihat Untuk [apa ABAC? AWS](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html) di *Panduan Pengguna IAM*.
+ [https://docs.aws.amazon.com/sns/latest/api/API_AddPermission.html](https://docs.aws.amazon.com/sns/latest/api/API_AddPermission.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_ConfirmSubscription.html](https://docs.aws.amazon.com/sns/latest/api/API_ConfirmSubscription.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_DeleteTopic.html](https://docs.aws.amazon.com/sns/latest/api/API_DeleteTopic.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_GetDataProtectionPolicy.html](https://docs.aws.amazon.com/sns/latest/api/API_GetDataProtectionPolicy.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_GetSubscriptionAttributes.html](https://docs.aws.amazon.com/sns/latest/api/API_GetSubscriptionAttributes.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_GetTopicAttributes.html](https://docs.aws.amazon.com/sns/latest/api/API_GetTopicAttributes.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_ListSubscriptionsByTopic.html](https://docs.aws.amazon.com/sns/latest/api/API_ListSubscriptionsByTopic.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_ListTagsForResource.html](https://docs.aws.amazon.com/sns/latest/api/API_ListTagsForResource.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_Publish.html](https://docs.aws.amazon.com/sns/latest/api/API_Publish.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_PublishBatch.html](https://docs.aws.amazon.com/sns/latest/api/API_PublishBatch.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_PutDataProtectionPolicy.html](https://docs.aws.amazon.com/sns/latest/api/API_PutDataProtectionPolicy.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_RemovePermission.html](https://docs.aws.amazon.com/sns/latest/api/API_RemovePermission.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_SetSubscriptionAttributes.html](https://docs.aws.amazon.com/sns/latest/api/API_SetSubscriptionAttributes.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_SetTopicAttributes.html](https://docs.aws.amazon.com/sns/latest/api/API_SetTopicAttributes.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html](https://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_TagResource.html](https://docs.aws.amazon.com/sns/latest/api/API_TagResource.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_Unsubscribe.html](https://docs.aws.amazon.com/sns/latest/api/API_Unsubscribe.html)
+ [https://docs.aws.amazon.com/sns/latest/api/API_UntagResource.html](https://docs.aws.amazon.com/sns/latest/api/API_UntagResource.html)