0

Könnte mir jemand etwas falsch Punkt helfen mache ich hier. Ich verstehe nicht, wie der Metadatenteil die Authentifizierungsressource verwendet. Im Teil AWS :: CloudFormation :: Authentication habe ich die Rolle erwähnt, die der an die Instanz angefügten Rolle entspricht. Ich kann die Datei jedoch nicht erstellen. " some.txt“Cloudformation-Vorlage Abschnitt erstellen „Dateien“ unter MetaDaten andernfalls

{ 

"Parameters": { 

    "SecurityGroupId": { 
     "Description": "Security group for instance", 
     "Type": "AWS::EC2::SecurityGroup::Id" 
    } 

}, 


"Resources": { 
    "MyInstance": { 
     "Type": "AWS::EC2::Instance", 
     "Metadata": { 
      "AWS::CloudFormation::Init": { 
       "configsets": { 
        "InstallIt": ["config1"] 
       }, 

       "config1": { 
        "files": { 
         "/home/ec2-user/some.txt": { 
          "content": "This is my name ", 
          "encoding": "base64", 
          "mode": "000644", 
          "owner": "root", 
          "group": "root" 
         } 
        } 
       } 
      }, 

      "AWS::CloudFormation::Authentication": { 
       "HelpMe": { 
        "type": "S3", 
        "buckets": "poc-bucket", 
        "roleName": "EC2andS3" 
       } 

      } 
     }, 
     "Properties": { 
      "KeyName": "GoldenImage-NV-Anant", 
      "DisableApiTermination": "false", 
      "ImageId": "ami-0b33d91d", 
      "InstanceType": "t2.micro", 
      "Monitoring": "false", 
      "SubnetId": "subnet-73487a59", 
      "SecurityGroupIds": [{ 
       "Ref": "SecurityGroupId" 
      }], 
      "IamInstanceProfile": { 
       "Ref": "MyInstanceProfile" 
      }, 
      "Tags": [{ 
       "Key": "Name", 
       "Value": "GeicoUserDataPocInstance" 
      }], 
      "UserData": { 
       "Fn::Base64": { 
        "Fn::Join": [ 
         "", [ 
          "#!/bin/bash -ex \n", 
          "echo \"hello dudes\" > /home/ec2-user/hello.txt \n", 
          "yum update -y aws-cfn-bootstrap\n", 
          "/opt/aws/bin/cfn-init -v", 
          " --stack ", { 
           "Ref": "AWS::StackId" 
          }, 
          " --resource MyInstance ", 
          " --configsets InstallIt ", 
          " --region ", { 
           "Ref": "AWS::Region" 
          }, "\n", 
          "echo \"bye dudes\" > /home/ec2-user/bye.txt", "\n", 


          "/opt/aws/bin/cfn-signal -e $? ", 
          " --stack ", { 
           "Ref": "AWS::StackId" 
          }, 
          " --resource MyInstance ", 
          " --region ", { 
           "Ref": "AWS::Region" 
          }, "\n" 
         ] 
        ] 
       } 
      } 
     }, 

     "CreationPolicy": { 
      "ResourceSignal": { 
       "Timeout": "PT90M", 
       "Count": "1" 
      } 
     } 
    }, 

    "MyInstanceProfile": { 
     "Description": "Instance profile for the instance", 
     "Type": "AWS::IAM::InstanceProfile", 
     "Properties": { 
      "Path": "/", 
      "Roles": ["EC2andS3"] 
     } 
    } 
} 
} 

Antwort

2
  • configsets sollte configSets mit Kapital S:

    "configSets": { 
        "InstallIt": ["config1"] 
    }, 
    
  • buckets Eigenschaft muss eine Liste von Strings sein (dies ist nicht notwendig sein könnte, th e-Dokumentation ist ein wenig unklar):

    "buckets": ["poc-bucket"] 
    
  • AWS::CloudFormation::Authentication Ressource nicht erforderlich sein sollte, es sei denn, die Quelle der Datei ein S3 Eimer ist. Selbst dann sollte es immer noch nicht notwendig sein, wenn Sie ein angehängtes Instanzprofil verwenden, da es standardmäßig das Instanzprofil für die Authentifizierung verwendet.

Verwandte Themen