Last active
April 12, 2024 08:20
-
-
Save zh4n7wm/6d777e126aae899856a6f94caa5f7abb to your computer and use it in GitHub Desktop.
list dataset records of aws cognito identity pool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
identity_pool_id = "us-east-1:xxxxx" | |
dataset_name = "dataset-name-xxx" | |
client_sync = boto3.client("cognito-sync") | |
client_identity = boto3.client("cognito-identity") | |
def get_dataset_detail(identity_id): | |
global identity_pool_id | |
global dataset_name | |
global client_sync | |
data = client_sync.list_records( | |
IdentityPoolId=identity_pool_id, | |
DatasetName=dataset_name, | |
IdentityId=identity_id, | |
) | |
if "Records" not in data: | |
return None | |
res = {} | |
for x in data["Records"]: | |
if "Key" not in x: | |
continue | |
res[x["Key"]] = x.get("Value") | |
return res | |
def main(): | |
global identity_pool_id | |
global client_identity | |
next_token = None | |
while True: | |
if next_token: | |
data = client_identity.list_identities( | |
IdentityPoolId=identity_pool_id, MaxResults=60 | |
) | |
else: | |
data = client_identity.list_identities( | |
IdentityPoolId=identity_pool_id, MaxResults=60 | |
) | |
if "NextToken" in data: | |
next_token = data["NextToken"] | |
if not data or "Identities" not in data: | |
break | |
for x in data["Identities"]: | |
identity_id = x["IdentityId"] | |
detail = get_dataset_detail(identity_id) | |
res = {"identity_id": identity_id, "records": detail} | |
print(f"{res}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment