

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.

# Aktivieren Sie Amazon GuardDuty unter bestimmten Bedingungen mithilfe von Vorlagen AWS CloudFormation
<a name="enable-amazon-guardduty-conditionally-by-using-aws-cloudformation-templates"></a>

*Ram Kandaswamy, Amazon Web Services*

## Zusammenfassung
<a name="enable-amazon-guardduty-conditionally-by-using-aws-cloudformation-templates-summary"></a>

[AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html), ein IaC-Tool (Infrastructure as Code), hilft Ihnen bei der Verwaltung AWS von Ressourcen durch vorlagenbasierte Bereitstellungen. CloudFormation wird in der Regel zur Verwaltung von Ressourcen verwendet. AWS Es zu aktivieren AWS-Services, wie [Amazon GuardDuty](https://docs.aws.amazon.com/guardduty/latest/ug/what-is-guardduty.html), kann besondere Herausforderungen mit sich bringen. GuardDuty ist ein Dienst zur Erkennung von Bedrohungen, der Sie kontinuierlich auf AWS-Konten böswillige Aktivitäten und unbefugtes Verhalten überwacht. Im Gegensatz zu typischen Ressourcen, die mehrfach erstellt werden können, GuardDuty handelt es sich um einen Dienst, der einmal pro Konto aktiviert werden muss und AWS-Region. Herkömmliche CloudFormation Bedingungen unterstützen nur statische Wertvergleiche, was es schwierig macht, den aktuellen Status von Diensten wie zu überprüfen GuardDuty. Wenn Sie versuchen, die Aktivierung CloudFormation in GuardDuty einem Konto durchzuführen, in dem es bereits aktiv ist, schlägt die Stack-Bereitstellung fehl. Dies kann zu betrieblichen Herausforderungen für DevOps Teams führen, die Umgebungen mit mehreren Konten verwalten.

Dieses Muster bietet eine Lösung für diese Herausforderung. Es verwendet CloudFormation benutzerdefinierte Ressourcen, die von [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)Funktionen unterstützt werden, um dynamische Zustandsprüfungen durchzuführen. Die bedingte Logik wird GuardDuty nur aktiviert, wenn sie nicht bereits aktiviert ist. Es verwendet die Stack-Ausgaben, um den GuardDuty Status zur future Referenz aufzuzeichnen.

Wenn Sie diesem Muster folgen, können Sie GuardDuty Bereitstellungen in Ihrer gesamten AWS Infrastruktur automatisieren und gleichzeitig einen sauberen, vorhersehbaren CloudFormation Stack-Betrieb aufrechterhalten. Dieser Ansatz ist besonders wertvoll für Unternehmen, die:
+ Verwaltung mehrerer AWS-Konten über IaC
+ Implementierung von Sicherheitsdiensten in großem Maßstab
+ Erforderlich sind idempotente Infrastrukturbereitstellungen
+ Automatisierung der Bereitstellung von Sicherheitsdiensten

## Voraussetzungen und Einschränkungen
<a name="enable-amazon-guardduty-conditionally-by-using-aws-cloudformation-templates-prereqs"></a>

**Voraussetzungen**
+ Ein aktiver AWS-Konto
+ Eine AWS Identity and Access Management (IAM-) Rolle, die über Berechtigungen zum Erstellen, Aktualisieren und Löschen CloudFormation von Stacks verfügt
+ AWS Command Line Interface [(AWS CLI), [installiert und konfiguriert](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html#getting-started-install-instructions)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)

**Einschränkungen**

Wenn dieses Muster für ein AWS-Konto oder manuell deaktiviert GuardDuty wurde AWS-Region, wird es GuardDuty für dieses Zielkonto oder diese Region nicht aktiviert.

## Architektur
<a name="enable-amazon-guardduty-conditionally-by-using-aws-cloudformation-templates-architecture"></a>

**Zieltechnologie-Stack**

Das Muster wird CloudFormation für Infrastructure as Code (IaC) verwendet. Sie verwenden eine CloudFormation benutzerdefinierte Ressource, die von einer Lambda-Funktion unterstützt wird, um die dynamische Service-Enablement-Funktion zu erreichen.

**Zielarchitektur**

Das folgende Architekturdiagramm auf hoher Ebene zeigt den Prozess der Aktivierung GuardDuty durch die Bereitstellung einer CloudFormation Vorlage:

![\[Verwendung eines CloudFormation Stacks zur Aktivierung GuardDuty in einem AWS-Konto.\]](http://docs.aws.amazon.com/de_de/prescriptive-guidance/latest/patterns/images/pattern-img/3abd7cb7-0937-41fe-8eaa-79aedb182732/images/71624052-eebc-474a-9aa3-8606d87fc51d.png)


1. Sie stellen eine CloudFormation Vorlage bereit, um einen CloudFormation Stack zu erstellen.

1. Der Stack erstellt eine IAM-Rolle und eine Lambda-Funktion.

1. Die Lambda-Funktion übernimmt die IAM-Rolle.

1. Wenn GuardDuty es auf dem Ziel noch nicht aktiviert ist AWS-Konto, aktiviert es die Lambda-Funktion.

**Automatisierung und Skalierung**

Sie können die AWS CloudFormation StackSet Funktion verwenden, um diese Lösung auf mehrere AWS-Konten und auszudehnen AWS-Regionen. Weitere Informationen finden Sie AWS CloudFormation StackSets in der CloudFormation Dokumentation unter [Arbeiten mit](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/what-is-cfnstacksets.html).

## Tools
<a name="enable-amazon-guardduty-conditionally-by-using-aws-cloudformation-templates-tools"></a>
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) ist ein Open-Source-Tool, mit dem Sie AWS-Services über Befehle in Ihrer Befehlszeilen-Shell interagieren können.
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)hilft Ihnen dabei, AWS Ressourcen einzurichten, sie schnell und konsistent bereitzustellen und sie während ihres gesamten Lebenszyklus regionsübergreifend AWS-Konten zu verwalten.
+ [Amazon GuardDuty](https://docs.aws.amazon.com/guardduty/latest/ug/what-is-guardduty.html) ist ein Dienst zur kontinuierlichen Sicherheitsüberwachung, der Protokolle analysiert und verarbeitet, um unerwartete und potenziell nicht autorisierte Aktivitäten in Ihrer AWS Umgebung zu identifizieren.
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) hilft Ihnen dabei, den Zugriff auf Ihre AWS Ressourcen sicher zu verwalten, indem kontrolliert wird, wer authentifiziert und zu deren Nutzung berechtigt ist.
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) ist ein Datenverarbeitungsservice, mit dem Sie Code ausführen können, ohne dass Sie Server bereitstellen oder verwalten müssen. Es führt Ihren Code nur bei Bedarf aus und skaliert automatisch, sodass Sie nur für die tatsächlich genutzte Rechenzeit zahlen.

## Epen
<a name="enable-amazon-guardduty-conditionally-by-using-aws-cloudformation-templates-epics"></a>

### Erstellen Sie die CloudFormation Vorlage und stellen Sie den Stack bereit
<a name="create-the-cfnshort-template-and-deploy-the-stack"></a>


| Aufgabe | Description | Erforderliche Fähigkeiten | 
| --- | --- | --- | 
| Speichern Sie den Code in Amazon S3. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/de_de/prescriptive-guidance/latest/patterns/enable-amazon-guardduty-conditionally-by-using-aws-cloudformation-templates.html) | AWS DevOps | 
| Erstellen Sie die CloudFormation Vorlage. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/de_de/prescriptive-guidance/latest/patterns/enable-amazon-guardduty-conditionally-by-using-aws-cloudformation-templates.html) | AWS DevOps | 
| Erstellen Sie den CloudFormation Stack. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/de_de/prescriptive-guidance/latest/patterns/enable-amazon-guardduty-conditionally-by-using-aws-cloudformation-templates.html) | AWS DevOps | 
| Überprüfen Sie, ob dies für aktiviert GuardDuty ist AWS-Konto. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/de_de/prescriptive-guidance/latest/patterns/enable-amazon-guardduty-conditionally-by-using-aws-cloudformation-templates.html) | Cloud-Administrator, AWS-Administrator | 
| Konfigurieren Sie zusätzliche Konten oder Regionen. | Verwenden Sie die CloudFormation StackSet Funktion je nach Bedarf für Ihren Anwendungsfall, um diese Lösung auf mehrere AWS-Konten und auszudehnen AWS-Regionen. Weitere Informationen finden Sie AWS CloudFormation StackSets in der CloudFormation Dokumentation unter [Arbeiten mit](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/what-is-cfnstacksets.html). | Cloud-Administrator, AWS-Administrator | 

