1 Answer
2
You should first check the items have those keys before using them:
for item in items:
if all(key in item for key in ("username", "Win", "Lose", "Score")):
if item['username'] and item['Win'] and item['Lose'] and item['Score']:
answered 2 months ago
Relevant content
- asked a month ago
- asked 8 months ago
- Accepted Answerasked 9 months ago
- Accepted Answerasked 2 years ago
- AWS OFFICIALUpdated 2 days ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 4 months ago
Thank you for replying :-)
Ended up doing it another way:
import boto3
dynamodb = boto3.resource('dynamodb') table = dynamodb.Table('INSERT DATABASE NAME HERE')
def lambda_handler(event, context): users = table.scan()['Items'] filtered_users = [] for user in users: if user.get('Win') or user.get('Lose') or user.get('Score'): filtered_users.append({ 'username': user.get('username'), 'Win': user.get('Win'), 'Lose': user.get('Lose'), 'Score': user.get('Score') }) return filtered_users