

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.

# Erstelle AWS Secrets Manager Geheimnisse in AWS CloudFormation
<a name="cloudformation"></a>

Sie können Geheimnisse in einem CloudFormation Stapel erstellen, indem Sie die `[ AWS::SecretsManager::Secret](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-secret.html)` Ressource in einer CloudFormation Vorlage verwenden, wie unter gezeigt[Ein Secret erstellen](cfn-example_secret.md). 

Um ein Admin-Secret für Amazon RDS oder Aurora zu erstellen, empfehlen wir Ihnen, `ManageMasterUserPassword` in [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbcluster.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbcluster.html) zu verwenden. Dann erstellt Amazon RDS das Secret und verwaltet die Rotation für Sie. Weitere Informationen finden Sie unter [Verwaltete Rotation](rotate-secrets_managed.md).

Für Amazon-Redshift- und Amazon-DocumentDB-Anmeldeinformationen erstellen Sie zunächst ein Secret mit einem von Secrets Manager generierten Passwort und verwenden dann eine [dynamische Referenz](cfn-example_reference-secret.md), um den Benutzernamen und das Passwort aus dem Secret abzurufen und als Anmeldeinformationen für eine neue Datenbank zu verwenden. Als nächstes verwenden Sie die `[ AWS::SecretsManager::SecretTargetAttachment](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-secrettargetattachment.html)`-Ressource, um dem Secret Details über die Datenbank hinzuzufügen, die Secrets Manager benötigt, um das Secret zu rotieren. Verwenden Sie abschließend die `[ AWS::SecretsManager::RotationSchedule](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-rotationschedule.html)`-Ressource und geben Sie eine [Rotationsfunktion](reference_available-rotation-templates.md) und einen [Zeitplan](rotate-secrets_schedule.md) an, um die automatische Rotation zu aktivieren. Im Folgenden sind einige Beispiele aufgeführt:
+ [Erstellen eines Secrets mit Amazon-Redshift-Anmeldeinformationen](cfn-example_Redshift-secret.md)
+ [Erstellen eines Secrets mit Amazon-DocumentDB-Anmeldeinformationen](cfn-example_DocDB-secret.md)

Um eine Ressourcenrichtlinie an Ihr Geheimnis anzufügen, verwenden Sie die Ressource `[ AWS::SecretsManager::ResourcePolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-resourcepolicy.html)`.



