aws-ssm-tools icon indicating copy to clipboard operation
aws-ssm-tools copied to clipboard

Instance list cache

Open spanagiot opened this issue 3 years ago • 4 comments

The ssm resolver as it is implemented now needs to fetch all the instances from AWS in every connection attempt. I thought it would faster to store the response in a temporary location for caching to speed up consecutive requests.

The cache lasts for one day (RESOLVER_CACHE_DURATION) and there is a flag --update-cache that can be used to trigger a cache update.

spanagiot avatar Aug 26 '22 12:08 spanagiot

Hi, thanks for the PR. I don't want this to be the default behaviour, as it could be very confusing for users. If anything the cache should be an explicit argument (e.g. --use-cache, --update-cache and --cache-file) so that only people who need it can use it. Also the cache should be stored in the user local cache dir, e.g. ~/.cache/ssm-session. I believe that there's a library to figure out the actual location on different systems.

Also please check the latest release from the master branch to see if the speed has improved for you. We now no longer fetch all the records but instead only the active ones, it may help.

mludvig avatar Sep 16 '22 02:09 mludvig

Thank you for your feedback.

The reason I didn't use the ~/.cache location was the extra library that needed and I didn't know if that was ok. I'll add it and fix that.

I'll merge your changes to my branch and update the cache behaviour.

spanagiot avatar Sep 16 '22 14:09 spanagiot

Hi again, one more thing - the cache should probably be aware of the account id and region. It makes sense to cache the records for each acct-id+region pair.

mludvig avatar Sep 16 '22 21:09 mludvig

I made all the recommended changes, seems to work as requested now.

spanagiot avatar Sep 26 '22 14:09 spanagiot