0

의 EC2 :: 인스턴스 내가 몇 가지 LaunchConfig이 그룹 AS사용 AWS는 :: AWS :: CloudFormation :: 초기화

"LaunchConfig": { 
    "Type" : "AWS::AutoScaling::LaunchConfiguration", 

    "Metadata" : { 
     "AWS::CloudFormation::Init" : { 
      "configSets" : { 
      "InstallAndRun" : [ "Install" ] 
      }, 

      "Install" : { 

      "files" : { 

       "/var/www/html/index.html" : { 
       "content" : { "Fn::Join" : ["", [ 
       "<html\n", 
       "<h1>Apache HTTP Server</h1>\n", 
       "</html>\n" 
       ]]}, 
       "mode" : "000644", 
       "owner" : "apache", 
       "group" : "apache" 
       }, 
      ...... 

그것은 같은 가능성 또는 어떤 좋은 방법을 추가하는 일부 데이터를 index.html을 위해, 예를 들어 AWS :: EC2 :: instance의 instance-id는 "files"섹션을 사용합니까?

{ "Ref": "AWS :: StackId"} 또는 { "Ref": "AWS :: Region"}을 추가하면 정상적으로 작동하지만 가짜 매개 변수에서 작동합니다.

   "/var/www/html/index.html" : { 
       "content" : { "Fn::Join" : ["", [ 
       "<html\n", 
       "<h1>Apache HTTP Server</h1>\n", 
       { "Ref" : "AWS::StackId" }, 
       "</html>\n" 
       ]]}, 

고마워요!

+0

파일을 외부에 추가하는 것이 좋습니다. S3에 설치하고 EC2를 실행하는 동안 가져옵니다. 템플릿이 지저분 해 보이지 않아도 필요에 따라 많은 콘텐츠를 추가 할 수있는 유연성이 있기 때문입니다. 그런 다음 EC2 실행 스크립트에서 sed 명령을 사용하여 추가 데이터를 주입하십시오. – ivanji

답변

1

는 내가 직접이 작업을 수행하는 것이 가능하다 생각하지 않습니다,하지만 당신은 파일을 배치하여이 작업을 수행 할 수 있어야하고 나중에이를 업데이트하는 명령을 실행 :

(면책 조항 : 나는하지 이것을 명시 적으로 테스트했습니다.)

{ 
    "AWS::CloudFormation::Init": { 
     "configSets": { 
      "InstallAndRun": [ 
       "Install", 
       "UpdateIndexHtml" 
      ] 
     }, 
     "Install": { 
      "files": { 
       "/var/www/html/index.html": { 
        "content": { 
         "Fn::Join": [ 
          "", 
          [ 
           "<html\n", 
           "<h1>Apache HTTP Server</h1>\n", 
           "---INSTANCE_ID---\n", 
           "</html>\n" 
          ] 
         ] 
        }, 
        "mode": "000644", 
        "owner": "apache", 
        "group": "apache" 
       } 
      } 
     }, 
     "UpdateIndexHtml": { 
      "commands": { 
       "UpdateIndexHtml": { 
        "command": "sed -i \"s|---INSTANCE_ID---|$(curl -s http://169.254.169.254/latest/meta-data/instance-id)|\" /var/www/html/index.html" 
       } 
      } 
     } 
    } 
} 
관련 문제