Amazon Machine Images (AMIs) and Azure Compute Gallery (formerly Shared Image Gallery): - unix1998/technical_notes GitHub Wiki
both AWS and Azure allow customers to store their own OS images, and both provide REST APIs and command-line interfaces (CLI) to manage these images. Here’s an overview and examples for both platforms.
AWS (Amazon Web Services)
Amazon Machine Images (AMIs):
-
REST API: AWS provides the EC2 API for managing AMIs. You can register an image using the
RegisterImage
API action.- Documentation: RegisterImage API
-
AWS CLI: You can create and manage AMIs using the AWS Command Line Interface (CLI).
-
To create an AMI from an instance:
aws ec2 create-image --instance-id i-1234567890abcdef0 --name "My server" --no-reboot
-
To register a new AMI:
aws ec2 register-image --name "My server" --root-device-name /dev/sda1 --block-device-mappings DeviceName=/dev/sda1,Ebs={SnapshotId=snap-1234567890abcdef0}
-
Azure
Azure Compute Gallery (formerly Shared Image Gallery):
-
REST API: Azure provides REST APIs to manage images in the Compute Gallery. You can create an image version using the
Create or Update Image Version
API.- Documentation: Create or Update Image Version API
-
Azure CLI: You can use the Azure CLI to create and manage images in the Azure Compute Gallery.
-
To create a new image:
az image create --resource-group MyResourceGroup --name MyImage --source /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Compute/virtualMachines/{vm-name}
-
To create a new image version in a Shared Image Gallery:
az sig image-version create --resource-group MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImageDef --gallery-image-version 1.0.0 --managed-image /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Compute/images/{image-name}
-
Example Process
-
AWS: Creating an AMI
-
Create an image from a running instance:
aws ec2 create-image --instance-id i-1234567890abcdef0 --name "MyCustomAMI" --no-reboot
-
Registering a new AMI (if you have a snapshot):
aws ec2 register-image --name "MyCustomAMI" --root-device-name /dev/sda1 --block-device-mappings DeviceName=/dev/sda1,Ebs={SnapshotId=snap-1234567890abcdef0}
-
-
Azure: Creating an Image and Image Version
-
Create an image from a VM:
az image create --resource-group MyResourceGroup --name MyCustomImage --source /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Compute/virtualMachines/{vm-name}
-
Create an image version in a Shared Image Gallery:
az sig image-version create --resource-group MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImageDef --gallery-image-version 1.0.0 --managed-image /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Compute/images/MyCustomImage
-
Both AWS and Azure provide robust support for managing custom OS images through their respective APIs and CLIs, enabling automation and integration into deployment pipelines.