Created
May 26, 2025 08:29
-
-
Save rr-on-gh/14a271b34112bb4820db97114217a552 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aws ec2 describe-images \ | |
--filters "Name=name,Values=Windows_Server-2022-English-Full-Base-*" \ | |
"Name=root-device-type,Values=ebs" \ | |
--owners amazon "099720109477" \ | |
--query 'Images[*] | sort_by(@, &CreationDate)[-1].ImageId' \ | |
--output text | |
aws ec2 run-instances \ | |
--image-id <AMI ID from prev command> \ | |
--instance-type m6a.xlarge \ | |
--block-device-mappings '[{ | |
"DeviceName": "/dev/sda1", | |
"Ebs": { | |
"VolumeSize": 50, | |
"VolumeType": "gp3", | |
"DeleteOnTermination": false, | |
"Encrypted": false | |
} | |
}]' \ | |
--user-data file://packer_bootstrap.yml | |
aws ec2 create-image \ | |
--instance-id <Instance ID from prev command> \ | |
--name "dreggn-maigl-$(date +%Y%m%d%H%M%S)" \ | |
--description "Custom Windows Server 2022 AMI" | |
AMI_ID="<AMI ID from prev command>" | |
while true; do | |
STATUS=$(aws ec2 describe-images \ | |
--image-ids $AMI_ID \ | |
--query 'Images[0].State' \ | |
--output text) | |
echo "$(date '+%Y-%m-%d %H:%M:%S') - AMI Status: $STATUS" | |
if [ "$STATUS" = "available" ]; then | |
echo "AMI creation completed successfully" | |
break | |
elif [ "$STATUS" = "failed" ]; then | |
echo "AMI creation failed" | |
break | |
fi | |
echo "AMI creation in progress" | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment