Wie kann ich mithilfe von CloudFormation Laufwerksbuchstaben Amazon EBS-Volumes in Windows zuordnen?

Lesedauer: 5 Minute
0

Ich möchte mithilfe von AWS CloudFormation Laufwerksbuchstaben Amazon Elastic Block Store (Amazon EBS) -Volumes in Windows zuordnen.

Kurzbeschreibung

Sie können ein benutzerdefiniertes Skript verwenden, das während des Startvorgangs ausgeführt wird, um Laufwerksbuchstaben Amazon EBS-Volumes in Windows mit CloudFormation zuzuordnen.

Behebung

  1. Starten Sie eine Windows-Instance mit dem Amazon Machine Image (AMI) für Windows Server 2016 Base oder höher.

  2. (Optional) Erstellen Sie manuell ein D-Laufwerk und legen Sie dann eine Datendatei in das D-Laufwerk ab. Weitere Informationen finden Sie unter Bereitstellen eines Amazon EBS-Volumes für die Verwendung unter Windows.

  3. Verwenden Sie die Option ShutDown mit der Sysprep-Option, um ein AMI aus Ihrer Instance zu erstellen. Weitere Informationen finden Sie unter Konfigurieren einer Windows-Instance mit ec2Launch.

  4. Erstellen Sie einen CloudFormation-Stack, der auf der folgenden Vorlage basiert.

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "AWS CloudFormation template AV Group, Launch Config for EC2",
  "Resources": {
    "DBServer": {
      "Type": "AWS::EC2::Instance",
      "Metadata" : {
        "AWS::CloudFormation::Init" : {
          "config" : {
          "files" : {
            "c:\\cfn\\cfn-hup.conf" : {
            "content" : { "Fn::Join" : ["", [
              "[main]\n",
              "stack=", { "Ref" : "AWS::StackId" }, "\n",
              "region=", { "Ref" : "AWS::Region" }, "\n"
              ]]}
            },
            "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf" : {
            "content": { "Fn::Join" : ["", [
              "[cfn-auto-reloader-hook]\n",
              "triggers=post.update\n",
              "path=Resources.DBServer.Metadata.AWS::CloudFormation::Init\n",
              "action=cfn-init.exe -v -s ", { "Ref" : "AWS::StackId" },
                " -r DBServer",
                " --region ", { "Ref" : "AWS::Region" }, "\n"
            ]]}
            },
            "c:\\cfn\\hooks.d\\drives.diskpart.txt" : {
              "content": { "Fn::Join" : ["", [
                "select disk 2\n",
                "attributes disk clear readonly\n",
                "clean\n",
                "online disk\n",
                "convert gpt\n",
                "create partition primary\n",
                "format quick fs=ntfs label=","\"","ORATEMP","\"","\n",
                "assign letter=X\n",
                "select disk 3\n",
                "attributes disk clear readonly\n",
                "clean\n",
                "online disk\n",
                "convert gpt\n",
                "create partition primary\n",
                "format quick fs=ntfs label=","\"","ORADATA","\"","\n",
                "assign letter=S\n",
                "select disk 1\n",
                "online disk\n"
              ]]}},
              "c:\\cfn\\hooks.d\\renamedrives.ps1" : {
                "content": { "Fn::Join" : ["", [
                  "diskpart /s c:\\cfn\\hooks.d\\drives.diskpart.txt\n"
              ]]}}
          },
          "commands" : {
            "1-rename-drives" : {
              "command" : "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File c:\\cfn\\hooks.d\\renamedrives.ps1",
              "waitAfterCompletion" : "0"
            },
            "2-signal-success" : {
              "command" : { "Fn::Join" : [ "", [
                "cfn-signal.exe -e %ERRORLEVEL% \"",
                { "Fn::Base64" : { "Ref" : "WindowsServerWaitHandle" }},
                "\""]]
              }
            }
          },
          "services" : {
            "windows" : {
            "cfn-hup" : {
              "enabled" : "true",
              "ensureRunning" : "true",
              "files" : ["c:\\cfn\\cfn-hup.conf", "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf"]
            }
            }
          }
          }
        }
      },
      "Properties": {
        "ImageId": "ami-01xxxxxxxxxx",
        "InstanceType": "m4.xlarge",
        "KeyName": "xxxxxxxx",
        "BlockDeviceMappings": [
          {"DeviceName": "xvdg","Ebs":{"VolumeSize":"20"}},
          {"DeviceName": "xvdm","Ebs":{"VolumeSize":"20"}}
        ],
        "Tags": [ {
          "Key": "Name",
          "Value": {"Fn::Join": ["-", ["DB",{"Ref": "AWS::StackName"}]]}
        }],
        "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
          "<powershell>\n",
          "cfn-init.exe -v -s ", { "Ref" : "AWS::StackId" },
          " -r DBServer",
          " --region ", { "Ref" : "AWS::Region" }, "\n",
          "</powershell>"
        ]]}}
      }
    },
    "WindowsServerWaitHandle" : {
      "Type" : "AWS::CloudFormation::WaitConditionHandle"
    },
    "WindowsServerWaitCondition" : {
      "Type" : "AWS::CloudFormation::WaitCondition",
      "DependsOn" : "DBServer",
      "Properties" : {
        "Handle" : {"Ref" : "WindowsServerWaitHandle"},
        "Timeout" : "1800"
      }
    }
  }
}

**Hinweis:**Die vorherige Vorlage enthält ein Skript, das Diskette 2 mit dem Laufwerksbuchstaben X und Diskette 3 mit dem Laufwerksbuchstaben S erstellt.

Das folgende Skript ist Teil der in Schritt 4 gezeigten Vorlage und wird hier zur Betonung genannt. Das Skript konfiguriert das Volume mit der Master Boot Record (MBR) -Partitionsstruktur, formatiert das Volume als NTFS-Volume und weist dann einen Laufwerkbuchstaben zu.

"select disk 2\n",
"attributes disk clear readonly\n",
"clean\n",
"online disk\n",
"convert gpt\n",
"create partition primary\n",
"format quick fs=ntfs label=","\"","ORATEMP","\"","\n",
"assign letter=X\n",
"select disk 3\n",
"attributes disk clear readonly\n",
"clean\n",
"online disk\n",
"convert gpt\n",
"create partition primary\n",
"format quick fs=ntfs label=","\"","ORADATA","\"","\n",
"assign letter=S\n",
"select disk 1\n",
"online disk\n"
  1. Verschieben Sie das Skript in den Dateibereich von AWS::CloudFormation::Init und führen Sie das Skript dann mithilfe des Befehlsabschnitts aus.

**Hinweis:**Disk0 ist immer das Root-Volume.

**Tipp:**Windows Explorer zeigt die Laufwerksreihenfolge alphabetisch an. Um die dem Festplattenbuchstaben zugewiesene Festplattennummer aus Ihrer CloudFormation-Vorlage zu ermitteln, führen Sie den Befehl diskmgmt im Dienstprogramm zur Datenträgerverwaltung aus.

  1. Stellen Sie Ihre Instance bereit und stellen Sie dann mithilfe des Remote Desktop Protocol (RDP) eine Verbindung zu Ihrer Instance her.

In diesem Beispiel hat Ihre Instance jetzt vier Laufwerke. Ihr D-Laufwerk enthält die Datendatei, die Sie in Schritt 1 gespeichert haben.

Drive D          =====> Drive with the data file
Drive S          =====> This is the Disk 3
Drive X          =====> This is the Disk 2

AWS OFFICIAL
AWS OFFICIALAktualisiert vor 3 Jahren