Building a perl package for Amazon Linux, CentOS or RHEL

A previous post detailed on how to build a .deb file for a perl module on Ubuntu. However, I needed the updated module as a .rpm on an Amazon Linux system, so I created the procedure for that OS as well. It was a lot easier than I thought it would be.

# install general dependencies of Net::Amazon::EC2
sudo yum --enablerepo=epel install \
    perl-Net-Amazon-EC2 perl-File-Slurp perl-DBI perl-DBD-MySQL \
    perl-Net-SSLeay perl-IO-Socket-SSL perl-Time-HiRes perl-Params-Validate \
    perl-Date-Manip perl-DateTime perl-DateTime-Format-ISO8601 \

# install stuff required for the build
sudo yum --enablerepo=epel install cpanspec rpm-build.x86_64
sudo yum --enablerepo=epel install perl-Test-Exception perl-CPAN

# generate .spec file
PACKAGER="John Smith <jsmith@example.com>"
cpanspec --packager "$PACKAGER" -v Net::Amazon::EC2

# get the source
mkdir -p rpmbuild/SOURCES
wget -Orpmbuild/SOURCES/Net-Amazon-EC2-0.23.tar.gz \

# don't set these or tests will fail

# do the build
rpmbuild -bb perl-Net-Amazon-EC2.spec


Piping STDOUT to one command but STDERR to a different command

Found this awesome stackoverflow answer and had to write it up as a note to myself:

./foobar.pl > >( logger -t stdout ) 2> >( logger -t stderr )

Specifically, I hope to use this to replicate all EBS snapshots taken on an instance, e.g.:

ec2-consistent-snapshot > >( ec2-replicate-snapshots ) 2> >( logger -t $PROGNAME )


Building a perl package for Ubuntu

I recently had a need to update an Ubuntu perl module for a client at $WORK. Specifically I needed to update the Net::Amazon::EC2 module to version 0.23 to support tagging of AWS resources. Looking at CPAN, the library went un-maintained for close to 3 years before a new author picked it up. Things are looking up though as it seems this fall's release of Ubuntu will likely have the new package.

Still, this project couldn't wait till then. Thankfully, I found a good article on how to roll your own Debian packages for perl modules. There were only 2 hangups. First, the "make test" step fails because it can't do the authentication for AWS. I've disabled the "make test" step in my procedure by exporting the variable DEB_BUILD_OPTIONS="nocheck". After that the module package builds fine, but there's no dependencies set so when installing it, it can't be used without a few rounds of dependency hell. To solve this, I just borrowed the dependency list from the current 0.14 version of the package. The borrowed dependencies were "perl, libmoose-perl, libparams-validate-perl, liburi-perl, libwww-perl, libxml-simple-perl".

Note, this is not a well-tuned setup. There's lots of peculiarities that the dh-make-perl and debuild process wants that can be glossed over. For example - if you don't have a pgp key for your $DEBEMAIL address in you private keychain, the .deb package will still build, but it won't be signed. This may or may not be a problem for you, YMMV.

Here's the steps I took for building the .deb:

# install some packages
sudo apt-get update
sudo apt-get install dh-make-perl libmodule-build-perl debhelper devscripts
sudo apt-file update

# do the build

# note: disable "make test" so you don't need valid AWS keys
# (I couldn't make it work because even though I set the end variables,
# I think dh-make-build cleans the environment before running make)
export DEB_BUILD_OPTIONS="nocheck"

export DEBFULLNAME="John Smith"
git config --global user.name $DEBFULLNAME
export DEBEMAIL="jsmith@example.com"
git config --global user.email $DEBEMAIL

wget http://search.cpan.org/CPAN/authors/id/M/MA/MALLEN/Net-Amazon-EC2-0.23.tar.gz
mkdir builder
cd builder
# debian is particular how original tar files are named
ln -s ../Net-Amazon-EC2-0.23.tar.gz libnet-amazon-ec2-perl_0.23.orig.tar.gz
tar -pzxvf libnet-amazon-ec2-perl_0.23.orig.tar.gz
cd Net-Amazon-EC2-0.23/
dh-make-perl --depends "perl, libmoose-perl, libparams-validate-perl, liburi-perl, libwww-perl, libxml-simple-perl" .
cd ..
# viola, a .deb package
dpkg --info libnet-amazon-ec2-perl_0.23-1_all.deb

Ratings and Recommendations by outbrain