无法使用 Cloudformation 安装 codedeploy-agent.msi
Not able to install codedeploy-agent.msi using Cloudformation
我正在尝试将 codedeploy-agent.msi
部署到 ec2 实例 (win 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" ]
}
}
}
}
}
},
我不确定,为什么它不起作用。我终于通过将它作为用户数据脚本使其工作。
"UserData": {
"Fn::Base64": {
"Fn::Join": ["", ["<script>\n", "mkdir c:\cfn\n", "mkdir c:\cfn\log\n",
"powershell.exe Read-S3Object -BucketName aws-codedeploy-us-west-2/latest -Key codedeploy-agent.msi -File c:\cfn\codedeploy-agent.msi\n",
"c:\cfn\codedeploy-agent.msi /quiet /l c:\cfn\host-agent-install-log.txt\n",
"c:\\"Program Files\"\Amazon\cfn-bootstrap\cfn-init.exe -s ", {
"Ref": "AWS::StackName"
}, " --region ", {
"Ref": "AWS::Region"
}, " > c:\cfn\log\cfn-call-log 2>&1", "</script>"]]
}
},
这将安装代理并启用和启动服务。
我正在尝试将 codedeploy-agent.msi
部署到 ec2 实例 (win 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" ]
}
}
}
}
}
},
我不确定,为什么它不起作用。我终于通过将它作为用户数据脚本使其工作。
"UserData": {
"Fn::Base64": {
"Fn::Join": ["", ["<script>\n", "mkdir c:\cfn\n", "mkdir c:\cfn\log\n",
"powershell.exe Read-S3Object -BucketName aws-codedeploy-us-west-2/latest -Key codedeploy-agent.msi -File c:\cfn\codedeploy-agent.msi\n",
"c:\cfn\codedeploy-agent.msi /quiet /l c:\cfn\host-agent-install-log.txt\n",
"c:\\"Program Files\"\Amazon\cfn-bootstrap\cfn-init.exe -s ", {
"Ref": "AWS::StackName"
}, " --region ", {
"Ref": "AWS::Region"
}, " > c:\cfn\log\cfn-call-log 2>&1", "</script>"]]
}
},
这将安装代理并启用和启动服务。