From d4c450e307ba9579e18b1a6ac09f0436ec0d402a Mon Sep 17 00:00:00 2001 From: Andrew Womeldorf Date: Mon, 14 Aug 2023 16:42:35 -0500 Subject: [PATCH] Refactor EC2 Volume to allow optional properties. (#1231) The existing EC2 Volume transformation assumes all properties will be present. See [EC2 API Reference for Volumes](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_Volume.html) to see that all properties on the Volume are optional. --- cartography/intel/aws/ec2/volumes.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cartography/intel/aws/ec2/volumes.py b/cartography/intel/aws/ec2/volumes.py index 3ad50f1186..6b8610d3cc 100644 --- a/cartography/intel/aws/ec2/volumes.py +++ b/cartography/intel/aws/ec2/volumes.py @@ -36,19 +36,19 @@ def transform_volumes(volumes: List[Dict[str, Any]], region: str, current_aws_ac volume_id = volume['VolumeId'] raw_vol = ({ 'Arn': build_arn('ec2', current_aws_account_id, 'volume', volume_id, region), - 'AvailabilityZone': volume['AvailabilityZone'], - 'CreateTime': volume['CreateTime'], - 'Encrypted': volume['Encrypted'], - 'Size': volume['Size'], - 'State': volume['State'], - 'OutpostArn': volume['OutpostArn'], - 'SnapshotId': volume['SnapshotId'], - 'Iops': volume['Iops'], - 'FastRestored': volume['FastRestored'], - 'MultiAttachEnabled': volume['MultiAttachEnabled'], - 'VolumeType': volume['VolumeType'], + 'AvailabilityZone': volume.get('AvailabilityZone'), + 'CreateTime': volume.get('CreateTime'), + 'Encrypted': volume.get('Encrypted'), + 'Size': volume.get('Size'), + 'State': volume.get('State'), + 'OutpostArn': volume.get('OutpostArn'), + 'SnapshotId': volume.get('SnapshotId'), + 'Iops': volume.get('Iops'), + 'FastRestored': volume.get('FastRestored'), + 'MultiAttachEnabled': volume.get('MultiAttachEnabled'), + 'VolumeType': volume.get('VolumeType'), 'VolumeId': volume_id, - 'KmsKeyId': volume['KmsKeyId'], + 'KmsKeyId': volume.get('KmsKeyId'), }) if not active_attachments: