简体   繁体   English

在不使用自定义AMI的情况下自定义EC2 Windows实例

[英]Customzing EC2 Windows instances without using a Custom AMI

We are currently setting up a CloudFormation stack based on the template created by AWS Toolkit for Visual Studio when deploying using "Load balanced template". 我们目前正在使用“负载平衡模板”进行部署时,基于AWS Toolkit for Visual Studio创建的模板设置CloudFormation堆栈。 We need to create a script that customizes the EC2-instances somewhat. 我们需要创建一个可以在某种程度上自定义EC2实例的脚本。 More specifically we want to: 1. Install two certificates into the certificate store. 更具体地说,我们希望:1。将两个证书安装到证书库中。 2. Configure IIS to use one of the certificates. 2.配置IIS以使用其中一个证书。 3. Enable TLS 1.2 on IIS. 3.在IIS上启用TLS 1.2。

We need to install these certs at the IIS, instead of the load balancer, because we need to support client cert authentication. 我们需要在IIS而不是负载均衡器上安装这些证书,因为我们需要支持客户端证书身份验证。

We'd like to achieve this without having to create a custom AMI, because we want to be able to easily update the AMI as new versions arrive. 我们希望在不必创建自定义AMI的情况下实现这一点,因为我们希望能够在新版本到达时轻松更新AMI。 We are using the following: ami-f6803f9f (which is the default used by the template). 我们使用以下命令:ami-f6803f9f(这是模板使用的默认值)。

We therefore want to do these customizations as part of the CloudFormation template. 因此,我们希望将这些自定义作为CloudFormation模板的一部分进行。 I've tried to create a simple file (just to make sure the scripting works) by using the "AWS::CloudFormation::Init" part of the template. 我试图通过使用模板的“AWS :: CloudFormation :: Init”部分创建一个简单的文件(只是为了确保脚本工作)。 However, when I launch the stack the file never gets created. 但是,当我启动堆栈时,文件永远不会被创建。 The part of the template that is supposed to create the file looks like this: 应该创建文件的模板部分如下所示:

 "Metadata" : {
    "AWS::CloudFormation::Init" : {
      "config" : {
      "files" : {
        "C:/ClientCA.pfx" : {
          "content" : { "Fn::Join" : ["", [
            "test1\n",
            "test2\n"
            ]]}
        }
      }
    }
  }
}

My questions are therefore: 1. Why is the file not being created? 因此,我的问题是:1。为什么没有创建文件? Is it because there's something wrong with the template or does this AMI not supported these types if init-scripts? 是因为模板有问题还是这个AMI不支持这些类型的init-scripts? 2. We are planning on downloading the certs from S3 using "AWS::CloudFormation::Init" and the installing them using a PowerShell-script that we add to UserData. 2.我们计划使用“AWS :: CloudFormation :: Init”从S3下载证书,并使用我们添加到UserData的PowerShell脚本安装它们。 Is this a good approach or should we do it differently? 这是一个好方法还是我们应该采取不同的方式?

I've just tested your snippet with a current Windows Server 2012 AMI and it worked just fine. 我刚用当前的Windows Server 2012 AMI测试了你的代码片段,它运行得很好。 Therefore my best guess is that ami-f6803f9f is a custom AMI already (at least I can't find it anywhere official) and lacks the required orchestration for Deploying Applications with AWS CloudFormation (this is the generic explanation for Unix/Linux, see Bootstrapping AWS CloudFormation Windows Stacks for a short Windows oriented example): 因此我最好的猜测是ami-f6803f9f已经是一个自定义AMI(至少我在官方的任何地方找不到它)并且缺少使用AWS CloudFormation部署应用程序所需的编排(这是Unix / Linux的通用解释,请参阅Bootstrapping AWS CloudFormation Windows Stacks ,面向Windows的简短示例):

AWS CloudFormation includes a set of helper applications ( cfn-init , cfn-signal, cfn-get-metadata , and cfn-hup) that are based on cloud-init. AWS CloudFormation包含一组基于cloud-init的帮助应用程序( cfn-init ,cfn-signal, cfn-get-metadata和cfn-hup)。 These helper applications not only provide functionality similar to cloud-init, but also allow you to update your metadata after your instance and applications are up and running. 这些帮助应用程序不仅提供类似于cloud-init的功能,还允许您在实例和应用程序启动并运行后更新元数据。 [...] [emphasis mine] [...] [强调我的]

The emphasized applications are those responsible for reading and acting on the metadata defined in the template, ie creating C:/ClientCA.pfx in your example. 强调的应用程序是那些负责读取和处理模板中定义的元数据的应用程序,即在您的示例中创建C:/ClientCA.pfx These helper applications are nowadays included in all current Amazon EBS-Backed Windows Server 2012 RTM AMIs , but haven't in the Amazon EBS-Backed Windows Server 2008 R2 AMIs usually, except for dedicated ones like the Amazon EBS-Backed Windows Server 2008 R2 English 64-bit - Base for CloudFormation . 这些助手应用程序现在包含在所有当前的Amazon EBS支持的Windows Server 2012 RTM AMI中 ,但通常不在Amazon EBS支持的Windows Server 2008 R2 AMI中 ,除了像Amazon EBS支持的Windows Server 2008 R2这样的专用应用程序英语64位 - CloudFormation的基础

Obviously you can also install these CloudFormation Helper Scripts on a custom AMI and move on from there, but if you haven't any specific reason to do so, I highly recommend to start with a current Amazon EBS-Backed Windows Server 2012 RTM AMI , which provides these and a few other likewise desired administrative productivity components out of the box (eg Windows PowerShell 3.0 and the new AWS Tools for Winodws PowerShell ). 显然,您也可以在自定义AMI上安装这些CloudFormation Helper脚本并从那里开始,但如果您没有任何具体原因,我强烈建议您从当前的Amazon EBS支持的Windows Server 2012 RTM AMI开始 ,它提供了这些以及一些其他同样需要的管理生产力组件(例如Windows PowerShell 3.0用于Winodws PowerShell的新AWS工具 )。

Old question - but I'm tipping that the reason the file is not being created is that the cloudformation script is not executing cfn-init. 旧问题 - 但我认为文件未被创建的原因是cloudformation脚本没有执行cfn-init。

The key part is to ensure that you've updated the userdata scripts... 关键部分是确保您已更新userdata脚本...

                "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
                "<script>\n",
                    "powershell.exe add-windowsfeature web-webserver -includeallsubfeature -logpath $env:temp\\webserver_addrole.log \n",
                    "powershell.exe add-windowsfeature web-mgmt-tools -includeallsubfeature -logpath $env:temp\\mgmttools_addrole.log \n",
                    "cfn-init.exe -v -s ", {"Ref" : "AWS::StackId"}, " -r WebServerLaunchConfiguration --region ", {"Ref" : "AWS::Region"}, "\n",
                "</script>\n",
                "<powershell>\n",
                    "new-website -name", {"Ref" : "Name"}, " -port 80 -physicalpath c:\\inetpub\\", {"Ref" : "Name"}, " -ApplicationPool \".NET v4.5\" -force \n",
                    "remove-website -name \"Default Web Site\" \n",
                    "start-website -name ", {"Ref" : "Name"}, " \n",
                "</powershell>"

The above script adds the web server features, the management tools, and then kicks of the cfn-init. 上面的脚本添加了Web服务器功能,管理工具,然后添加了cfn-init。 It's cfn-init that is responsible for parsing of the meta data. 它是cfn-init,负责解析元数据。

There are more details about bootstrapping IIS on AWS on my Kloud blog. 有关在我的Kloud博客上在AWS引导IIS的更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM