Get images information with awscli

AWS owner ID of AMI images can be checked here: Cloud/AmazonEC2Image/Marketplace.

awscli package must be installed and AWS credentials configured before to run commands below.

New images starting from Debian 10 Buster

Get list of all official Debian images:

aws ec2 describe-images --region eu-north-1 --owners 136693071363 --query 'sort_by(Images, &CreationDate)[].[CreationDate,Name,ImageId]' --output table

Output example:

---------------------------------------------------------------------------------------
|                                   DescribeImages                                    |
+--------------------------+--------------------------------+-------------------------+
|  2019-09-09T08:52:18.000Z|  debian-10-amd64-20190909-10   |  ami-e634bf98           |
|  2019-09-09T09:12:17.000Z|  debian-10-arm64-20190909-10   |  ami-5b34bf25           |
|  2019-10-15T13:39:56.000Z|  debian-10-amd64-20191015-47   |  ami-060fdd0563bc99ed2  |
|  2019-10-15T13:54:55.000Z|  debian-10-arm64-20191015-47   |  ami-0bb0682cdb81a9e5b  |
|  2019-11-13T17:44:08.000Z|  debian-10-amd64-20191113-76   |  ami-000231dfbd34bff4b  |
|  2019-11-13T17:58:29.000Z|  debian-10-arm64-20191113-76   |  ami-0f191a4366d7e2c2e  |
|  2019-11-18T18:58:08.000Z|  debian-10-amd64-20191117-80   |  ami-0df5dd9cdb4d0246e  |
|  2019-11-18T19:12:29.000Z|  debian-10-arm64-20191117-80   |  ami-0eef4339da2df513c  |
|  2020-02-10T18:43:12.000Z|  debian-10-amd64-20200210-166  |  ami-0c82d9a7f5674320a  |
|  2020-02-10T19:04:56.000Z|  debian-10-arm64-20200210-166  |  ami-0cc1803d72d492d0c  |
|  2020-04-25T15:04:16.000Z|  debian-10-amd64-20200425-243  |  ami-06bbca612a67d8f30  |
|  2020-04-25T15:23:50.000Z|  debian-10-arm64-20200425-243  |  ami-0f7417d939abfa09f  |
|  2020-04-29T16:09:24.000Z|  debian-10-amd64-20200429-248  |  ami-0710d888a15af5250  |
|  2020-04-29T16:32:16.000Z|  debian-10-arm64-20200429-248  |  ami-0ddc7d17df785a116  |
|  2020-05-11T18:44:04.000Z|  debian-10-amd64-20200511-260  |  ami-01fc55264cb09eed8  |
|  2020-05-11T19:05:59.000Z|  debian-10-arm64-20200511-260  |  ami-029250cb3c05a9a94  |
|  2020-06-10T14:58:38.000Z|  debian-10-amd64-20200610-292  |  ami-0f39313b56c5ec3d9  |
|  2020-06-10T15:20:56.000Z|  debian-10-arm64-20200610-292  |  ami-0f06f418ccd37cf14  |
|  2020-06-10T20:29:37.000Z|  debian-10-amd64-20200610-293  |  ami-0e0ed860953d90a95  |
|  2020-06-10T20:54:56.000Z|  debian-10-arm64-20200610-293  |  ami-0e04701badea63ecf  |
+--------------------------+--------------------------------+-------------------------+

Get list of all official Debian 10 Buster images for x86_64 arch:

aws ec2 describe-images --region eu-north-1 --owners 136693071363 --filters 'Name=architecture,Values=x86_64' 'Name=name,Values=debian-10*' --query 'sort_by(Images, &CreationDate)[].[CreationDate,Name,ImageId]' --output table

Get only one AMI ID of latest Debian 10 Buster image for x86_64 arch:

aws ec2 describe-images --region eu-north-1 --owners 136693071363 --filters 'Name=architecture,Values=x86_64' 'Name=name,Values=debian-10*' --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' --output text

Old images till Debian 9 Stretch

Get list of all official Debian images before Debian 10:

aws ec2 describe-images --region eu-north-1 --owners 379101102735 --query 'sort_by(Images, &CreationDate)[].[CreationDate,Name,ImageId]' --output table

Output example:

