AWS CloudFormation Windows 스택 부트스트랩 - AWS CloudFormation

AWS CloudFormation Windows 스택 부트스트랩

이 주제에서는 Windows 스택을 부트스트랩하고 스택 생성 문제를 해결하는 방법을 설명합니다. CloudFormation에서 사용할 고유한 Windows 이미지를 생성하려는 경우 지침은 Amazon EC2 - Windows 인스턴스용 사용 설명서EC2Config 서비스를 사용하여 Windows 인스턴스 구성의 정보를 참조하세요. Windows 인스턴스를 AWS CloudFormation 부트스트랩 도구에서 사용하려면 EC2ConfigService를 사용하여 Windows 인스턴스를 설정해야 합니다.

Windows 스택 부트스트랩 예

설명을 위해 AWS CloudFormation 단일 인스턴스 SharePoint 서버 템플릿을 검사해보도록 하겠습니다.

다음 URL에서 전체 템플릿을 볼 수 있습니다.

이번 예제에서는 다음 작업 방법에 대해 설명합니다.

  • 인스턴스 액세스를 위한 IAM 사용자 및 보안 그룹을 생성합니다.

  • 초기화 파일 cfn-credentials, cfn-hup.confcfn-auto-reloader.conf를 구성합니다.

  • 패키지(예: SharePoint Foundation 2010)를 다운로드하여 서버 인스턴스에 설치

  • WaitCondition을 사용하여 리소스가 준비되었는지 확인합니다.

  • Amazon 탄력적 IP(EIP)를 사용하여 인스턴스에 대한 IP 검색

AWS CloudFormation 헬퍼 스크립트 cfn-init는 Windows Single Server Sharepoint Foundation 템플릿에 있는 AWS::CloudFormation::Init 리소스의 정보를 기반으로 각 작업을 수행하는 데 사용됩니다.

AWS::CloudFormation::Init 섹션은 이름이 'SharePointFoundation'이고 표준 선언으로 시작합니다.

"SharePointFoundation": { "Type" : "AWS::EC2::Instance", "Metadata" : { "AWS::CloudFormation::Init" : { "config" : {

이후에 AWS::CloudFormation::Initfiles(파일) 섹션이 선언됩니다.

"files" : { "c:\\cfn\\cfn-hup.conf" : { "content" : { "Fn::Join" : ["", [ "[main]\n", "stack=", { "Ref" : "AWS::StackName" }, "\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.SharePointFoundation.Metadata.AWS::CloudFormation::Init\n", "action=cfn-init.exe -v -s ", { "Ref" : "AWS::StackName" }, " -r SharePointFoundation", " --region ", { "Ref" : "AWS::Region" }, "\n" ]]} }, "C:\\SharePoint\\SharePointFoundation2010.exe" : { "source" : "http://d3adzpja92utk0.cloudfront.net/SharePointFoundation.exe" } },

여기서 세 파일이 생성되어 서버 인스턴스의 C:\cfn 디렉터리에 배치됩니다. 다음 3개의 파일입니다.

  • cfn-hup.conf - cfn-hup의 구성 파일입니다.

  • cfn-auto-reloader.conf, AWS::CloudFormation::Init의 메타데이터가 변경될 때 cfn-hup가 업데이트를 시작(cfn-init 호출)하는 데 사용되는 후크에 대한 구성 파일입니다.

SharePointFoundation.exe - 서버에 다운로드되는 파일이며, 서버 인스턴스에서 SharePoint를 설치하는 데 사용됩니다.

중요

Windows의 경로는 백슬래시('\') 문자를 사용하므로 AWS CloudFormation 템플릿에서 Windows 경로를 참조할 경우 항상 다른 백슬래시를 추가하여 모든 백슬래시를 적절히 이스케이프해야 합니다.

다음은 cmd.exe 명령인 commands 섹션입니다.

"commands" : { "1-extract" : { "command" : "C:\\SharePoint\\SharePointFoundation2010.exe /extract:C:\\SharePoint\\SPF2010 /quiet /log:C:\\SharePoint\\SharePointFoundation2010-extract.log" }, "2-prereq" : { "command" : "C:\\SharePoint\\SPF2010\\PrerequisiteInstaller.exe /unattended" }, "3-install" : { "command" : "C:\\SharePoint\\SPF2010\\setup.exe /config C:\\SharePoint\\SPF2010\\Files\\SetupSilent\\config.xml" }

인스턴스의 명령은 이름별로 사전순으로 처리되므로 각 명령에 원하는 실행 순서를 나타내는 숫자를 추가했습니다. 따라서 설치 패키지가 먼저 추출된 다음에 모든 사전 요구 사항이 설치되고, 마지막으로 SharePoint 설치가 시작되는지 확인할 수 있습니다.

다음은 Properties 섹션입니다.

"Properties": { "InstanceType" : { "Ref" : "InstanceType" }, "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, "SecurityGroups" : [ {"Ref" : "SharePointFoundationSecurityGroup"} ], "KeyName" : { "Ref" : "KeyPairName" }, "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ "<script>\n", "cfn-init.exe -v -s ", { "Ref" : "AWS::StackName" }, " -r SharePointFoundation", " --region ", { "Ref" : "AWS::Region" }, "\n", "cfn-signal.exe -e %ERRORLEVEL% ", { "Fn::Base64" : { "Ref" : "SharePointFoundationWaitHandle" }}, "\n", "</script>" ]]}} }

이 섹션에서 UserData 속성에는 cfn-init에 의해 실행될 cmd.exe 스크립트가 <script> 태그에 둘러싸여 있습니다. 여기서는 스크립트를 <powershell> 태그로 둘러싸는 대신 Windows Powershell 스크립트를 사용할 수 있습니다. Windows 스택의 경우 대기 조건 핸들 URL을 다시 base64 인코딩해야 합니다.

SharePointFoundationWaitHandle은 여기서 참조되며 cfn-signal을 사용하여 실행됩니다. WaitConditionHandle 및 연결된 WaitCondition이 템플릿에서 다음에 선언됩니다.

"SharePointFoundationWaitHandle" : { "Type" : "AWS::CloudFormation::WaitConditionHandle" }, "SharePointFoundationWaitCondition" : { "Type" : "AWS::CloudFormation::WaitCondition", "DependsOn" : "SharePointFoundation", "Properties" : { "Handle" : {"Ref" : "SharePointFoundationWaitHandle"}, "Timeout" : "3600" } }

모든 단계를 실행하고 SharePoint를 설치하는 데 시간이 다소 걸릴 수 있지만 1시간을 초과하지 않으므로 WaitCondition은 1시간(3600초)을 대기한 이후에 시간 초과됩니다.

아무 문제가 없다면 SharePoint 인스턴스에 액세스하는 데 탄력적 IP가 사용됩니다.

"Outputs" : { "SharePointFoundationURL" : { "Value" : { "Fn::Join" : ["", ["http://", { "Ref" : "SharePointFoundationEIP" } ]] }, "Description" : "SharePoint Team Site URL. Please retrieve Administrator password of the instance and use it to access the URL" }

스택 생성이 완료되면 EIP가 제공한 IP 주소가 AWS CloudFormation 콘솔의 출력 탭에 표시됩니다. 하지만 인스턴스에 액세스하려면 인스턴스에 대해 생성된 임시 관리자 암호를 검색해야 합니다. 자세한 내용을 알아보려면 Amazon EC2 - Windows 인스턴스용 사용 설명서RDP를 사용하여 Windows 인스턴스에 연결을 참조하세요.

Windows 서비스를 관리하는 방법

windows 대신 sysvinit 키를 사용한다는 점을 제외하면 Linux 서비스와 동일한 방법으로 Windows 서비스를 관리합니다. 다음 예에서는 cfn-hup 서비스를 시작하고 [Automatic]으로 설정한 다음 cfn-init가 c:\cfn\cfn-hup.conf 또는 c:\cfn\hooks.d\cfn-auto-reloader.conf 구성 파일을 수정하면 서비스를 다시 시작합니다.

"services" : { "windows" : { "cfn-hup" : { "enabled" : "true", "ensureRunning" : "true", "files" : ["c:\\cfn\\cfn-hup.conf", "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf"] } } }

이름(표시 이름 아님)으로 서비스를 참조하여 다른 Windows 서비스를 관리할 수 있습니다.

스택 생성 문제를 해결하는 방법

생성 중에 스택이 실패할 경우 기본 동작은 실패 시 롤백입니다. 일반적으로 기본 동작은 불필요한 과금을 피할 수 있다는 점은 좋지만 스택 생성이 실패한 원인을 디버깅하기 어렵습니다.

이 동작을 해제하려면 AWS CloudFormation 콘솔에서 스택을 생성할 때 Show Advanced Options(고급 옵션 표시)를 선택하고 Rollback on failure(실패 시 롤백) 옆에 있는 No(아니요) 선택기를 선택합니다. 그러면 인스턴스에 로그인한 후 로그 파일을 보고 시작 스크립트를 실행할 때 발생한 문제를 정확히 파악할 수 있습니다.

검토할 중요 로그는 다음과 같습니다.

  • C:\Program Files\Amazon\Ec2ConfigService\Logs\Ec2ConfigLog.txt의 EC2 구성 로그

  • C:\cfn\log\cfn-init.logcfn-init 로그

자세한 로그는 다음 EC2 안내서를 참조하세요.