mlevit / aws-auto-cleanup

Programmatically delete AWS resources based on an allowlist and time to live (TTL) settings
MIT License
496 stars 55 forks source link

Security groups added to the whitelist showing blank action in execution log when it should say "SKIP - WHITELIST" #91

Closed atqhg23 closed 2 years ago

atqhg23 commented 2 years ago

Describe the bug When a security group is added to the whitelist, the action in the execution log is blank.

To Reproduce

  1. Add a security group to the whitelist
  2. Run the cleanup with dry-run on/off
  3. Check the execution log action for the security group added to the whitelist
  4. The action appear blank

Expected behavior The execution log action should say "SKIP - WHITELIST"

AWS (please complete the following information):

mlevit commented 2 years ago

Can you please test https://github.com/servian/aws-auto-cleanup/tree/security-group-fix

atqhg23 commented 2 years ago

For sure, thanks, I will test this in the morning (EST where I'm at) and will send an update.

atqhg23 commented 2 years ago

When there are no security groups in the whitelist, the cleanup runs successfully, but this error comes up when there is a security group in the whitelist:

[ERROR] TypeError: unhashable type: 'dict'
Traceback (most recent call last):
  File "/var/task/src/main.py", line 608, in lambda_handler
    cleanup.run_cleanup()
  File "/opt/python/func_timeout/dafunc.py", line 185, in <lambda>
    return wraps(func)(lambda *args, **kwargs : func_timeout(defaultTimeout, func, args=args, kwargs=kwargs))
  File "/opt/python/func_timeout/dafunc.py", line 108, in func_timeout
    raise_exception(exception)
  File "/opt/python/func_timeout/py3_raise.py", line 7, in raise_exception
    raise exception[0] from None
  File "/var/task/src/main.py", line 316, in run_cleanup
    ec2_class.run()
  File "/var/task/src/ec2_cleanup.py", line 47, in run
    self.security_groups()
  File "/var/task/src/ec2_cleanup.py", line 377, in security_groups
    if resource not in resource_whitelist:
mlevit commented 2 years ago

Issue fixed. Was comparing the wrong variable against the whitelist :)

atqhg23 commented 2 years ago

Ah I missed that, will test to confirm

atqhg23 commented 2 years ago

Apologies for the late response. I just tested this and everything works