Skip to content

Commit

Permalink
Fixes snapshot fetching InvalidParameterValue bug (#832)
Browse files Browse the repository at this point in the history
* Fixes snapshot fetching InvalidParameterValue bug

It looks like the InvalidParameterValue bug (lyft/cartography#825) is still present after lyft/cartography#822. This adds an exception for error

* set snapshot id in load_snapshot_volume_relations

* filter for non empty snapshot ids

* setting snapshot id

Co-authored-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com>
  • Loading branch information
QinZuoyana and ramonpetgrave64 committed Apr 27, 2022
1 parent 07a054d commit 832b7fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cartography/intel/aws/ec2/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@ def _load_ec2_instance_ebs_tx(
UNWIND {ebs_mappings_list} as em
MERGE (vol:EBSVolume{id: em.Ebs.VolumeId})
ON CREATE SET vol.firstseen = timestamp()
SET vol.lastupdated = {update_tag}, vol.deleteontermination = em.Ebs.DeleteOnTermination
SET vol.lastupdated = {update_tag},
vol.deleteontermination = em.Ebs.DeleteOnTermination,
vol.snapshotid = vol.SnapshotId
WITH vol, em
MATCH (aa:AWSAccount{id: {AWS_ACCOUNT_ID}})
MERGE (aa)-[r:RESOURCE]->(vol)
Expand Down
4 changes: 2 additions & 2 deletions cartography/intel/aws/ec2/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_snapshots_in_use(neo4j_session: neo4j.Session, region: str, current_aws_
RETURN v.snapshotid as snapshot
"""
results = neo4j_session.run(query, AWS_ACCOUNT_ID=current_aws_account_id, Region=region)
return [r['snapshot'] for r in results]
return [r['snapshot'] for r in results if r['snapshot']]


@timeit
Expand Down Expand Up @@ -100,7 +100,7 @@ def load_snapshot_volume_relations(
UNWIND {snapshot_volumes_list} as volume
MERGE (v:EBSVolume{id: volume.VolumeId})
ON CREATE SET v.firstseen = timestamp()
SET v.lastupdated = {update_tag}
SET v.lastupdated = {update_tag}, v.snapshotid = volume.SnapshotId
WITH v, volume
MATCH (aa:AWSAccount{id: {AWS_ACCOUNT_ID}})
MERGE (aa)-[r:RESOURCE]->(v)
Expand Down

0 comments on commit 832b7fa

Please sign in to comment.