AWS SSM SDK缓存DescribeParametersCommand的结果是为了提高性能。但是在一些情况下,这可能会导致问题,例如当参数列表动态变化时,缓存的结果可能已经过时。
要避免缓存问题,可以使用以下方法:
aws ssm describe-parameters --no-cli-pager
import boto3 from botocore.config import Config
config = Config( retries = dict( max_attempts = 10 ) )
ssm = boto3.client('ssm', config=config)
response = ssm.describe_parameters( NoCache=True )
import boto3 from botocore.cache import MemoryCache
cache = MemoryCache()
ssm = boto3.client('ssm') ssm.meta.events.register('before-call', cache.add_to_cache) ssm.meta.events.register('after-call', cache.add_to_cache)
response1 = ssm.describe_parameters() response2 = ssm.describe_parameters()
assert response1 is response2
请注意,如果参数在缓存超时之前发生更改,则缓存的结果将变为无效。如果需要及时更新结果,请考虑使用适当的缓存超时时间。