Right now, I'm supporting a customer that's a heavy user of Linux for their business support systems. They're in the process of migrating from our legacy hosting environment to hosting things on AWS. During their development phase, use of CentOS was sufficient for their needs. As they move to production, however, they want "real" Red Hat Enterprise Linux.
Go up on the MarketPlace and there's plenty of options to choose from. However, my customer doesn't want to deal with buying a stand-alone entitlement to patch-support for their AWS-hosted systems. This requirement considerably cuts down on the useful choices in the MarketPlace. There's still "license included" Red Hat options to choose from.
Unfortunately, my customer also has fairly specific partitioning requirements that are not met by the "license included" AMIs. When using CentOS, this wan't a problem - CentOS's patch repos are open-access. Creating an AMI with suitable partitioning and access to those public repos is about a 20 minute process. While some of that process is leveragable for creating a Red Hat AMI, making the resultant AMI be "license included" is a bit more challenging.
When I tried to simply re-use my CentOS process, supplemented by the Amazon repo RPMs, I ended up with a system that, when I did a yum-query, got me 401 errors. I was missing something.
Google searches weren't terribly helpful in solving my problem. I found a lot of "how do I do this" posts, but damned few that actually included the answer. Ultimately, what it turns out to be is that if you generate your AMI from an EBS snapshot, instances launched from that AMI don't have an entitlement key to access the Amazon yum repos. You can see this by looking at your launched instance's metadata:
# curl http://169.254.169.254/latest/dynamic/instance-identity/document
{
"accountId" : "717243568699",
"architecture" : "x86_64",
"availabilityZone" : "us-west-2b",
"billingProducts" : null,
"devpayProductCodes" : null,
"imageId" : "ami-9df0ec7a",
"instanceId" : "i-51825ba7",
"instanceType" : "t1.micro",
"kernelId" : "aki-fc8f11cc",
"pendingTime" : "2015-03-25T19:04:51Z",
"privateIp" : "172.31.19.148",
"ramdiskId" : null,
"region" : "us-east-1",
"version" : "2010-08-31"
}
Specifically, what you want to look at is the value for "billingProducts". If it's "null", your yum isn't going to be able to access the Amazon RPM repositories. Where I came up close to empty on my Google searches was "how to make this attribute persist across images".
I found a small note in a community forum post indicating that AMIs generated from an EBS snapshot will always have "billingProducts" set to "null". This is due to a limitation in the tool used to register an image from a snapshot.
To get around this limitation, one has to create an AMI from a instance of an entitled AMI. Basically, after you've created the EBS you've readied to make a custom AMI, you do a disk-swap with a properly-entitled instance. You then use the "create image" option from that instance. Once you launch AMI you created via the EBS-swap, your instance's metadata will now look something like:
# curl http://169.254.169.254/latest/dynamic/instance-identity/document
{
"accountId" : "717243568699",
"architecture" : "x86_64",
"availabilityZone" : "us-west-2b",
"billingProducts" : [ "bp-6fa54006" ],
"devpayProductCodes" : null,
"imageId" : "ami-9df0ec7a",
"instanceId" : "i-51825ba7",
"instanceType" : "t1.micro",
"kernelId" : "aki-fc8f11cc",
"pendingTime" : "2015-03-25T19:04:51Z",
"privateIp" : "172.31.19.148",
"ramdiskId" : null,
"region" : "us-east-1",
"version" : "2010-08-31"
}
Once that "billingProducts" is set, the cloud-init related first-boot scripts will take that "billingProducts" and use it to register the system with the Amazon yum repos. Voilà: you now have a fully custom AMI that uses Amazon-billed access to Red Hat updates.
Note on Compatibility: the Red Hat provided PVM AMIs do not yield well to this method. The Red Hat provided PVM AMIs are all designed with their boot/root device set to /dev/sda1. To date, attempts to leverage the above techniques for PVM AMIs that require their boot/root device set to /dev/sda (used when using a single, partitioned EBS to host a bare /boot partition and LVM-managed root partitions) have not met with success.
how to set the billing product manually in an AWS linux instance
ReplyDeleteCan't manually set (unless you have a MarketPlace account and are setting the billing product code that points to your MarketPlace account).
Delete