Skip to content

Commit 242491a

Browse files
authored
Add new columns to aws_ec2_ami table (#2774)
1 parent 9a1825c commit 242491a

4 files changed

Lines changed: 70 additions & 1 deletion

File tree

aws-test/tests/aws_ec2_ami/test-get-expected.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,41 @@
55
{
66
"DeviceName":"/dev/sda1",
77
"Ebs": {
8+
"AvailabilityZone": null,
9+
"AvailabilityZoneId": null,
810
"DeleteOnTermination":true,
911
"Encrypted":true,
1012
"Iops":null,
1113
"KmsKeyId":null,
1214
"OutpostArn": null,
1315
"SnapshotId":"{{ output.snapshot_id.value }}",
1416
"Throughput": null,
17+
"VolumeInitializationRate": null,
1518
"VolumeSize":8,
1619
"VolumeType":"standard"
1720
},
1821
"NoDevice":null,
1922
"VirtualName":null
2023
}
2124
],
25+
"deregistration_protection": "disabled",
2226
"description": "This is a test image.",
2327
"ena_support": false,
28+
"free_tier_eligible": true,
2429
"hypervisor": "xen",
30+
"image_allowed": null,
2531
"image_id": "{{ output.resource_id.value }}",
2632
"image_location": "{{ output.account_id.value }}/{{resourceName}}",
2733
"image_type": "machine",
34+
"last_launched_time": null,
2835
"name": "{{resourceName}}",
2936
"owner_id": "{{ output.account_id.value }}",
3037
"platform_details": "Linux/UNIX",
3138
"public": false,
3239
"root_device_name": "/dev/sda1",
3340
"root_device_type": "ebs",
41+
"source_image_id": null,
42+
"source_image_region": null,
3443
"sriov_net_support": "simple",
3544
"tags_src": [
3645
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
select name, image_id, image_type, image_location, architecture, description, ena_support, hypervisor, owner_id, platform_details, public, root_device_name, root_device_type, sriov_net_support, usage_operation, virtualization_type, block_device_mappings, tags_src
1+
select name, image_id, image_type, image_location, architecture, description, ena_support, hypervisor, owner_id, platform_details, public, root_device_name, root_device_type, sriov_net_support, usage_operation, virtualization_type, block_device_mappings, tags_src, deregistration_protection, free_tier_eligible, image_allowed, source_image_id, source_image_region, last_launched_time
22
from aws.aws_ec2_ami
33
where image_id = '{{ output.resource_id.value }}'

aws/table_aws_ec2_ami.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,37 @@ func tableAwsEc2Ami(_ context.Context) *plugin.Table {
104104
Type: proto.ColumnType_TIMESTAMP,
105105
Transform: transform.FromField("DeprecationTime").Transform(transform.NullIfZeroValue),
106106
},
107+
{
108+
Name: "last_launched_time",
109+
Description: "The date and time, in ISO 8601 date-time format, when the AMI was last used to launch an EC2 instance. When the AMI is used to launch an instance, there is a 24-hour delay before that usage is reported.",
110+
Type: proto.ColumnType_TIMESTAMP,
111+
Transform: transform.FromField("LastLaunchedTime").Transform(transform.NullIfZeroValue),
112+
},
113+
{
114+
Name: "deregistration_protection",
115+
Description: "Indicates whether deregistration protection is enabled for the AMI.",
116+
Type: proto.ColumnType_STRING,
117+
},
118+
{
119+
Name: "free_tier_eligible",
120+
Description: "Indicates whether the image is eligible for Amazon Web Services Free Tier.",
121+
Type: proto.ColumnType_BOOL,
122+
},
123+
{
124+
Name: "image_allowed",
125+
Description: "If true, the AMI satisfies the criteria for Allowed AMIs and can be discovered and used in the account.",
126+
Type: proto.ColumnType_BOOL,
127+
},
128+
{
129+
Name: "source_image_id",
130+
Description: "The ID of the source AMI from which the AMI was created. Only appears if the AMI was created using CreateImage, CopyImage, or CreateRestoreImageTask.",
131+
Type: proto.ColumnType_STRING,
132+
},
133+
{
134+
Name: "source_image_region",
135+
Description: "The Region of the source AMI. Only appears if the AMI was created using CreateImage, CopyImage, or CreateRestoreImageTask.",
136+
Type: proto.ColumnType_STRING,
137+
},
107138
{
108139
Name: "architecture",
109140
Description: "The architecture of the image.",

docs/tables/aws_ec2_ami.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,35 @@ where
9898
state = 'failed';
9999
```
100100

101+
### List AMIs not launched in the last 90 days
102+
Identify AMIs that haven't been used recently, helping you find candidates for deregistration to reduce storage costs and simplify your AMI inventory.
103+
104+
```sql+postgres
105+
select
106+
name,
107+
image_id,
108+
creation_date,
109+
last_launched_time
110+
from
111+
aws_ec2_ami
112+
where
113+
last_launched_time < now() - interval '90 days'
114+
or last_launched_time is null;
115+
```
116+
117+
```sql+sqlite
118+
select
119+
name,
120+
image_id,
121+
creation_date,
122+
last_launched_time
123+
from
124+
aws_ec2_ami
125+
where
126+
last_launched_time < datetime('now', '-90 days')
127+
or last_launched_time is null;
128+
```
129+
101130
### Get volume info for each AMI
102131
Explore the characteristics of each Amazon Machine Image (AMI), such as volume size and type, encryption status, and deletion policy. This information is vital for managing storage resources efficiently and ensuring data security within your AWS EC2 environment.
103132

0 commit comments

Comments
 (0)