FEA-Bench / testbed /aws-powertools__powertools-lambda-python /tests /e2e /utils /data_fetcher /idempotency.py
| import boto3 | |
| from retry import retry | |
| def get_ddb_idempotency_record( | |
| function_name: str, | |
| table_name: str, | |
| ) -> int: | |
| """_summary_ | |
| Parameters | |
| ---------- | |
| function_name : str | |
| Name of Lambda function to fetch dynamodb record | |
| table_name : str | |
| Name of DynamoDB table | |
| Returns | |
| ------- | |
| int | |
| Count of records found | |
| Raises | |
| ------ | |
| ValueError | |
| When no record is found within retry window | |
| """ | |
| ddb_client = boto3.resource("dynamodb") | |
| table = ddb_client.Table(table_name) | |
| ret = table.scan( | |
| FilterExpression="contains (id, :functionName)", | |
| ExpressionAttributeValues={":functionName": f"{function_name}#"}, | |
| ) | |
| if not ret["Items"]: | |
| raise ValueError("Empty response from DynamoDB Repeating...") | |
| return ret["Count"] | |