

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

# Markierung von Amazon-SNS-Themen
<a name="sns-tags"></a>

Amazon SNS unterstützt die Markierung von Amazon-SNS-Themen. Auf diese Weise können Sie die mit Ihren Themen verbundenen Kosten verfolgen und verwalten, die Sicherheit Ihrer AWS Identity and Access Management (IAM) -Richtlinien verbessern und Tausende von Themen einfach durchsuchen oder filtern. Mit Tagging können Sie Ihre Amazon SNS SNS-Themen mithilfe von AWS Resource Groups verwalten. Weitere Informationen zu Resource Groups finden Sie im [Benutzerhandbuch zu AWS Resource Groups](https://docs.aws.amazon.com/ARG/latest/userguide/resource-groups.html).

## Markierungen für die Kostenzuordnungen
<a name="tagging-for-cost-allocation"></a>

Zur Organisation und Identifizierung Ihrer Amazon-SNS-Themen für die Kostenzuordnung können Sie Tags hinzufügen, die den Zweck eines Themas identifizieren. Das ist vor allem dann nützlich, wenn Sie viele Themen haben. Mithilfe von Tags zur Kostenzuweisung können Sie Ihre AWS Rechnung so organisieren, dass sie Ihrer eigenen Kostenstruktur entspricht. Melden Sie sich dazu an, um Ihre AWS Kontorechnung mit den Tagschlüsseln und -werten zu erhalten. Weitere Informationen finden Sie unter [Einrichten eines monatlichen Kostenzuordnungsberichts](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/configurecostallocreport.html#allocation-report) im [Benutzerhandbuch zu AWS Billing and Cost Management](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/billing-what-is.html).

Beispielsweise können Sie wie folgt Tags hinzufügen, die die Kostenstelle und den Zweck Ihrer Amazon-SNS-Topics repräsentieren.

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/de_de/sns/latest/dg/sns-tags.html)

Dieses Markierungsschema ermöglicht es Ihnen, zwei Themen zu gruppieren, die verwandte Aufgaben für dieselbe Kostenstelle ausführen, während Sie eine unabhängige Aktivität mit einem anderen Tag für die Kostenzuordnung markieren.

## Markierungen für die Zugriffssteuerung
<a name="sns-tagging-for-access-control"></a>

AWS Identity and Access Management unterstützt die Steuerung des Zugriffs auf Ressourcen auf der Grundlage von Tags. Geben Sie nach der Markierung Ihrer Ressourcen Informationen über die Ressourcen-Tags im Bedingungselement einer Identity and Access Management (IAM)-Richtlinie an, um den tagbasierten Zugriff zu verwalten. Weitere Informationen darüber, wie Sie Ihre Ressourcen mit der [Amazon-SNS-Konsole](sns-tags-configuring.md#list-add-update-remove-tags-for-topic-aws-console) oder dem [AWS -SDK](sns-tags-configuring.md#tag-resource-aws-sdks) markieren, finden Sie unter [Konfigurieren von Tags](sns-tags-configuring.md).

Sie können den Zugriff auf eine IAM-Identität einschränken. Sie können z. B. den Zugriff von `Publish` und `PublishBatch` auf alle Amazon-SNS-Themen einschränken, die ein Tag mit dem Schlüssel `environment`und dem Wert `production` enthalten, während gleichzeitig Zugriff auf alle anderen Amazon-SNS-Themen gewährt wird. Im folgenden Beispiel schränkt die Richtlinie die Möglichkeit ein, Nachrichten zu Themen zu veröffentlichen, die mit `production` markiert sind, während Nachrichten zu Themen, die mit `development`gekennzeichnet sind, veröffentlicht werden können. Weitere Informationen finden Sie unter [Zugriffssteuerung mit Tags](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html) im IAM-Benutzerhandbuch.

**Anmerkung**  
Das Einrichten der IAM-Berechtigung für `Publish` legt die Berechtigung für sowohl für `Publish` als auch für `PublishBatch` fest.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [{
    "Effect": "Deny",
    "Action": [
	"sns:Publish"
    ],
    "Resource": "arn:aws:sns:*:*:*",
    "Condition": {
      "StringEquals": {
        "aws:ResourceTag/environment": "production"
      }
    }
  },
  {
    "Effect": "Allow",
    "Action": [
      "sns:Publish"
    ],
    "Resource": "arn:aws:sns:*:*:*",
    "Condition": {
      "StringEquals": {
        "aws:ResourceTag/environment": "development"
      }
    }
  }]
}
```

------

## Markierungen für die Suche und Filterung von Ressourcen
<a name="sns-tagging-for-searching-filtering"></a>

Ein AWS Konto kann Zehntausende von Amazon SNS SNS-Themen enthalten (weitere Informationen finden Sie unter [Amazon SNS SNS-Kontingente](https://docs.aws.amazon.com/general/latest/gr/sns.html)). Durch das Markieren Ihrer Themen erleichtern Sie sich das Durchsuchen oder Filtern von Themen.

Möglicherweise haben Sie z. B. hunderte Themen, die mit Ihrer Produktionsumgebung verknüpft sind. Anstatt manuell nach diesen Themen suchen zu müssen, können Sie alle Themen mit einem bestimmten Tag abfragen:

```
import com.amazonaws.services.resourcegroups.AWSResourceGroups;
import com.amazonaws.services.resourcegroups.AWSResourceGroupsClientBuilder;
import com.amazonaws.services.resourcegroups.model.QueryType;
import com.amazonaws.services.resourcegroups.model.ResourceQuery;
import com.amazonaws.services.resourcegroups.model.SearchResourcesRequest;
import com.amazonaws.services.resourcegroups.model.SearchResourcesResult;

public class Example {
    public static void main(String[] args) {
        // Query Amazon SNS Topics with tag "keyA" as "valueA"
        final String QUERY = "{\"ResourceTypeFilters\":[\"AWS::SNS::Topic\"],\"TagFilters\":[{\"Key\":\"keyA\", \"Values\":[\"valueA\"]}]}";

        // Initialize ResourceGroup client
        AWSResourceGroups awsResourceGroups = AWSResourceGroupsClientBuilder
            .standard()
            .build();

        // Query all resources with certain tags from ResourceGroups 
        SearchResourcesResult result = awsResourceGroups.searchResources(
            new SearchResourcesRequest().withResourceQuery(
                new ResourceQuery()
                .withType(QueryType.TAG_FILTERS_1_0)
                .withQuery(QUERY)
            ));
        System.out.println("SNS Topics with certain tags are " + result.getResourceIdentifiers());
    }
}
```

# Konfigurieren von Tags für ein Amazon-SNS-Thema
<a name="sns-tags-configuring"></a>

In diesem Thema wird erklärt, wie Sie Tags für ein [Amazon SNS SNS-Thema](sns-tags.md) mithilfe von AWS-Managementkonsole, einem AWS SDK oder dem AWS CLI konfigurieren.

**Wichtig**  
Fügen Sie keine personenbezogenen Daten (Personally Identifiable Information, PII) oder andere vertrauliche Informationen in Tags hinzu. Tags sind für andere Amazon Web Services zugänglich, einschließlich der Abrechnung. Tags sind nicht für private oder sensible Daten gedacht.

## Auflisten, Hinzufügen und Entfernen von Tags für ein Amazon SNS SNS-Thema mithilfe der AWS-Managementkonsole
<a name="list-add-update-remove-tags-for-topic-aws-console"></a>

1. Melden Sie sich bei der [Amazon-SNS-Konsole](https://console.aws.amazon.com/sns/home) an.

1. Wählen Sie im Navigationsbereich **Topics** (Themen) aus.

1. Wählen Sie auf der Seite **Topics (Themen)** ein Thema und anschließend **Edit (Bearbeiten)** aus.

1. Erweitern Sie den Abschnitt **Tags**.

   Die dem Thema hinzugefügten Tags werden aufgelistet.

1. Ändern von Themen-Tags:
   + Um ein Tag hinzuzufügen, wählen Sie **Add tag (Tag hinzufügen)** aus und geben Sie einen **Key (Schlüssel)** und einen **Value (Wert)** (optional) ein.
   + Zum Entfernen eines Tags wählen Sie neben einem Schlüssel-Wert-Paar **Remove tag (Tag entfernen)** aus.

1. Wählen Sie **Änderungen speichern ** aus.

## Hinzufügen von Tags zu einem Thema mithilfe eines SDK AWS
<a name="tag-resource-aws-sdks"></a>

Um ein AWS SDK verwenden zu können, müssen Sie es mit Ihren Anmeldeinformationen konfigurieren. Weitere Informationen finden Sie unter [The shared config and credentials files](https://docs.aws.amazon.com/sdkref/latest/guide/creds-config-files.html) im *AWS SDKs Referenzhandbuch zu Tools*.

Die folgenden Code-Beispiele zeigen, wie `TagResource` verwendet wird.

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

**AWS CLI**  
**So fügen Sie einem Thema ein Tag hinzu**  
Das folgende `tag-resource`-Beispiel fügt dem angegebenen Amazon-SNS-Thema ein Metadaten-Tag hinzu.  

```
aws sns tag-resource \
    --resource-arn arn:aws:sns:us-west-2:123456789012:MyTopic \
    --tags Key=Team,Value=Alpha
```
Mit diesem Befehl wird keine Ausgabe zurückgegeben.  
+  Einzelheiten zur API finden Sie [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/tag-resource.html)unter *AWS CLI Befehlsreferenz*. 

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

**SDK für Java 2.x**  
 Es gibt noch mehr dazu GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das [AWS -Code-Beispiel-](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/sns#code-examples) einrichten und ausführen. 

```
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);
        }
    }
}
```
+  Einzelheiten zur API finden Sie [TagResource](https://docs.aws.amazon.com/goto/SdkForJavaV2/sns-2010-03-31/TagResource)in der *AWS SDK for Java 2.x API-Referenz*. 

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

**SDK für Kotlin**  
 Es gibt noch mehr dazu GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das [AWS -Code-Beispiel-](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin/services/sns#code-examples) einrichten und ausführen. 

```
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")
    }
}
```
+  Einzelheiten zur API finden Sie [TagResource](https://sdk.amazonaws.com/kotlin/api/latest/index.html)in der *API-Referenz zum AWS SDK für Kotlin*. 

------

## Verwalten von Tags mit SNS-API-Aktionen von Amazon
<a name="manage-tags-with-sns-api-actions"></a>

Um Tags über die Amazon-SNS-API zu verwalten, verwenden Sie die folgenden API-Aktionen:
+ [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)

## API-Aktionen, die ABAC unterstützen
<a name="api-actions-that-support-abac"></a>

Im Folgenden finden Sie eine Liste von API-Aktionen, die Attribute-based Access Control (ABAC, attributbasierte Zugriffssteuerung) unterstützen. Weitere Informationen zu ABAC finden Sie unter [Wozu dient ABAC](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html)? AWS im *IAM-Benutzerhandbuch*.
+ [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)