gpt4 book ai didi

Windows CloudFormation 脚本、元数据命令未运行

转载 作者:行者123 更新时间:2023-12-03 07:45:35 24 4
gpt4 key购买 nike

下面是我的 CloudFormation 模板,用于创建安装了 Java 和 Tomcat 的 Windows EC2 实例。然而,元数据中的任何内容都没有被执行。我登录创建的EC2实例,找不到元数据中指定的文件夹。我的 CloudFormation 脚本缺少什么?

谢谢

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Script to create Windows AMI",
"Metadata": {
"AWS::CloudFormation::Designer": {
"94153bdc-589b-4aa8-b859-5e84a1051a50": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 280,
"y": 110
},
"z": 1,
"embeds": []
}
}
},
"Parameters": {},
"Rules": {},
"Mappings": {},
"Resources": {
"JavaTomcatEC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-06b19063",
"InstanceType": "t2.micro",
"KeyName": "WindowsTest"
},
"Metadata": {
"AWS::CloudFormation::Init": {
"configSets": {
"config": [
"setup"
]
},
"setup": {
"Install-Java-Tomcat-set-env-variables-paths": {
"files": {
"c:\\cfn\\modules\\jdk-8u151-windows-x64.exe": {
"source": "https://s3.amazonaws.com/windows-ami-software/jdk-8u151-windows-x64.exe"
},
"c:\\cfn\\modules\\apache-tomcat-8.5.23.exe": {
"source": "https://s3.amazonaws.com/windows-ami-software/apache-tomcat-8.5.23.exe"
},
"c:\\cfn\\scripts\\Install-Java-JDK.ps1": {
"content": {
"Fn::Join": [
"",
[
"Set-Location C:\\cfn\\modules;",
".\\jdk-8u151-windows-x64.exe /s ADDLOCAL=\"ToolsFeature,SourceFeature,PublicjreFeature\"",
"\n"
]
]
}
},
"c:\\cfn\\scripts\\Install-Tomcat8.ps1": {
"content": {
"Fn::Join": [
"",
[
"Set-Location C:\\cfn\\modules;",
".\\apache-tomcat-8.5.23.exe /S",
"\n"
]
]
}
},
"c:\\cfn\\scripts\\Set-Java-Tomcat8-Paths-Homes.ps1": {
"content": {
"Fn::Join": [
"",
[
"$oldPath=(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Environment' -Name PATH).Path;",
"$addedFolder = 'C:\\Program Files\\Java\\jdk1.8.0_151\\bin; C:\\Program Files\\Apache Software Foundation\\Tomcat 8.5\\bin';",
"$newPath = $oldPath +';'+$addedFolder;",
"Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Environment' -Name PATH -Value $newPath ;",
"[Environment]::SetEnvironmentVariable('CATALINA_HOME', 'C:\\Program Files\\Apache Software Foundation\\Tomcat 8.5\\', 'Machine');",
"[Environment]::SetEnvironmentVariable('JAVA_HOME', 'C:\\Program Files\\Java\\jdk1.8.0_151\\', 'Machine');",
"Restart-Computer -Force;",
"\n"
]
]
}
},
"c:\\cfn\\scripts\\Install-Tomcat8-Service.ps1": {
"content": {
"Fn::Join": [
"",
[
"Set-Location 'C:\\Program Files\\Apache Software Foundation\\Tomcat 8.5\\bin';",
".\\service.bat install;",
"Set-Service Tomcat8 -StartupType Automatic;",
"Start-Service Tomcat8;",
"\n"
]
]
}
}
},
"commands": {
"a-Install-Java-JDK": {
"command": "powershell.exe -ExecutionPolicy RemoteSigned -Command c:\\cfn\\scripts\\Install-Java-JDK.ps1",
"waitAfterCompletion": "30"
},
"b-Install-Tomcat8": {
"command": "powershell.exe -ExecutionPolicy RemoteSigned -Command c:\\cfn\\scripts\\Install-Tomcat8.ps1",
"waitAfterCompletion": "30"
},
"c-Set-Java-Tomcat8-Paths-Homes": {
"command": "powershell.exe -ExecutionPolicy RemoteSigned -Command c:\\cfn\\scripts\\Set-Java-Tomcat8-Paths-Homes.ps1",
"waitAfterCompletion": "forever"
},
"d-Install-Tomcat8-Service": {
"command": "powershell.exe -ExecutionPolicy RemoteSigned -Command c:\\cfn\\scripts\\Install-Tomcat8-Service.ps1",
"waitAfterCompletion": "30"
}
}
}
}
},
"AWS::CloudFormation::Designer": {
"id": "94153bdc-589b-4aa8-b859-5e84a1051a50"
}
}
}
}

}

最佳答案

您需要检查两件事:

  1. 检查这些脚本是否在位置 C:\cfn\scripts 上创建--如果没有则检查问题出在哪里

  2. 如果这些脚本是在那里创建的,则单独调用 configSets 中的步骤 “commands”(第 33-34 行)。我怀疑这是实际脚本没有被调用的问题。

关于Windows CloudFormation 脚本、元数据命令未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47272555/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com