

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.

# Erstellen Sie Startvorlagen mit CloudFormation
<a name="quickref-ec2-launch-templates"></a>

Dieser Abschnitt enthält ein Beispiel für die Erstellung einer Amazon EC2 EC2-Startvorlage mithilfe von CloudFormation. Mit Startvorlagen können Sie Vorlagen für die Konfiguration und Bereitstellung von Amazon EC2-Instances innerhalb von AWS erstellen. Mit Startvorlagen können Sie Startparameter speichern, so dass Sie diese nicht bei jedem Start einer Instance neu angeben müssen. Weitere Beispiele finden Sie im Abschnitt [Beispiele](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-launchtemplate.html#aws-resource-ec2-launchtemplate--examples) in der `AWS::EC2::LaunchTemplate` Ressource.

Weitere Informationen über Startvorlagen finden Sie unter [Speichern von Instance-Startparametern in Amazon EC2-Startvorlagen](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html) im *Amazon EC2 User Guide*. 

Informationen zur Erstellung von Startvorlagen für die Verwendung mit Auto Scaling-Gruppen finden Sie unter [Auto Scaling-Startvorlagen](https://docs.aws.amazon.com/autoscaling/ec2/userguide/launch-templates.html) im *Amazon EC2 Auto Scaling User Guide*.

**Topics**
+ [Erstellen Sie eine Startvorlage, in der Sicherheitsgruppen, Tags, Benutzerdaten und eine IAM-Rolle angegeben sind.](#scenario-as-launch-template)

## Erstellen Sie eine Startvorlage, in der Sicherheitsgruppen, Tags, Benutzerdaten und eine IAM-Rolle angegeben sind.
<a name="scenario-as-launch-template"></a>

Dieser Ausschnitt zeigt eine [AWS::EC2::LaunchTemplate](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-launchtemplate.html)Ressource, die die Konfigurationsinformationen zum Starten einer Instance enthält. Sie definieren Werte für die `ImageId`-, `InstanceType`-, `SecurityGroups`-, `UserData`- und `TagSpecifications`-Eigenschaften. Die `SecurityGroups`-Eigenschaft gibt eine vorhandene EC2-Sicherheitsgruppe und eine neue Sicherheitsgruppe an. Die `Ref` Funktion ruft die ID der [AWS::EC2::SecurityGroup](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-securitygroup.html)Ressource ab`myNewEC2SecurityGroup`, die an anderer Stelle in der Stack-Vorlage deklariert wurde. 

Die Einführungsvorlage enthält einen Abschnitt für benutzerdefinierte Benutzerdaten. In diesem Abschnitt können Sie Konfigurations-Aufgaben und Skripts übergeben, die beim Launch einer Instance ausgeführt werden. In diesem Beispiel installieren die Benutzerdaten den AWS Systems Manager Agenten und starten den Agenten.

Die Startvorlage enthält auch eine IAM-Rolle, die es Anwendungen, die auf Instances laufen, ermöglicht, Aktionen in Ihrem Namen durchzuführen. Dieses Beispiel zeigt eine [AWS::IAM::Role](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-iam-role.html)Ressource für die Startvorlage, die die `IamInstanceProfile` Eigenschaft verwendet, um die IAM-Rolle anzugeben. Die `Ref` Funktion ruft den Namen der [AWS::IAM::InstanceProfile](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-iam-instanceprofile.html)Ressource `myInstanceProfile` ab. Um die Berechtigungen der IAM-Rolle zu konfigurieren, geben Sie einen Wert für die `ManagedPolicyArns`-Eigenschaft an.

### JSON
<a name="quickref-launch-template-example-1.json"></a>

```
 1. {
 2.   "Resources":{
 3.     "myLaunchTemplate":{
 4.       "Type":"AWS::EC2::LaunchTemplate",
 5.       "Properties":{
 6.         "LaunchTemplateName":{ "Fn::Sub": "${AWS::StackName}-launch-template" },
 7.         "LaunchTemplateData":{
 8.           "ImageId":"ami-02354e95b3example",
 9.           "InstanceType":"t3.micro",
10.           "IamInstanceProfile":{
11.             "Name":{
12.               "Ref":"myInstanceProfile"
13.             }
14.           },
15.           "SecurityGroupIds":[
16.             {
17.               "Ref":"myNewEC2SecurityGroup"
18.             },
19.             "sg-083cd3bfb8example"
20.           ],
21.           "UserData":{
22.             "Fn::Base64":{
23.               "Fn::Join": [
24.                 "", [
25.                   "#!/bin/bash\n",
26.                   "cd /tmp\n",
27.                   "yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm\n",
28.                   "systemctl enable amazon-ssm-agent\n",
29.                   "systemctl start amazon-ssm-agent\n"
30.                 ]
31.               ]
32.             }
33.           },
34.           "TagSpecifications":[
35.             {
36.               "ResourceType":"instance",
37.               "Tags":[
38.                 {
39.                   "Key":"environment",
40.                   "Value":"development"
41.                 }
42.               ]
43.             },
44.             {
45.               "ResourceType":"volume",
46.               "Tags":[
47.                 {
48.                   "Key":"environment",
49.                   "Value":"development"
50.                 }
51.               ]
52.             }
53.           ]
54.         }
55.       }
56.     },
57.     "myInstanceRole":{
58.       "Type":"AWS::IAM::Role",
59.       "Properties":{
60.         "RoleName":"InstanceRole",
61.         "AssumeRolePolicyDocument":{
62.           "Version": "2012-10-17",		 	 	 
63.           "Statement":[
64.             {
65.               "Effect":"Allow",
66.               "Principal":{
67.                 "Service":[
68.                   "ec2.amazonaws.com"
69.                 ]
70.               },
71.               "Action":[
72.                 "sts:AssumeRole"
73.               ]
74.             }
75.           ]
76.         },
77.         "ManagedPolicyArns":[
78.           "arn:aws:iam::aws:policy/myCustomerManagedPolicy"
79.         ]
80.       }
81.     },
82.     "myInstanceProfile":{
83.       "Type":"AWS::IAM::InstanceProfile",
84.       "Properties":{
85.         "Path":"/",
86.         "Roles":[
87.           {
88.             "Ref":"myInstanceRole"
89.           }
90.         ]
91.       }
92.     }
93.   }
94. }
```

### YAML
<a name="quickref-launch-template-example-1.yaml"></a>

```
 1. ---
 2. Resources:
 3.   myLaunchTemplate:
 4.     Type: AWS::EC2::LaunchTemplate
 5.     Properties:
 6.       LaunchTemplateName: !Sub ${AWS::StackName}-launch-template
 7.       LaunchTemplateData:
 8.         ImageId: ami-02354e95b3example
 9.         InstanceType: t3.micro
10.         IamInstanceProfile:
11.           Name: !Ref myInstanceProfile
12.         SecurityGroupIds:
13.         - !Ref myNewEC2SecurityGroup
14.         - sg-083cd3bfb8example
15.         UserData:
16.           Fn::Base64: !Sub |
17.             #!/bin/bash
18.             cd /tmp
19.             yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
20.             systemctl enable amazon-ssm-agent
21.             systemctl start amazon-ssm-agent
22.         TagSpecifications:
23.         - ResourceType: instance
24.           Tags:
25.           - Key: environment
26.             Value: development
27.         - ResourceType: volume
28.           Tags:
29.           - Key: environment
30.             Value: development
31.   myInstanceRole:
32.     Type: AWS::IAM::Role
33.     Properties:
34.       RoleName: InstanceRole
35.       AssumeRolePolicyDocument:
36.         Version: '2012-10-17'
37.         Statement:
38.         - Effect: 'Allow'
39.           Principal:
40.             Service:
41.             - 'ec2.amazonaws.com'
42.           Action:
43.           - 'sts:AssumeRole'
44.       ManagedPolicyArns:
45.         - 'arn:aws:iam::aws:policy/myCustomerManagedPolicy'
46.   myInstanceProfile:
47.     Type: AWS::IAM::InstanceProfile
48.     Properties:
49.       Path: '/'
50.       Roles:
51.       - !Ref myInstanceRole
```