使用EB扩展在Amazon Linux 2上运行软件包安装命令

问题描述

我正在使用Amazon Linux 2 EC2实例在Elastic Beanstalk上运行ASP.NET Core 3.1应用程序。我需要我的应用程序能够生成QR码,为此,我正在使用QRCoder库。它开箱即用地在我的Windows计算机上运行,​​但是要使其在Amazon Linux 2计算机上运行,​​我必须通过SSH运行以下命令:

sudo amazon-linux-extras install epel
sudo yum install libgdiplus

运行这些命令后,还需要重新启动EB应用服务器,以使图像生成正常工作。

我试图通过在应用程序回购根目录中创建.ebextensions/install_gdi.config文件来编写脚本,其内容如下:

commands:
  00_install_extras:
    command: amazon-linux-extras install -y epel
  01_install_gdi:
    command: yum install -y libgdiplus

我重建了Beanstalk环境,使其具有重新部署的新EC2实例版本,而且EB扩展配置文件似乎没有任何作用。在我通过SSH连接并在EC2实例上手动运行这些命令之前,仍然无法生成图像。

我读到有其他方法可以自动执行Amazon Linux 2的实例配置,但是我无法找到很好的示例来探索诸如预部署钩子和Buildfile之类的东西,而且EB扩展似乎是正确的工具。在这种情况下工作。

我的应用程序使用AWS CodePipeline部署到Elastic Beanstalk,该代码钩接到GitHub存储库上。

解决方法

我尝试在Amazon Linux 2的EB上复制该问题,但是您的commands正常运行。我使用的是Python平台,而不是.NET,但是由于两者均基于AL2,所以我不明白为什么它们在这方面会有所不同。

故障排除,您可以进入EB实例,或从控制台下载EB日志并检查/var/log/cfn-init-cmd.log。它应该包含有关install_gdi.config执行的详细信息。

为了比较,我附上我的输出:

2020-08-30 05:34:52,631 P3617 [INFO] Command 01_install_gdi
2020-08-30 05:35:08,423 P3617 [INFO] -----------------------Command Output-----------------------
2020-08-30 05:35:08,423 P3617 [INFO]    Loaded plugins: extras_suggestions,langpacks,priorities,update-motd
2020-08-30 05:35:08,423 P3617 [INFO]    http://csc.mcs.sdsmt.edu/epel/7/x86_64/repodata/0e811d5e2eb547161695f97c2fb8c2eaa0ccfe0ba7125321404db90dab5af5b3-updateinfo.xml.bz2: [Errno 12] Timeout on http://csc.mcs.sdsmt.edu/epel/7/x86_64/repodata/0e811d5e2eb547161695f97c2fb8c2eaa0ccfe0ba7125321404db90dab5af5b3-updateinfo.xml.bz2: (28,'Operation too slow. Less than 1000 bytes/sec transferred the last 5 seconds')
2020-08-30 05:35:08,423 P3617 [INFO]    Trying other mirror.
2020-08-30 05:35:08,423 P3617 [INFO]    200 packages excluded due to repository priority protections
2020-08-30 05:35:08,423 P3617 [INFO]    Resolving Dependencies
2020-08-30 05:35:08,424 P3617 [INFO]    --> Running transaction check
2020-08-30 05:35:08,424 P3617 [INFO]    ---> Package libgdiplus.x86_64 0:2.10-10.el7 will be installed
2020-08-30 05:35:08,424 P3617 [INFO]    --> Processing Dependency: libXrender.so.1()(64bit) for package: libgdiplus-2.10-10.el7.x86_64
2020-08-30 05:35:08,424 P3617 [INFO]    --> Processing Dependency: libcairo.so.2()(64bit) for package: libgdiplus-2.10-10.el7.x86_64
2020-08-30 05:35:08,424 P3617 [INFO]    --> Processing Dependency: libexif.so.12()(64bit) for package: libgdiplus-2.10-10.el7.x86_64
2020-08-30 05:35:08,424 P3617 [INFO]    --> Processing Dependency: libgif.so.4()(64bit) for package: libgdiplus-2.10-10.el7.x86_64
#
# more logs
#
2020-08-30 05:35:08,433 P3617 [INFO]
2020-08-30 05:35:08,433 P3617 [INFO]    Installed:
2020-08-30 05:35:08,434 P3617 [INFO]      libgdiplus.x86_64 0:2.10-10.el7
2020-08-30 05:35:08,434 P3617 [INFO]
#
# more logs
#
2020-08-30 05:35:08,435 P3617 [INFO]    Complete!
2020-08-30 05:35:08,435 P3617 [INFO] ------------------------------------------------------------
2020-08-30 05:35:08,435 P3617 [INFO] Completed successfully.

,

问题出在我的buildspec.yml文件上。

它以前看起来像这样,但没有在发布工件文件夹中包含.ebxtensions文件夹:

version: 0.2

phases:
  build:
    commands:
      - dotnet publish WebApi.csproj -c Release
artifacts:
  files:
    - bin/Release/netcoreapp3.1/publish/*
  discard-paths: yes

我将其更改为如下所示,现在可以使用:

version: 0.2

phases:
  build:
    commands:
      - dotnet publish WebApi.csproj -c Release
artifacts:
  files:
    - '**/*'
  base-directory: bin/Release/netcoreapp3.1/publish

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...