

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.

# Konfigurieren Sie Amazon VPC-Ressourcen mit CloudFormation
<a name="quickref-ec2-vpc"></a>

Dieser Abschnitt enthält Beispiele für die Konfiguration von Amazon VPC-Ressourcen mithilfe von CloudFormation. VPCsermöglichen es Ihnen, darin ein virtuelles Netzwerk zu erstellen. Diese Auszüge zeigen AWS, wie Sie Aspekte von konfigurieren können, um Ihre VPCs Netzwerkanforderungen zu erfüllen. 

**Topics**
+ [Aktivieren Sie den Internetzugang IPv6 nur für ausgehenden Datenverkehr in einer VPC](#quickref-ec2-route-egressonlyinternetgateway)
+ [Elastic Network-Schnittstelle (ENI) Vorlagenausschnitte](#cfn-template-snippets-eni)

## Aktivieren Sie den Internetzugang IPv6 nur für ausgehenden Datenverkehr in einer VPC
<a name="quickref-ec2-route-egressonlyinternetgateway"></a>

Ein auf ausgehenden Datenverkehr beschränktes Internet-Gateway erlaubt Instances in einer VPC den Zugriff auf das Internet und verhindert, dass Ressourcen aus dem Internet mit den Instances kommunizieren. Das folgende Snippet ermöglicht den Internetzugang IPv6 nur für ausgehenden Datenverkehr von einer VPC aus. Es erstellt eine VPC mit einem IPv4 Adressbereich, der eine `10.0.0/16` [AWS: :EC2: :VPC-Ressource](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-vpc.html) verwendet. Eine Routentabelle ist dieser VPC-Ressource mithilfe einer [AWS::EC2::RouteTable](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-routetable.html)Ressource zugeordnet. Über die Routing-Tabelle werden Routen für Instances in der VPC verwaltet. An [AWS::EC2::EgressOnlyInternetGateway](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-egressonlyinternetgateway.html)wird verwendet, um ein Internet-Gateway nur für ausgehenden Datenverkehr zu erstellen, um die IPv6 Kommunikation für ausgehenden Datenverkehr von Instances innerhalb der VPC zu ermöglichen und gleichzeitig eingehenden Datenverkehr zu verhindern. Eine [AWS::EC2::Route](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-route.html)Ressource wird angegeben, um eine IPv6 Route in der Routentabelle zu erstellen, die den gesamten ausgehenden IPv6 Verkehr () `::/0` an das Internet-Gateway weiterleitet, das nur für ausgehenden Verkehr bestimmt ist. 

*Weitere Informationen zu Internet-Gateways nur für ausgehenden Datenverkehr finden Sie unter [Aktivieren von ausgehendem IPv6 Datenverkehr mithilfe eines Internet-Gateways nur für ausgehenden Datenverkehr im Amazon VPC-Benutzerhandbuch](https://docs.aws.amazon.com/vpc/latest/userguide/egress-only-internet-gateway.html).*

### JSON
<a name="quickref-ec2-example-16.json"></a>

```
"DefaultIpv6Route": {
    "Type": "AWS::EC2::Route",
    "Properties": {
        "DestinationIpv6CidrBlock": "::/0",
        "EgressOnlyInternetGatewayId": {
            "Ref": "EgressOnlyInternetGateway"
        },
        "RouteTableId": {
            "Ref": "RouteTable"
        }
    }
},
"EgressOnlyInternetGateway": {
    "Type": "AWS::EC2::EgressOnlyInternetGateway",
    "Properties": {
        "VpcId": {
            "Ref": "VPC"
        }
    }
},
"RouteTable": {
    "Type": "AWS::EC2::RouteTable",
    "Properties": {
        "VpcId": {
            "Ref": "VPC"
        }
    }
},
"VPC": {
    "Type": "AWS::EC2::VPC",
    "Properties": {
        "CidrBlock": "10.0.0.0/16"
    }
}
```

### YAML
<a name="quickref-ec2-example-16.yaml"></a>

```
DefaultIpv6Route:
  Type: AWS::EC2::Route
  Properties:
    DestinationIpv6CidrBlock: "::/0"
    EgressOnlyInternetGatewayId:
      Ref: "EgressOnlyInternetGateway"
    RouteTableId:
      Ref: "RouteTable"
EgressOnlyInternetGateway:
  Type: AWS::EC2::EgressOnlyInternetGateway
  Properties:
    VpcId:
      Ref: "VPC"
RouteTable:
  Type: AWS::EC2::RouteTable
  Properties:
    VpcId:
      Ref: "VPC"
VPC:
  Type: AWS::EC2::VPC
  Properties:
    CidrBlock: "10.0.0.0/16"
```

## Elastic Network-Schnittstelle (ENI) Vorlagenausschnitte
<a name="cfn-template-snippets-eni"></a>

### Erstellen Sie eine Amazon EC2 EC2-Instance mit angehängten elastischen Netzwerkschnittstellen () ENIs
<a name="cfn-template-snippets-eni-template"></a>

Das folgende Beispiel-Snippet erstellt eine Amazon EC2-Instance unter Verwendung einer [https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-instance.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-instance.html)-Ressource in der angegebenen Amazon VPC und dem angegebenen Subnetz. Sie verbindet zwei Netzwerkschnittstellen (ENIs) mit der Instance, ordnet Elastic IP-Adressen den Instances über die angehängte ENIs Verbindung zu und konfiguriert die Sicherheitsgruppe für SSH- und HTTP-Zugriff. Benutzerdaten werden der Instance im Rahmen der Startkonfiguration bereitgestellt, wenn die Instance erstellt wird. Die Benutzerdaten enthalten ein im `base64`-Format codiertes Skript, damit sie auf jeden Fall an die Instance übergeben werden. Beim Start der Instance wird das Skript automatisch als Teil des Bootstrapping-Prozesses ausgeführt. Es installiert `ec2-net-utils`, konfiguriert die Netzwerkschnittstellen und startet den HTTP-Service. 

Um das passende Amazon Machine Image (AMI) für die ausgewählte Region zu ermitteln, wird im Ausschnitt eine `Fn::FindInMap`-Funktion verwendet, die Werte in einer `RegionMap`-Zuordnung nachschlägt. Diese Zuordnung muss in der größeren Vorlage definiert werden. Die beiden Netzwerkschnittstellen werden mit [https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-networkinterface.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-networkinterface.html) Ressourcen erstellt. Elastische IP-Adressen werden über [https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-eip.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-eip.html) Ressourcen angegeben, die der `vpc`-Domain zugewiesen sind. Diese elastischen IP-Adressen sind mit den Netzwerkschnittstellen über die Ressourcen [https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-eipassociation.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-eipassociation.html) verbunden. 

Im Abschnitt `Outputs` werden Werte oder Ressourcen definiert, auf die Sie nach Erstellung des Stacks zugreifen möchten. In diesem Codeausschnitt lautet die definierte Ausgabe `InstancePublicIp`, was für die öffentliche IP-Adresse der vom Stack erstellten EC2-Instance steht. [Sie können diese Ausgabe auf der Registerkarte „**Ausgabe**“ in der CloudFormation Konsole oder mit dem Befehl describe-stacks abrufen.](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/describe-stacks.html) 

Weitere Informationen über Elastic-Network-Schnittstellen finden Sie unter [Elastic-Network-Schnittstellen](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html).

#### JSON
<a name="cfn-template-snippets-eni-example-1.json"></a>

```
"Resources": {
    "ControlPortAddress": {
        "Type": "AWS::EC2::EIP",
        "Properties": {
            "Domain": "vpc"
        }
    },
    "AssociateControlPort": {
        "Type": "AWS::EC2::EIPAssociation",
        "Properties": {
            "AllocationId": {
                "Fn::GetAtt": [
                    "ControlPortAddress",
                    "AllocationId"
                ]
            },
            "NetworkInterfaceId": {
                "Ref": "controlXface"
            }
        }
    },
    "WebPortAddress": {
        "Type": "AWS::EC2::EIP",
        "Properties": {
            "Domain": "vpc"
        }
    },
    "AssociateWebPort": {
        "Type": "AWS::EC2::EIPAssociation",
        "Properties": {
            "AllocationId": {
                "Fn::GetAtt": [
                    "WebPortAddress",
                    "AllocationId"
                ]
            },
            "NetworkInterfaceId": {
                "Ref": "webXface"
            }
        }
    },
    "SSHSecurityGroup": {
        "Type": "AWS::EC2::SecurityGroup",
        "Properties": {
            "VpcId": {
                "Ref": "VpcId"
            },
            "GroupDescription": "Enable SSH access via port 22",
            "SecurityGroupIngress": [
                {
                    "CidrIp": "0.0.0.0/0",
                    "FromPort": 22,
                    "IpProtocol": "tcp",
                    "ToPort": 22
                }
            ]
        }
    },
    "WebSecurityGroup": {
        "Type": "AWS::EC2::SecurityGroup",
        "Properties": {
            "VpcId": {
                "Ref": "VpcId"
            },
            "GroupDescription": "Enable HTTP access via user-defined port",
            "SecurityGroupIngress": [
                {
                    "CidrIp": "0.0.0.0/0",
                    "FromPort": 80,
                    "IpProtocol": "tcp",
                    "ToPort": 80
                }
            ]
        }
    },
    "controlXface": {
        "Type": "AWS::EC2::NetworkInterface",
        "Properties": {
            "SubnetId": {
                "Ref": "SubnetId"
            },
            "Description": "Interface for controlling traffic such as SSH",
            "GroupSet": [
                {
                    "Fn::GetAtt": [
                        "SSHSecurityGroup",
                        "GroupId"
                    ]
                }
            ],
            "SourceDestCheck": true,
            "Tags": [
                {
                    "Key": "Network",
                    "Value": "Control"
                }
            ]
        }
    },
    "webXface": {
        "Type": "AWS::EC2::NetworkInterface",
        "Properties": {
            "SubnetId": {
                "Ref": "SubnetId"
            },
            "Description": "Interface for web traffic",
            "GroupSet": [
                {
                    "Fn::GetAtt": [
                        "WebSecurityGroup",
                        "GroupId"
                    ]
                }
            ],
            "SourceDestCheck": true,
            "Tags": [
                {
                    "Key": "Network",
                    "Value": "Web"
                }
            ]
        }
    },
    "Ec2Instance": {
        "Type": "AWS::EC2::Instance",
        "Properties": {
            "ImageId": {
                "Fn::FindInMap": [
                    "RegionMap",
                    {
                        "Ref": "AWS::Region"
                    },
                    "AMI"
                ]
            },
            "KeyName": {
                "Ref": "KeyName"
            },
            "NetworkInterfaces": [
                {
                    "NetworkInterfaceId": {
                        "Ref": "controlXface"
                    },
                    "DeviceIndex": "0"
                },
                {
                    "NetworkInterfaceId": {
                        "Ref": "webXface"
                    },
                    "DeviceIndex": "1"
                }
            ],
            "Tags": [
                {
                    "Key": "Role",
                    "Value": "Test Instance"
                }
            ],
            "UserData": {
                "Fn::Base64": {
                    "Fn::Sub": "#!/bin/bash -xe\nyum install ec2-net-utils -y\nec2ifup eth1\nservice httpd start\n"
                }
            }
        }
    }
},
"Outputs": {
    "InstancePublicIp": {
        "Description": "Public IP Address of the EC2 Instance",
        "Value": {
            "Fn::GetAtt": [
                "Ec2Instance",
                "PublicIp"
            ]
        }
    }
}
```

#### YAML
<a name="cfn-template-snippets-eni-example.yaml"></a>

```
Resources:
  ControlPortAddress:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
  AssociateControlPort:
    Type: AWS::EC2::EIPAssociation
    Properties:
      AllocationId:
        Fn::GetAtt:
          - ControlPortAddress
          - AllocationId
      NetworkInterfaceId:
        Ref: controlXface
  WebPortAddress:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
  AssociateWebPort:
    Type: AWS::EC2::EIPAssociation
    Properties:
      AllocationId:
        Fn::GetAtt:
          - WebPortAddress
          - AllocationId
      NetworkInterfaceId:
        Ref: webXface
  SSHSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId:
        Ref: VpcId
      GroupDescription: Enable SSH access via port 22
      SecurityGroupIngress:
        - CidrIp: 0.0.0.0/0
          FromPort: 22
          IpProtocol: tcp
          ToPort: 22
  WebSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId:
        Ref: VpcId
      GroupDescription: Enable HTTP access via user-defined port
      SecurityGroupIngress:
        - CidrIp: 0.0.0.0/0
          FromPort: 80
          IpProtocol: tcp
          ToPort: 80
  controlXface:
    Type: AWS::EC2::NetworkInterface
    Properties:
      SubnetId:
        Ref: SubnetId
      Description: Interface for controlling traffic such as SSH
      GroupSet:
        - Fn::GetAtt:
            - SSHSecurityGroup
            - GroupId
      SourceDestCheck: true
      Tags:
        - Key: Network
          Value: Control
  webXface:
    Type: AWS::EC2::NetworkInterface
    Properties:
      SubnetId:
        Ref: SubnetId
      Description: Interface for web traffic
      GroupSet:
        - Fn::GetAtt:
            - WebSecurityGroup
            - GroupId
      SourceDestCheck: true
      Tags:
        - Key: Network
          Value: Web
  Ec2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId:
        Fn::FindInMap:
          - RegionMap
          - Ref: AWS::Region
          - AMI
      KeyName:
        Ref: KeyName
      NetworkInterfaces:
        - NetworkInterfaceId:
            Ref: controlXface
          DeviceIndex: "0"
        - NetworkInterfaceId:
            Ref: webXface
          DeviceIndex: "1"
      Tags:
        - Key: Role
          Value: Test Instance
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash -xe
          yum install ec2-net-utils -y
          ec2ifup eth1
          service httpd start
Outputs:
  InstancePublicIp:
    Description: Public IP Address of the EC2 Instance
    Value:
      Fn::GetAtt:
        - Ec2Instance
        - PublicIp
```