Informationen zum Erstellen von Ressourcen mit CloudFormation finden [Sie im CloudFormation Benutzerhandbuch unter Grundlagen von Vorlagen lernen](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/gettingstarted.templatebasics.html). Sie können auch die AWS Cloud Development Kit (AWS CDK) verwenden. Weitere Informationen finden Sie unter [AWS Secrets Manager Construct Library](https://docs.aws.amazon.com/cdk/api/latest/docs/aws-secretsmanager-readme.html).

# Erstelle ein AWS Secrets Manager Geheimnis mit CloudFormation
<a name="cfn-example_secret"></a>

In diesem Beispiel wird ein Secret mit dem Namen **CloudFormationCreatedSecret-*a1b2c3d4e5f6*** erstellt. Der Secret-Wert ist der folgende JSON mit einem Passwort mit 32 Zeichen, das beim Erstellen des Secrets generiert wird.

```
{
    "password": "EXAMPLE-PASSWORD",
    "username": "saanvi"
}
```

In diesem Beispiel wird die folgende CloudFormation Ressource verwendet:
+ [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-secret.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-secret.html)

Informationen zum Erstellen von Ressourcen mit CloudFormation finden [Sie unter Grundlagen der Lernvorlage](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/gettingstarted.templatebasics.html) im CloudFormation Benutzerhandbuch.

## JSON
<a name="cfn-example_secret.json"></a>

```
{
    "Resources": {
        "CloudFormationCreatedSecret": {
            "Type": "AWS::SecretsManager::Secret",
            "Properties": {
                "Description": "Simple secret created by CloudFormation.",
                "GenerateSecretString": {
                    "SecretStringTemplate": "{\"username\": \"saanvi\"}",
                    "GenerateStringKey": "password",
                    "PasswordLength": 32
                }
            }
        }
    }
}
```

## YAML
<a name="cfn-example_secret.yaml"></a>

```
Resources:
  CloudFormationCreatedSecret:
    Type: 'AWS::SecretsManager::Secret'
    Properties:
      Description: Simple secret created by CloudFormation.
      GenerateSecretString:
        SecretStringTemplate: '{"username": "saanvi"}'
        GenerateStringKey: password
        PasswordLength: 32
```

# Erstellen Sie ein AWS Secrets Manager Geheimnis mit automatischer Rotation und einer Amazon RDS MySQL-DB-Instance mit CloudFormation
<a name="cfn-example_RDSsecret"></a>

Um ein Admin-Secret für Amazon RDS oder Aurora zu erstellen, empfehlen wir die Verwendung von `ManageMasterUserPassword`, wie im Beispiel *Erstellen eines Secrets-Manager-Secrets für ein Master-Passwort* in [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbcluster.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbcluster.html) gezeigt. Dann erstellt Amazon RDS das Secret und verwaltet die Rotation für Sie. Weitere Informationen finden Sie unter [Verwaltete Rotation](rotate-secrets_managed.md).

# Erstellen Sie ein AWS Secrets Manager Geheimnis und einen Amazon Redshift Redshift-Cluster mit CloudFormation
<a name="cfn-example_Redshift-secret"></a>

Um ein Administratorgeheimnis für Amazon Redshift zu erstellen, empfehlen wir Ihnen, die Beispiele auf [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-redshift-cluster.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-redshift-cluster.html)und [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-redshiftserverless-namespace.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-redshiftserverless-namespace.html)zu verwenden. 

# Erstellen Sie ein AWS Secrets Manager Geheimnis und eine Amazon DocumentDB DocumentDB-Instance mit CloudFormation
<a name="cfn-example_DocDB-secret"></a>

In diesem Beispiel werden ein Geheimnis und eine Amazon-DocumentDB-Instance erstellt, wobei die Anmeldeinformationen im Geheimnis als Benutzer und Passwort verwendet werden. Das Secret verfügt über eine zugeordnete ressourcenbasierte Richtlinie, die angibt, wer Zugriff auf das Secret hat. Die Vorlage erstellt außerdem eine Lambda-Drehungsfunktion von den [Rotationsfunktionsvorlagen](reference_available-rotation-templates.md) und konfiguriert das Geheimnis so, dass es am ersten Tag eines jeden Monats automatisch zwischen 8:00 und 10:00 Uhr UTC gedreht wird. Als bewährte Methode für Sicherheit befindet sich die Instance in einer Amazon VPC. 

In diesem Beispiel werden die folgenden CloudFormation Ressourcen für Secrets Manager verwendet:
+ [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-secret.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-secret.html)
+ [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-secrettargetattachment.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-secrettargetattachment.html)
+ [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-rotationschedule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-rotationschedule.html)

Informationen zum Erstellen von Ressourcen mit CloudFormation finden [Sie im CloudFormation Benutzerhandbuch unter Grundlagen von Vorlagen lernen](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/gettingstarted.templatebasics.html).

## JSON
<a name="cfn-example_DocDB-secret.json"></a>

```
{
   "AWSTemplateFormatVersion":"2010-09-09",
   "Transform":"AWS::SecretsManager-2020-07-23",
   "Resources":{
      "TestVPC":{
         "Type":"AWS::EC2::VPC",
         "Properties":{
            "CidrBlock":"10.0.0.0/16",
            "EnableDnsHostnames":true,
            "EnableDnsSupport":true
         }
      },
      "TestSubnet01":{
         "Type":"AWS::EC2::Subnet",
         "Properties":{
            "CidrBlock":"10.0.96.0/19",
            "AvailabilityZone":{
               "Fn::Select":[
                  "0",
                  {
                     "Fn::GetAZs":{
                        "Ref":"AWS::Region"
                     }
                  }
               ]
            },
            "VpcId":{
               "Ref":"TestVPC"
            }
         }
      },
      "TestSubnet02":{
         "Type":"AWS::EC2::Subnet",
         "Properties":{
            "CidrBlock":"10.0.128.0/19",
            "AvailabilityZone":{
               "Fn::Select":[
                  "1",
                  {
                     "Fn::GetAZs":{
                        "Ref":"AWS::Region"
                     }
                  }
               ]
            },
            "VpcId":{
               "Ref":"TestVPC"
            }
         }
      },
      "SecretsManagerVPCEndpoint":{
         "Type":"AWS::EC2::VPCEndpoint",
         "Properties":{
            "SubnetIds":[
               {
                  "Ref":"TestSubnet01"
               },
               {
                  "Ref":"TestSubnet02"
               }
            ],
            "SecurityGroupIds":[
               {
                  "Fn::GetAtt":[
                     "TestVPC",
                     "DefaultSecurityGroup"
                  ]
               }
            ],
            "VpcEndpointType":"Interface",
            "ServiceName":{
               "Fn::Sub":"com.amazonaws.${AWS::Region}.secretsmanager"
            },
            "PrivateDnsEnabled":true,
            "VpcId":{
               "Ref":"TestVPC"
            }
         }
      },
      "MyDocDBClusterRotationSecret":{
         "Type":"AWS::SecretsManager::Secret",
         "Properties":{
            "GenerateSecretString":{
               "SecretStringTemplate":"{\"username\": \"someadmin\",\"ssl\": true}",
               "GenerateStringKey":"password",
               "PasswordLength":16,
               "ExcludeCharacters":"\"@/\\"
            },
            "Tags":[
               {
                  "Key":"AppName",
                  "Value":"MyApp"
               }
            ]
         }
      },
      "MyDocDBCluster":{
         "Type":"AWS::DocDB::DBCluster",
         "Properties":{
            "DBSubnetGroupName":{
               "Ref":"MyDBSubnetGroup"
            },
            "MasterUsername":{
               "Fn::Sub":"{{resolve:secretsmanager:${MyDocDBClusterRotationSecret}::username}}"
            },
            "MasterUserPassword":{
               "Fn::Sub":"{{resolve:secretsmanager:${MyDocDBClusterRotationSecret}::password}}"
            },
            "VpcSecurityGroupIds":[
               {
                  "Fn::GetAtt":[
                     "TestVPC",
                     "DefaultSecurityGroup"
                  ]
               }
            ]
         }
      },
      "DocDBInstance":{
         "Type":"AWS::DocDB::DBInstance",
         "Properties":{
            "DBClusterIdentifier":{
               "Ref":"MyDocDBCluster"
            },
            "DBInstanceClass":"db.r5.large"
         }
      },
      "MyDBSubnetGroup":{
         "Type":"AWS::DocDB::DBSubnetGroup",
         "Properties":{
            "DBSubnetGroupDescription":"",
            "SubnetIds":[
               {
                  "Ref":"TestSubnet01"
               },
               {
                  "Ref":"TestSubnet02"
               }
            ]
         }
      },
      "SecretDocDBClusterAttachment":{
         "Type":"AWS::SecretsManager::SecretTargetAttachment",
         "Properties":{
            "SecretId":{
               "Ref":"MyDocDBClusterRotationSecret"
            },
            "TargetId":{
               "Ref":"MyDocDBCluster"
            },
            "TargetType":"AWS::DocDB::DBCluster"
         }
      },
      "MySecretRotationSchedule":{
         "Type":"AWS::SecretsManager::RotationSchedule",
         "DependsOn":"SecretDocDBClusterAttachment",
         "Properties":{
            "SecretId":{
               "Ref":"MyDocDBClusterRotationSecret"
            },
            "HostedRotationLambda":{
               "RotationType":"MongoDBSingleUser",
               "RotationLambdaName":"MongoDBSingleUser",
               "VpcSecurityGroupIds":{
                  "Fn::GetAtt":[
                     "TestVPC",
                     "DefaultSecurityGroup"
                  ]
               },
               "VpcSubnetIds":{
                  "Fn::Join":[
                     ",",
                     [
                        {
                           "Ref":"TestSubnet01"
                        },
                        {
                           "Ref":"TestSubnet02"
                        }
                     ]
                  ]
               }
            },
            "RotationRules":{
              "Duration": "2h",
              "ScheduleExpression": "cron(0 8 1 * ? *)"
            }
         }
      }
   }
}
```

## YAML
<a name="cfn-example_DocDB-secret.yaml"></a>

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::SecretsManager-2020-07-23
Resources:
  TestVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      EnableDnsHostnames: true
      EnableDnsSupport: true
  TestSubnet01:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: 10.0.96.0/19
      AvailabilityZone: !Select
        - '0'
        - !GetAZs
          Ref: AWS::Region
      VpcId: !Ref TestVPC
  TestSubnet02:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: 10.0.128.0/19
      AvailabilityZone: !Select
        - '1'
        - !GetAZs
          Ref: AWS::Region
      VpcId: !Ref TestVPC
  SecretsManagerVPCEndpoint:
    Type: AWS::EC2::VPCEndpoint
    Properties:
      SubnetIds:
        - !Ref TestSubnet01
        - !Ref TestSubnet02
      SecurityGroupIds:
        - !GetAtt TestVPC.DefaultSecurityGroup
      VpcEndpointType: Interface
      ServiceName: !Sub com.amazonaws.${AWS::Region}.secretsmanager
      PrivateDnsEnabled: true
      VpcId: !Ref TestVPC
  MyDocDBClusterRotationSecret:
    Type: AWS::SecretsManager::Secret
    Properties:
      GenerateSecretString:
        SecretStringTemplate: '{"username": "someadmin","ssl": true}'
        GenerateStringKey: password
        PasswordLength: 16
        ExcludeCharacters: '"@/\'
      Tags:
        - Key: AppName
          Value: MyApp
  MyDocDBCluster:
    Type: AWS::DocDB::DBCluster
    Properties:
      DBSubnetGroupName: !Ref MyDBSubnetGroup
      MasterUsername: !Sub '{{resolve:secretsmanager:${MyDocDBClusterRotationSecret}::username}}'
      MasterUserPassword: !Sub '{{resolve:secretsmanager:${MyDocDBClusterRotationSecret}::password}}'
      VpcSecurityGroupIds:
        - !GetAtt TestVPC.DefaultSecurityGroup
  DocDBInstance:
    Type: AWS::DocDB::DBInstance
    Properties:
      DBClusterIdentifier: !Ref MyDocDBCluster
      DBInstanceClass: db.r5.large
  MyDBSubnetGroup:
    Type: AWS::DocDB::DBSubnetGroup
    Properties:
      DBSubnetGroupDescription: ''
      SubnetIds:
        - !Ref TestSubnet01
        - !Ref TestSubnet02
  SecretDocDBClusterAttachment:
    Type: AWS::SecretsManager::SecretTargetAttachment
    Properties:
      SecretId: !Ref MyDocDBClusterRotationSecret
      TargetId: !Ref MyDocDBCluster
      TargetType: AWS::DocDB::DBCluster
  MySecretRotationSchedule:
    Type: AWS::SecretsManager::RotationSchedule
    DependsOn: SecretDocDBClusterAttachment
    Properties:
      SecretId: !Ref MyDocDBClusterRotationSecret
      HostedRotationLambda:
        RotationType: MongoDBSingleUser
        RotationLambdaName: MongoDBSingleUser
        VpcSecurityGroupIds: !GetAtt TestVPC.DefaultSecurityGroup
        VpcSubnetIds: !Join
          - ','
          - - !Ref TestSubnet01
            - !Ref TestSubnet02
      RotationRules:
        Duration: 2h
        ScheduleExpression: cron(0 8 1 * ? *)
```

## So verwendet Secrets Manager AWS CloudFormation
<a name="how-asm-uses-cfn"></a>

Wenn Sie die Konsole verwenden, um die Rotation zu aktivieren, verwendet Secrets Manager, AWS CloudFormation um Ressourcen für die Rotation zu erstellen. Wenn Sie während dieses Vorgangs eine neue Rotationsfunktion erstellen, CloudFormation erstellt diese auf der [https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html)Grundlage der entsprechenden[Rotationsfunktionsvorlagen](reference_available-rotation-templates.md). CloudFormation Legt dann die fest [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-rotationschedule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-rotationschedule.html), wodurch die Rotationsfunktion und die Rotationsregeln für das Geheimnis festgelegt werden. Sie können den CloudFormation Stapel anzeigen, indem Sie im Banner die Option „**Stapel anzeigen**“ wählen, nachdem Sie die automatische Rotation aktiviert haben.

Informationen zum Einschalten der automatischen Drehung finden Sie unter [AWS Secrets Manager Geheimnisse rotieren](rotating-secrets.md).