Eugene
Eugene

Reputation: 3375

AWS Systems Manager `GetParametersByPath` API returns outdated results

I am trying to utilize SSM's GetParametersByPath API and I am getting outdated results which looks like a ~3 seconds caching by Path parameter.

I am testing the following scenario:

  1. Get parameters by path recursively
  2. Put a parameter under the tested path
  3. Get parameters by path again using same arguments as in (1)

I am getting the same response in step (3) as in step (1) regardless of the changes in step (2).

I am thinking that this is related to caching because the following 2 scenarios work as expected.

Correct behavior scenario 1:

  1. Get parameters by path recursively
  2. Put a parameter under the tested path
  3. Sleep for 3 seconds
  4. Get parameters by path again using same parameters as in (1)

Correct behavior scenario 2:

  1. Put a parameter under the tested path
  2. Get parameters by path recursively

This behavior is consistent across different SDKs which I tried: .Net, Python (boto3) and CLI, so this is not an SKD issue.

Here is a code snippet in Python with boto3 that replicates incorrect behavior:

import boto3

client = boto3.client('ssm')

first = client.get_parameters_by_path(
    Path='/param-store-test/1',
    Recursive=True,
    WithDecryption=True,
    MaxResults=10)

print(first['Parameters'][0]['Version'] if first['Parameters'] else None)

put_response = client.put_parameter(
    Name='/param-store-test/1/2',
    Value='test',
    Type='SecureString',
    KeyId='alias/aws/ssm',
    Overwrite=True,
    Tier='Standard')

print("v{}".format(put_response['Version']))

second = client.get_parameters_by_path(
    Path='/param-store-test/1',
    Recursive=True,
    WithDecryption=True,
    MaxResults=10)

print(second['Parameters'][0]['Version'] if second['Parameters'] else None)

This code gives me the following output when run for the first time:

None
v1
None

And when run for the second time:

1
v2
1

You can see the pattern - the first request is being cached.

According to API docs: Request results are returned on a best-effort basis. So is this behavior considered to be correct? Does this mean that I don't have any way to get all parameters by path in a reliable way?

Upvotes: 4

Views: 5929

Answers (1)

MikeW
MikeW

Reputation: 6110

I have noticed that get_parameters_by_path() does not work as I expected.

You might think that (simplified code):

put_parameter('/abc/def', "123")
get_parameters_by_path('/abc/def')

would return "123", whereas it seems to return [] nothing.

However,

get_parameter('/abc/def')

correctly returns "123".

Also,

get_parameters_by_path('/abc')

will return '/abc/def' => "123"

So it seems to work, but not quite as one might expect.

Upvotes: 1

Related Questions