Run Packages Installation Commands on Amazon Linux 2 using EB Extensions

Viewed 1755

I'm running ASP.NET Core 3.1 Application on Elastic Beanstalk with Amazon Linux 2 EC2 instances. I need my app to be able to generate QR codes and for this I'm using QRCoder library. It worked on my Windows machine out of the box, but to make it work on Amazon Linux 2 machine I had to run the following commands via SSH:

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

After running these commands EB app servers also need to be restarted for image generation to work.

I tried to script it by creating .ebextensions/install_gdi.config file in my application repo root directory with the following contents:

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

I rebuilt my Beanstalk environment to have fresh EC2 instances redeployed version, and it seems that EB extensions config file isn't doing anything. Images still cannot be generated until I connect via SSH and run those command manually on EC2 instance.

I read that there are alternative ways to automate instance provisioning for Amazon Linux 2 but I wasn't able to find good examples to explore things like pre deployment hooks and Buildfile and it also seems that EB extensions is the right tool for the job in this case.

My application is deployed to Elastic Beanstalk using AWS CodePipeline, which is hooked to a GitHub repo.

2 Answers

I tried to replicate the issue on EB with Amazon Linux 2, but your commands worked perfectly fine. I used Python platform, not .NET, but since both are based on AL2 I don't see why would they be different in this aspect.

To troubleshoot, you can ssh into your EB instance, or download EB logs from console and inspect /var/log/cfn-init-cmd.log. It should have details regarding install_gdi.config execution.

For comparision, I attach my output:

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.

The problem was with my buildspec.yml file.

It used to look like this and it didn't include .ebxtensions folder into the publish artifact folder:

version: 0.2

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

I changed it to look like this and it works now:

version: 0.2

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