我正在尝试将codedeploy-agent.msi
部署到ec2实例(赢得2012年)。它在没有NAT gateway
的专用子网后面,但是通过S3 endpoint
,我测试了这个powershell.exe -Command Read-S3Object -BucketName aws-codedeploy-us-west-2 -Key latest/codedeploy-agent.msi -File codedeploy-agent.msi
是否正常工作。代理是通过Powershell从ec2实例下载的。
但是,使用以下cloudfromation脚本,无需安装代理即可创建实例。没有c:\ cfn文件夹,并且cfn-init.log文件丢失。可能是什么问题???
"WorkerInstance": {
"Type": "AWS::EC2::Instance",
"Metadata": {
"AWS::CloudFormation::Init": {
"config": {
"commands": {
"00-download-host-agent": {
"command": {
"Fn::Join": [
"",
[
"powershell.exe -Command \"Read-S3Object ",
"-BucketName aws-codedeploy-us-west-2 ",
"-Key latest/codedeploy-agent.msi ",
"-File codedeploy-agent.msi\""
]
]
},
"cwd": "C:/cfn",
"waitAfterCompletion" : 0
},
"01-install-host-agent": {
"command": "C:\\cfn\\codedeploy-agent.msi /quiet /l C:\\cfn\\host-agent-install-log.txt",
"ignoreErrors": "true",
"waitAfterCompletion" : 0
},
"02-signal-ready": {
"command": {
"Fn::Join": [
"",
[
"\"C:\\Program Files\\Amazon\\cfn-bootstrap\\cfn-signal\"",
" -e 0 \"",
"\""
]
]
}
}
},
"services": {
"windows": {
"codedeploy-agent": {
"enabled": "true",
"ensureRunning": "true",
"commands": [
"01-install-host-agent"
]
}
}
}
}
}
},
"Properties": {
"DisableApiTermination": "false",
"InstanceInitiatedShutdownBehavior": "stop",
"IamInstanceProfile": {
"Ref": "IAMRole"
},
"ImageId": "ami-c55089bd",
"InstanceType": "t2.medium",
"KeyName": "mykey",
"Monitoring": "true",
"Tags": [{
"Key": "CodeDeployGroup",
"Value": {
"Fn::Join": ["-", ["app", {
"Ref": "EnvType"
}, {
"Ref": "EnvVersion"
}, "CodeDeployGroup"
]]
}
}, {
"Key": "Name",
"Value": {
"Fn::Join": ["-", ["App", {
"Ref": "EnvType"
}, {
"Ref": "EnvVersion"
}, "Worker"
]]
}
}
],
"NetworkInterfaces": [{
"DeleteOnTermination": "true",
"Description": "Primary network interface",
"DeviceIndex": 0,
"SubnetId": "subnet-70234568",
"GroupSet": ["sg-8affd7", "sg-fdffsfsd4"]
}
]
}
}
最佳答案
该命令看起来不错。您可以尝试为powershell命令指定执行策略。此CFN模板适用于我:
"WorkerInstance" : {
"Type" : "AWS::EC2::Instance",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"config" : {
"commands" : {
"00-download-host-agent" : {
"command" : {"Fn::Join" : [ "", [
"powershell.exe -executionpolicy remotesigned -Command \"Read-S3Object ",
"-BucketName aws-codedeploy-us-west-2 ",
"-Key latest/codedeploy-agent.msi ",
"-File codedeploy-agent.msi\""
]]},
"cwd" : "C:/cfn",
"waitAfterCompletion" : 0
},
"01-install-host-agent" : {
"command" : "C:\\cfn\\codedeploy-agent.msi /quiet /l C:\\cfn\\host-agent-install-log.txt",
"ignoreErrors" : "true",
"waitAfterCompletion" : 0
},
"02-signal-ready" : {
"command" : {
"Fn::Join" : [ "", [
"\"C:\\Program Files\\Amazon\\cfn-bootstrap\\cfn-signal\"",
" -e 0 \"",
{ "Ref" : "WaitHandle" },
"\""
]]
},
"waitAfterCompletion" : 0
}
},
"services" : {
"windows" : {
"codedeploy-agent" : {
"enabled" : "true",
"ensureRunning" : "true",
"commands" : [ "01-install-host-agent" ]
}
}
}
}
}
},
关于powershell - 无法使用Cloudformation安装codedeploy-agent.msi,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47654390/