## Zugehörige Ressourcen
<a name="enable-amazon-guardduty-conditionally-by-using-aws-cloudformation-templates-resources"></a>

**Referenzen**
+ [AWS CloudFormation Dokumentation](https://docs.aws.amazon.com/cloudformation/index.html)
+ [AWS Lambda Referenz zum Ressourcentyp](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_Lambda.html)
+ [CloudFormation Ressourcentyp: AWS: :IAM: :Rolle](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html)
+ [CloudFormation Ressourcentyp::: AWS: Detector GuardDuty](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-guardduty-detector.html)
+ [Vier Möglichkeiten zum Abrufen beliebiger AWS Service-Eigenschaften mithilfe von AWS CloudFormation](https://aws.amazon.com/blogs/mt/four-ways-to-retrieve-any-aws-service-property-using-aws-cloudformation-part-1/) (Blogbeitrag)

**Tutorials und Videos**
+ [Vereinfachen Sie Ihr Infrastrukturmanagement mithilfe von AWS CloudFormation](https://www.youtube.com/watch?v=1h-GPXQrLZw) (Tutorial)
+ [Verwenden Sie Amazon GuardDuty und sichern AWS Security Hub CSPM Sie mehrere Konten](https://www.youtube.com/watch?v=Rg2ZzAAi1nY) (AWS re:Invent 2020)
+ [Bewährte Methoden für die Inhaltserstellung (re:Invent AWS CloudFormation](https://www.youtube.com/watch?v=bJHHQM7GGro) 2019)AWS 
+ [Bedrohungserkennung auf AWS: Eine Einführung in Amazon GuardDuty](https://www.youtube.com/watch?v=czsuZXQvD8E) (AWS re:INFORCE 2019)

## Zusätzliche Informationen
<a name="enable-amazon-guardduty-conditionally-by-using-aws-cloudformation-templates-additional"></a>

**Python-Kode**

```
import boto3
import os
import json
from botocore.exceptions import ClientError
import cfnresponse
guardduty=boto3.client('guardduty')
cfn=boto3.client('cloudformation')
def lambda_handler(event, context):
    print('Event: ', event)
    if 'RequestType' in event:    
      if event['RequestType'] in ["Create","Update"]:
          enabled=False
          try:  
            response=guardduty.list_detectors()
            if "DetectorIds" in response and len(response["DetectorIds"])>0:
              enabled="AlreadyEnabled"
            elif "DetectorIds" in response and len(response["DetectorIds"])==0:
              cfn_response=cfn.create_stack(
                StackName='guardduty-cfn-stack',
                TemplateBody='{ "AWSTemplateFormatVersion": "2010-09-09",    "Description": "Guard duty creation template",    "Resources": { "IRWorkshopGuardDutyDetector": {  "Type": "AWS::GuardDuty::Detector",    "Properties": {   "Enable": true  }   } } }'
                )
              enabled="True"
          except Exception as e:
              print("Exception: ",e)
          responseData = {}
          responseData['status'] = enabled
          cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData, "CustomResourcePhysicalID" )
      elif event['RequestType'] == "Delete":
          cfn_response=cfn.delete_stack(
                  StackName='guardduty-cfn-stack')
          cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
```