---------------------------------------------------------------------------------------------------------
|                                            DescribeImages                                             |
+---------------------------+--------------------------------------------------+------------------------+
|  2019-01-14T22:10:34.000Z |  debian-stretch-hvm-x86_64-gp2-2019-01-14-59254  |  ami-0f170b0d6d3f779a8 |
|  2019-01-22T18:44:03.000Z |  debian-stretch-hvm-x86_64-gp2-2019-01-22-59357  |  ami-0a59d98ba4449a3ff |
|  2019-02-19T07:27:59.000Z |  debian-stretch-hvm-arm64-gp2-2019-02-19-26259   |  ami-03c6ccf3b408e6b55 |
|  2019-02-19T07:33:39.000Z |  debian-stretch-hvm-x86_64-gp2-2019-02-19-26620  |  ami-043a919b6dc7c51cc |
|  2019-04-29T18:15:26.000Z |  debian-stretch-hvm-arm64-gp2-2019-04-28-63458   |  ami-0dd987195ebcd2c72 |
|  2019-04-29T18:19:57.000Z |  debian-stretch-hvm-x86_64-gp2-2019-04-27-83345  |  ami-02cf25cb7fa2f633c |
|  2019-05-14T23:50:43.000Z |  debian-stretch-hvm-x86_64-gp2-2019-05-14-84483  |  ami-050f04ca573daa1fb |
|  2019-05-14T23:51:12.000Z |  debian-stretch-hvm-arm64-gp2-2019-05-14-84905   |  ami-02c20e69f398ea368 |
|  2019-06-18T22:15:11.000Z |  debian-stretch-hvm-x86_64-gp2-2019-06-18-79269  |  ami-0bc3de1bc9c65c14e |
|  2019-06-18T22:17:13.000Z |  debian-stretch-hvm-arm64-gp2-2019-06-18-79362   |  ami-0dcdbca6440555b17 |
|  2019-08-06T03:27:53.000Z |  debian-stretch-hvm-arm64-gp2-2019-08-06-10282   |  ami-0ecfc7de519f3ae94 |
|  2019-08-06T03:35:35.000Z |  debian-stretch-hvm-x86_64-gp2-2019-08-06-10230  |  ami-02d9a375d51f80e38 |
|  2019-08-13T16:46:34.000Z |  debian-stretch-hvm-x86_64-gp2-2019-08-13-59243  |  ami-0828202fd23cfc483 |
|  2019-08-13T16:47:33.000Z |  debian-stretch-hvm-arm64-gp2-2019-08-13-59426   |  ami-07329533adba4806e |
|  2019-09-08T05:10:38.000Z |  debian-stretch-hvm-arm64-gp2-2019-09-08-18091   |  ami-0ca7cb21876643388 |
|  2019-09-08T05:10:46.000Z |  debian-stretch-hvm-x86_64-gp2-2019-09-08-17994  |  ami-05b74a5b2e19a2a97 |
|  2019-10-15T17:52:41.000Z |  debian-stretch-hvm-x86_64-gp2-2019-10-15-63611  |  ami-04cc93d303a4dd18c |
|  2019-10-15T17:53:40.000Z |  debian-stretch-hvm-arm64-gp2-2019-10-15-63845   |  ami-0b7d4c988f3fbb201 |
|  2019-11-13T17:57:09.000Z |  debian-stretch-hvm-x86_64-gp2-2019-11-13-63558  |  ami-0779d91bf695ed455 |
|  2019-11-13T18:00:53.000Z |  debian-stretch-hvm-arm64-gp2-2019-11-13-64005   |  ami-064003f8fbd82d711 |
|  2020-02-10T20:49:03.000Z |  debian-stretch-hvm-x86_64-gp2-2020-02-10-73984  |  ami-098c2f770214112a1 |
|  2020-02-10T20:49:07.000Z |  debian-stretch-hvm-arm64-gp2-2020-02-10-74089   |  ami-024bf24155b02c7db |
+---------------------------+--------------------------------------------------+------------------------+

Get list of all official Debian 9 Stretch images for x86_64 arch:

aws ec2 describe-images --region eu-north-1 --owners 379101102735 --filters 'Name=architecture,Values=x86_64' 'Name=name,Values=debian-stretch*' --query 'sort_by(Images, &CreationDate)[].[CreationDate,Name,ImageId]' --output table

Get only one AMI ID of latest Debian 9 Stretch image for x86_64 arch:

aws ec2 describe-images --region eu-north-1 --owners 379101102735 --filters 'Name=architecture,Values=x86_64' 'Name=name,Values=debian-stretch*' --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' --output text

Create ec2 instance with latest Debian 10 Buster image

Example: how to create ec2 instance and how to use "cloud-config" parameters.

Next information have to be collected:

Replace all "XXXXX" before to run command.

   1 export AWS_DEFAULT_REGION="eu-north-1"
   2 export AWS_PROFILE="default"
   3 NAME="my-srv01"
   4 TAGS="{Key=Temporary,Value=Yes},{Key=Environment,Value=Dev},{Key=Name,Value=$NAME}"
   5 AMI=$(aws ec2 describe-images --owners 136693071363 --filters 'Name=architecture,Values=x86_64' 'Name=name,Values=debian-10*' --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' --output text)
   6 EBS_ROOT_DISK=$(aws ec2 describe-images --image-ids "$AMI" --query 'Images[0].BlockDeviceMappings[0].DeviceName' --output text)
   7 aws ec2 run-instances --image-id "$AMI" --count 1 --instance-type t3.micro --key-name "XXXXX" \
   8  --security-group-ids sg-XXXXX sg-XXXXX \
   9  --subnet-id subnet-XXXXX \
  10  --no-associate-public-ip-address \
  11  --credit-specification CpuCredits=standard \
  12  --instance-initiated-shutdown-behavior terminate \
  13  --tag-specifications "ResourceType=instance,Tags=[$TAGS]" "ResourceType=volume,Tags=[$TAGS,{Key=MountPoint,Value=/}]" \
  14  --block-device-mapping "DeviceName=${EBS_ROOT_DISK},Ebs={VolumeSize=10,Encrypted=true}" \
  15  --user-data "#cloud-config
  16 hostname: $NAME
  17 swap:
  18   filename: /swapfile01
  19   size: 209715200 # 200MB
  20 packages:
  21   - zsh
  22   - mc
  23   - awscli
  24 package_update: true
  25 package_upgrade: true
  26 package_reboot_if_required: true
  27 users:
  28   - default
  29   - name: my-username
  30     groups: [ adm, sudo ]
  31     sudo: [ 'ALL=(ALL) NOPASSWD:ALL' ]
  32     shell: /bin/zsh
  33     ssh-authorized-keys:
  34     - 'ssh-ed25519 AAAAXXXXX my-username@desktop'
  35     - 'ssh-rsa AAAAXXXXX my-username@laptop'
  36 write_files:
  37 - path: /ec2_tags.json
  38   permissions: '0644'
  39   owner: root:root
  40   content: |
  41     $TAGS
  42 "

Output example:

{
    "Groups": [],
    "Instances": [
        {
            "AmiLaunchIndex": 0,
            "ImageId": "ami-0e0ed860953d90a95",
            "InstanceId": "i-0f316e39f1a492930",
            "InstanceType": "t3.micro",
            "KeyName": "XXXXX",
            "LaunchTime": "2020-06-10T22:53:02.000Z",
            "Monitoring": {
                "State": "disabled"
            },
            "Placement": {
                "AvailabilityZone": "eu-north-1c",
                "GroupName": "",
                "Tenancy": "default"
            },
            "PrivateDnsName": "ip-10-0-102-151.eu-north-1.compute.internal",
            "PrivateIpAddress": "10.0.102.151",
            "ProductCodes": [],
            "PublicDnsName": "",
            "State": {
                "Code": 0,
                "Name": "pending"
            },
            "StateTransitionReason": "",
            "SubnetId": "subnet-041d1bf391f3ee9fc",
            "VpcId": "vpc-0678dbd17b8cd21bd",
            "Architecture": "x86_64",
            "BlockDeviceMappings": [],
            "ClientToken": "YYYYY",
            "EbsOptimized": false,
            "Hypervisor": "xen",
            "NetworkInterfaces": [
                {
                    "Attachment": {
                        "AttachTime": "2020-06-10T22:53:02.000Z",
                        "AttachmentId": "eni-attach-0c69bb940da04bf24",
                        "DeleteOnTermination": true,
                        "DeviceIndex": 0,
                        "Status": "attaching"
                    },
                    "Description": "",
                    "Groups": [
                        {
                            "GroupName": "default",
                            "GroupId": "sg-09d91dd3ebacd42d3"
                        },
                        {
                            "GroupName": "allow_ssh",
                            "GroupId": "sg-09c73962b7c52801a"
                        }
                    ],
                    "Ipv6Addresses": [
                        {
                            "Ipv6Address": "2a05:d016:a7c:7501:f2d6:58ac:ee1c:ef14"
                        }
                    ],
                    "MacAddress": "0e:8a:c4:25:4b:3e",
                    "NetworkInterfaceId": "eni-02763a3cb13a289ff",
                    "OwnerId": "XXXXX",
                    "PrivateDnsName": "ip-10-0-102-151.eu-north-1.compute.internal",
                    "PrivateIpAddress": "10.0.102.151",
                    "PrivateIpAddresses": [
                        {
                            "Primary": true,
                            "PrivateDnsName": "ip-10-0-102-151.eu-north-1.compute.internal",
                            "PrivateIpAddress": "10.0.102.151"
                        }
                    ],
                    "SourceDestCheck": true,
                    "Status": "in-use",
                    "SubnetId": "subnet-041d1bf391f3ee9fc",
                    "VpcId": "vpc-0678dbd17b8cd21bd",
                    "InterfaceType": "interface"
                }
            ],
            "RootDeviceName": "/dev/xvda",
            "RootDeviceType": "ebs",
            "SecurityGroups": [
                {
                    "GroupName": "default",
                    "GroupId": "sg-09d91dd3ebacd42d3"
                },
                {
                    "GroupName": "allow_ssh",
                    "GroupId": "sg-09c73962b7c52801a"
                }
            ],
            "SourceDestCheck": true,
            "StateReason": {
                "Code": "pending",
                "Message": "pending"
            },
            "Tags": [
                {
                    "Key": "Environment",
                    "Value": "Dev"
                },
                {
                    "Key": "Name",
                    "Value": "my-srv01"
                },
                {
                    "Key": "Temporary",
                    "Value": "Yes"
                }
            ],
            "VirtualizationType": "hvm",
            "CpuOptions": {
                "CoreCount": 1,
                "ThreadsPerCore": 2
            },
            "CapacityReservationSpecification": {
                "CapacityReservationPreference": "open"
            },
            "MetadataOptions": {
                "State": "pending",
                "HttpTokens": "optional",
                "HttpPutResponseHopLimit": 1,
                "HttpEndpoint": "enabled"
            }
        }
    ],
    "OwnerId": "XXXXX",
    "ReservationId": "r-0c9cca1b60ab000f8"
}

Inside ec2 virtual machine, after login by SSH:

my-username@my-srv01 ~ % free -m
              total        used        free      shared  buff/cache   available
Mem:            961          61         497           2         402         756
Swap:             0           0           0
my-username@my-srv01 ~ %
my-username@my-srv01 ~ % df -h
Filesystem       Size  Used Avail Use% Mounted on
udev             473M     0  473M   0% /dev
tmpfs             97M  2.8M   94M   3% /run
/dev/nvme0n1p1   9.7G  964M  8.3G  11% /
tmpfs            481M     0  481M   0% /dev/shm
tmpfs            5.0M     0  5.0M   0% /run/lock
tmpfs            481M     0  481M   0% /sys/fs/cgroup
/dev/nvme0n1p15  124M  262K  124M   1% /boot/efi
tmpfs             97M     0   97M   0% /run/user/1000
my-username@my-srv01 ~ %
my-username@my-srv01 ~ % cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
my-username@my-srv01 ~ %
my-username@my-srv01 ~ % cat /etc/apt/sources.list
deb http://cdn-aws.deb.debian.org/debian buster main
deb-src http://cdn-aws.deb.debian.org/debian buster main
deb http://security.debian.org/debian-security buster/updates main
deb-src http://security.debian.org/debian-security buster/updates main
deb http://cdn-aws.deb.debian.org/debian buster-updates main
deb-src http://cdn-aws.deb.debian.org/debian buster-updates main
deb http://cdn-aws.deb.debian.org/debian buster-backports main
deb-src http://cdn-aws.deb.debian.org/debian buster-backports main
my-username@my-srv01 ~ %
my-username@my-srv01 ~ % lscpu
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
Address sizes:       46 bits physical, 48 bits virtual
CPU(s):              2
On-line CPU(s) list: 0,1
Thread(s) per core:  2
Core(s) per socket:  1
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               85
Model name:          Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz
Stepping:            4
CPU MHz:             2499.998
BogoMIPS:            4999.99
Hypervisor vendor:   KVM
Virtualization type: full
L1d cache:           32K
L1i cache:           32K
L2 cache:            1024K
L3 cache:            33792K
NUMA node0 CPU(s):   0,1
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves ida arat pku ospke
my-username@my-srv01 ~ %
my-username@my-srv01 ~ % lsblk
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
nvme0n1      259:0    0   10G  0 disk
├─nvme0n1p1  259:4    0  9.9G  0 part /
├─nvme0n1p14 259:5    0    3M  0 part
└─nvme0n1p15 259:6    0  124M  0 part /boot/efi

See also

License

https://i.creativecommons.org/l/by/4.0/88x31.png This work is licensed under a Creative Commons Attribution 4.0 International License or newer.