EC2 인스턴스를 생성하고 UserData를 사용하여 무언가를 설치하는 cloudformation 스택이 있습니다. Cloudformation 은 RedHat를 기반으로 EC2 인스턴스 생성시 즉시 CREATE_COMPLETE 를 보고합니다 . 그러나이 시점에서 사용자 데이터가 완료되는 데 약 40 분이 걸리기 때문에 인스턴스를 실제로 사용할 수 없습니다. 문서를 읽고 cfn-signal을 시도했지만 성공적으로 실행할 수 없었습니다.
누군가 정확히 어떻게해야하는지 말해 줄 수 있습니까?
EC2Instance:
Type: AWS::EC2::Instance
Properties:
CreditSpecification:
CPUCredits: standard
IamInstanceProfile:
Fn::ImportValue:
!Sub ${InstanceProfileStackName}-instanceProfile
ImageId: !Ref ImageId
InstanceInitiatedShutdownBehavior: stop
InstanceType: !Ref InstanceType
SubnetId: !Ref SubnetId
SecurityGroupIds:
- !Ref DefaultSecurityGroup
- !Ref WebSecurityGroup
UserData:
Fn::Base64: !Sub |
#!/bin/bash
set -e
yum update -y
위는 내 Cloudformation 템플릿에서 잘린 부분입니다.
최신 정보
다음 줄이있는 스크립트가 있습니다.
source scl_source enable rh-python36
내 인스턴스의 기본값은 python2.7이지만 python3.6으로 pip 패키지를 설치해야했습니다. 그것이 cfn-signal이 실패했는지 확실하지 않습니다.
스크립트가 마지막 단계까지 진행 중이며 실패한 것 같습니다. EC2 IP에서 레코드 세트를 생성하고 있지만 Cloudformation은 여전히 EC2 인스턴스가 완료되지 않은 것으로 생각하고 시간 초과까지 기다리고 있습니다.
또한 내 로그 파일 이름은 /var/log/cloud-init.log입니다. 해당 디렉토리에는 cloud-init-output.log가 없습니다.
오류를 재현하고 여기에서 수정할 수 있습니다. 다음은 수정 된 템플릿입니다. 나는 Marcin의 답변에 추가했습니다.
EC2Instance:
Type: AWS::EC2::Instance
CreationPolicy:
ResourceSignal:
Timeout: PT5M # Specify the time here
Properties:
CreditSpecification:
CPUCredits: standard
IamInstanceProfile:
Fn::ImportValue:
!Sub ${InstanceProfileStackName}-instanceProfile
ImageId: !Ref ImageId
InstanceInitiatedShutdownBehavior: stop
InstanceType: !Ref InstanceType
SubnetId: !Ref SubnetId
SecurityGroupIds:
- !Ref DefaultSecurityGroup
- !Ref WebSecurityGroup
UserData:
Fn::Base64: !Sub |
#!/bin/bash -ex
yum update -y
source scl_source enable rh-python36
<Your additional commands>
cfn-signal -e $? --stack ${AWS::StackName} --resource EC2Instance --region ${AWS::Region}
시도하기 전에 들여 쓰기를 카운터 검사하는 것이 좋습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다