amazon-web-services - 使用 Elastic Beanstalk 在实例启动时运行 Windows Powershell 脚本

标签 amazon-web-services powershell amazon-ec2 amazon-elastic-beanstalk

我有一个简单的 Windows Powershell 脚本,我希望它在 Elastic Beanstalk 环境中启动时在 EC2 实例上运行。它只是设置一个自签名 SSL 证书并将其绑定(bind)到 IIS 中的默认网站。

我知道这可以通过使用 UserData 单独使用 EC2 实例来完成(如下所示)......但是如何处理在 EB 环境中启动的任何实例呢?

<powershell>
Import-Module WebAdministration
Set-Location IIS:\SslBindings
New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https
$c = New-SelfSignedCertificate -DnsName "domain.com" -CertStoreLocation cert:\LocalMachine\My
$c | New-Item 0.0.0.0!443
</powershell>

最佳答案

我不是 Powershell 专家,但您是否考虑过类似的问题:

  • 在源包中创建一个名为 .ebextensions 的文件夹
  • 创建一个任何名称的文件,但它应该具有 .config 扩展名
    (例如我的 script.config)并部署它。
  • myscript.confi 的内容应该有两个键,即 Files 和
    命令。注意这里的 Yaml 格式可能会关闭并且
    可能会导致部署失败

  •   files:  
            "c:/targetdirectory/my_script.ps1":
               content: |
           <powershell>
           Import-Module WebAdministration
           Set-Location IIS:\SslBindings
           New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https
           $c = New-SelfSignedCertificate -DnsName "domain.com" -CertStoreLocation cert:\LocalMachine\My
           $c | New-Item 0.0.0.0!443
           </powershell> 
               encoding: (encoding format either plain or base64)
      commands:
            run_my_script: 
                  command: ./my_script.ps1
                  cwd: "c:/targetdirectory/"
    


    所以基本上,你只是创建一个包含脚本的文件然后运行它。 More info is here .

    关于amazon-web-services - 使用 Elastic Beanstalk 在实例启动时运行 Windows Powershell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61345798/

    相关文章:

    amazon-web-services - 将 AWS SES 收到的电子邮件转换为人类可读的格式

    powershell - Powershell:通过字符串数组过滤文件的内容

    amazon-ec2 - <CoreOS, cloud-config> 在 Docker Private Registry 准备好之前如何设置 'Wait'?

    python - 在 Amazon Cognito MFA 中恢复

    amazon-web-services - AWS EBS、EC2、S3 之间的区别

    node.js - 使用 AWS SNS 的浏览器通知

    Powershell azure 模块

    Powershell "join"

    amazon-web-services - kubernetes LoadBalancer服务

    python - 我可以获得为我的每个账户运行的 AWS EC2 实例的列表吗?