Random CS Student
Random CS Student

Reputation: 21

How to use fixture when testing Serverless locally with FastAPI?

I am testing a few endpoints written with FastAPI. I wrote tests for commands and queries using pytest with a dynamoDB table from a fixture that I had written, and it works.

However, now that I want to test the endpoints with an example test_event.json (I need the requestContext field) with the command:

serverless invoke local --function API --path test_event.json

I get the following error:

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the Query operation: The table does not have the specified index: GS1PK-GS1SK-index

So, obviously the DynamoDB table was not loaded. Anyone has an idea how to use the fixtures in this case?

Upvotes: 0

Views: 297

Answers (1)

shaunfaz
shaunfaz

Reputation: 36

By looking at the error it seems there is a DynamoDB request in the function that targets an index called "GS1PK-GS1SK-index". This index does not exist so the request is failing. You need to ensure you are targeting an existing index on the correct table.

Upvotes: 0

Related Questions