Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boto3 1.26.117 ssm list_documents() not retrieving documents when filtered by tag #3679

Closed
b-ngu opened this issue Apr 21, 2023 · 2 comments
Closed
Assignees
Labels
pagination response-requested Waiting on additional information or feedback. ssm

Comments

@b-ngu
Copy link

b-ngu commented Apr 21, 2023

Describe the bug

boto3==1.26.117 ssm client list_documents() call is not filtering documents by tag

Expected Behavior

list_documents() should return documents when filtered by tag

Current Behavior

list_documents() appears to not find the document when filtered by tag, despite the document being tagged

Reproduction Steps

session = boto3.session.Session(profile_name="dev")
client = session.client("ssm")
response = client.list_documents(Filters=[
{
'Key': 'tag:Component',
'Values': ['core-directory-retrieve-groups-for-user']
}
])
logger.debug(pformat(response))

Output

response
'DocumentIdentifiers': [],
'NextToken': 'AAMAARqoT0YpDF0hNtKThpjLNC4mcm5RlQKIrnXPcq42yHoRAAAAAGRClb4FgM1VrH1s60MfZ76kjxBEovTFOytUnZTIziJSJ2olAEQgF2fM8U2D4PXjwYkV500dDQAENagCtkb+uDjZzhy0GBybhOtsHX35Jg8vVPQCYSu3cRsNp1zHhdyV+wTEi/oJF07DFXbQgnhfknssGjXHm6V5+R1BLA75TcVG+bax5CD5RIylYs4AEcJ0LeetUiIbxYbjB3bc8gQB6F+JWYm4sFWdP5JJhxW26AfiQgSof5EHBwMnWiK+BA3sGh67uppsnANedxukf2Cq88nl4X3nS8OUx39j79IvRsXkxg5e6QKOg4XSQhzjLJXVqxveWOb0eyhMzKztc/tpQ/0xs4AXKu2xVIXgfCF/DlC2199PXXYzJ3FtXsSAtyv7ICSnsxG9qlGBJqCtfhTK0TOUxpIRT7WNUh48so06bthaY3In1rqYur+p5Eh6irnVCjBAmscyhOKLt+DN+lk/2VMVu5BtEVuR3c5fdX1vkxiNR/KXo3/Q5EZLA0U0sOamZEftifpJe3L/XaqK5feElmgb+Ier9mrbS6PySQgKHc6Y90cVwWd7JxhyXldO1WugzDgtylUl3ywYmo9NewT2+0HpyiRGdI9GbhcbsW7Q1/HmJYdlUxXIME5EWdhA6H2vPbdQg34Uz/lEobhFh3Utr7L8I3ua1MEgSsB/mnwSYxBiBvcye5K79qDcwnmHipuPUMcnf6MloA2Y9i6+NZhpSBbL/z2OvylDSj3Y/CQNetoSRZTyecyfbcpFseETKXPOE6TsKtli9d0mHkh4CAJQqYtVDPBTg1bedK0J9g3LdwP7vE7CKKPC7EfxO03LeTd6kBUiN8abQO2Gg3zd5x8Agy9ww1R8XkQIjWKsaXhapWrAdbF+QC7/vmoIYCLsnx4dNkI5VGdEYpI9+tjqJ8KaO+9zue9REbS9/PIEY3AI839flpGkF2i8SBMef0rGkW48s+mwi5d0T8cJKKrcSe34D3CRvkpg',
'ResponseMetadata': {'HTTPHeaders': {'connection': 'keep-alive',
'content-length': '1081',
'content-type': 'application/x-amz-json-1.1',
'date': 'Fri, 21 Apr 2023 13:55:10 GMT',
'server': 'Server',
'x-amzn-requestid': '319ffb0b-ecbd-4f71-b3bf-249de47bf432'},
'HTTPStatusCode': 200,
'RequestId': '319ffb0b-ecbd-4f71-b3bf-249de47bf432',
'RetryAttempts': 0}}

Possible Solution

No response

Additional Information/Context

The AWS CLI is able to retrieve the documents by tag
aws --version
aws-cli/2.11.13 Python/3.11.3 Linux/5.15.90.1-microsoft-standard-WSL2 exe/x86_64.ubuntu.20 prompt/off

aws ssm list-documents --profile dev --filters Key=tag:Component,Values=core-directory-retrieve-groups-for-user

Output

{
"DocumentIdentifiers": [
{
"Name": "core-directory-retrieve-groups-for-user-Document-156PFmQlwgwp",
"CreatedDate": "2023-04-20T16:08:57.741000-06:00",
"Owner": "xxxxxxxxxxxx",
"PlatformTypes": [
"Windows",
"Linux"
],
"DocumentVersion": "1",
"DocumentType": "Command",
"SchemaVersion": "2.2",
"DocumentFormat": "YAML",
"TargetType": "/AWS::EC2::Instance",
"Tags": [
{
"Key": "App",
"Value": "directory"
},
{
"Key": "AppCode",
"Value": "ABC123"
},
{
"Key": "core-patch-environment",
"Value": "dev"
},
{
"Key": "Branch",
"Value": "dev"
},
{
"Key": "Portfolio",
"Value": "core"
},
{
"Key": "Environment",
"Value": "nonp"
},
{
"Key": "Component",
"Value": "core-directory-retrieve-groups-for-user"
},
{
"Key": "Name",
"Value": "core-directory-dev-core-directory-retrieve-groups-for-user"
}
]
}
]
}

SDK version used

1.26.117

Environment details (OS name and version, etc.)

Ubuntu 20.04.5 LTS (WSL on WIndows)

@b-ngu b-ngu added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Apr 21, 2023
@b-ngu b-ngu changed the title (short issue description) Boto3 1.26.117 list_documents() not retrieving documents when filtered by tag Apr 21, 2023
@b-ngu b-ngu changed the title Boto3 1.26.117 list_documents() not retrieving documents when filtered by tag Boto3 1.26.117 ssm list_documents() not retrieving documents when filtered by tag Apr 21, 2023
@tim-finnigan tim-finnigan self-assigned this Apr 21, 2023
@tim-finnigan
Copy link
Contributor

Hi @bn-sourced thanks for reaching out. Here is the list_documents documentation for reference. As noted there, you receive a NextToken in your response if there are additional results to return. The AWS CLI has a different pagination mechanism than boto3. There is a boto3 paginator you can use here: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm/paginator/ListDocuments.html, for example:

import boto3

client = boto3.client('ssm')
paginator = client.get_paginator('list_documents')

response_iterator = paginator.paginate(
    Filters=[
        {
            'Key': 'tag:Name',
            'Values': [
                'test',
            ]
        },
    ],
    PaginationConfig={
        'MaxItems': 50,
        'PageSize': 50
    }
)

for page in response_iterator:
    print(page['DocumentIdentifiers'])

Also here is the boto3 documentation on paginators: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/paginators.html

I hope that helps, please let us know if you have any follow up questions.

@tim-finnigan tim-finnigan added response-requested Waiting on additional information or feedback. pagination ssm and removed bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Apr 21, 2023
@b-ngu
Copy link
Author

b-ngu commented Apr 22, 2023

Thank you that helps!

@b-ngu b-ngu closed this as completed Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pagination response-requested Waiting on additional information or feedback. ssm
Projects
None yet
Development

No branches or pull requests

2 participants