Windows上的Beanstalk:如何防止在重新部署时运行命令?

Sam*_*ack 7 windows amazon-web-services amazon-elastic-beanstalk

我正在尝试利用AWS Elastic Beanstalk的工具来自定义它创建的EC2实例.这需要在.ebextensions目录中创建.config文件.

您可以指定在将应用程序部署到实例时应执行的许多命令.我正在使用它来安装一些msi文件,并且还要配置EC2以为实例分配唯一的名称.然后需要重启.

我的问题是我只希望在首次部署实例时运行这些命令.当我将仅代码更改部署到现有实例时,不应该运行它们.

我尝试过使用"test"参数,这会阻止命令运行.我创建一个文件作为最后一个命令,然后我检查"test"参数中是否存在该文件.但它似乎没有用.

我的配置文件是这样的:

# File structure documented at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-windows-ec2.html
files:
  "C:\\Users\\Public\\EnableEc2SetComputerName.ps1":
    source: "[File Source]"
commands:
  init-01-ec2setcomputername-enable:
    test: cmd /c "if exist C:\\Users\\Public\\initialised (exit 1) else (exit 0)"
    command: powershell.exe -ExecutionPolicy Bypass -File "C:\\Users\\Public\\EnableEc2SetComputerName.ps1"
    waitAfterCompletion: 0
  init-05-reboot-instance:
    test: cmd /c "if exist C:\\Users\\Public\\initialised (exit 1) else (exit 0)"
    command: shutdown -r # restart to enable EC2 to set the computer name
    waitAfterCompletion: forever
  init-06-mark-initialised:
    test: cmd /c "if exist C:\\Users\\Public\\initialised (exit 1) else (exit 0)"
    command: echo initialised > C:\\Users\\Public\\initialised
    waitAfterCompletion: 0
Run Code Online (Sandbox Code Playgroud)

有没有其他方法来实现这一目标?或者我做了一些愚蠢的事情?

在基于Unix的系统上,有touchtest命令(在本回答中提到了Unix系统的等效问题).在这种情况下,Windows中最有效的是什么?

Pet*_*SFT 3

本质上,不。Elastic Beanstalk 是一个抽象概念,负责为您管理底层基础设施。您放弃了很多环境控制并获得了更轻松的部署。如果您研究 CloudFormation - 特别是元数据和 cfn-init / cfn-hup,您将看到围绕 beanstalkfilescommands http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide的非常相似的构造/aws-resource-init.html

如果您需要在应用程序自定义之外进行实例自定义 - 那么您可能使用了错误的工具,并且必须采用笨拙的解决方法(直到来自 AWS 的触摸/测试)Cloud Formation 脚本可能更适合。

我写了有关如何通过 cloudformation 配置 Windows 实例的文章,并且还有关于 Amazon本身的大量文档。

鉴于您已经完成了有关命令的所有艰苦工作,我认为转向 Cloud Formation 脚本并将一次性启动代码放入用户数据中将非常容易。

**编辑 - 我认为如果你使用弹性豆茎你可以这样做 command: dir initialised || powershell.exe -ExecutionPolicy Bypass -File "C:\\Users\\Public\\EnableEc2SetComputerName.ps1"