[英]cfn-init stops working after adding cfn-signal
I am trying to execute few powershell commands in Amazon EC2 Windows instance using cfn-init.我正在尝试使用 cfn-init 在 Amazon EC2 Windows 实例中执行一些 powershell 命令。 If I add cfn-signal and CreationPolicy, cfn-init is not getting executed.
如果我添加 cfn-signal 和 CreationPolicy,则不会执行 cfn-init。 Without adding cfn-signal and Creation Policy, everything is getting executed and working fine.
如果不添加 cfn-signal 和 Creation Policy,一切都将得到执行并且运行良好。 Here is part of my script:
这是我的脚本的一部分:
EC2Instance1:
Type: AWS::EC2::Instance
Metadata:
AWS::CloudFormation::Init:
config:
files:
'c:\cfn\cfn-hup.conf':
content: !Join
- ''
- - |
[main]
- stack=
- !Ref 'AWS::StackId'
- |+
- region=
- !Ref 'AWS::Region'
- |+
'c:\cfn\hooks.d\cfn-auto-reloader.conf':
content: !Join
- ''
- - |
[cfn-auto-reloader-hook]
- |
triggers=post.update
- >
path=Resources.EC2Instance1.Metadata.AWS::CloudFormation::Init
- 'action=cfn-init.exe -v -s '
- !Ref 'AWS::StackId'
- ' -r EC2Instance1'
- ' --region '
- !Ref 'AWS::Region'
- |+
commands:
1-createFile:
command: !Sub |
powershell.exe New-Item ${PathOfFile} -ItemType file
2-addContenttoFile:
command: !Sub |
powershell.exe Set-Content -path ${PathOfFile} -Value 'Ip of webserver1 here'
3-replaceText:
command: !Sub |
powershell.exe (Get-Content ${PathOfFile}).replace('webserver1', (Invoke-WebRequest ifconfig.me/ip).Content.Trim()) ^| Set-Content ${PathOfFile}
Properties:
ImageId: !Ref AMI1
InstanceType: !Ref EC2InstanceType
KeyName: !Ref KeyName
UserData: !Base64
'Fn::Join':
- ''
- - |
<script>
- 'cfn-init.exe -v -s '
- !Ref 'AWS::StackId'
- ' -r EC2Instance1'
- ' --region '
- !Ref 'AWS::Region'
- |+
- |
- 'cfn-signal.exe -e %ERRORLEVEL% -s --stack '
- !Ref 'AWS::StackName'
- ' --resource EC2Instance1'
- ' --region '
- !Ref 'AWS::Region'
- |+
- </script>
CreationPolicy:
ResourceSignal:
Count: "1"
Timeout: PT10M
Where am I going wrong?我哪里错了?
I had a similar issue but the cause was due to reboots during cfn-init.我有一个类似的问题,但原因是在 cfn-init 期间重新启动。 I found this helpful: https://aws.amazon.com/premiumsupport/knowledge-center/create-complete-bootstrapping/ .
我发现这很有帮助: https : //aws.amazon.com/premiumsupport/knowledge-center/create-complete-bootstrapping/ 。 You might try putting the cfn-signal in a command within your configset instead of in userData.
您可以尝试将 cfn-signal 放在 configset 中的命令中,而不是放在 userData 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.