If you don't want to scan (and maybe you shouldn't), you will need to create a GSI (Global Secondary Index) for that, and set event_status
as the GSIPK.
so your table config will be:
table = dynamodb.create_table(
TableName="your_table",
KeySchema=[
{"AttributeName": "event_id", "KeyType": "HASH"}, # Partition key
{"AttributeName": "event_status", "KeyType": "RANGE"}, # Sort key
],
AttributeDefinitions=[
{"AttributeName": "event_id, "AttributeType": "S"},
{"AttributeName": "event_status", "AttributeType": "S"},
{"AttributeName": "gsi_event_status", "AttributeType": "S"},
{"AttributeName": "gsi_event_id", "AttributeType": "S"},
],
GlobalSecondaryIndexes=[
{
"IndexName": "gsiIndex",
"KeySchema": [
{"AttributeName": "gsi_event_status", "KeyType": "HASH"},
{"AttributeName": "gsi_event_id", "KeyType": "RANGE"},
],
"Projection": {"ProjectionType": "ALL"},
},
],
BillingMode="PAY_PER_REQUEST",
)
Be mindful that GSIs can be expensive and you might wanna change the ProjectionType if you don't need all attributes.
Now you can query by pk:
table.query(KeyConditionExpression=Key('event_id').eq(event_id))
or by the GSI PK which is set to your sk:
lookup.query(
IndexName="gsiIndex",
KeyConditionExpression=Key("gsi_event_status").eq(event_status),
)