【问题标题】:How to use fixture when testing Serverless locally with FastAPI?使用 FastAPI 在本地测试 Serverless 时如何使用夹具?
【发布时间】:2022-06-23 20:58:27
【问题描述】:

我正在测试一些用 FastAPI 编写的端点。我使用 pytest 和我编写的夹具中的 dynamoDB 表为命令和查询编写了测试,并且它可以工作。

但是,现在我想使用示例 test_event.json(我需要 requestContext 字段)和命令来测试端点:

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

我收到以下错误:

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

所以,显然 DynamoDB 表没有加载。 有人知道在这种情况下如何使用这些装置吗?

【问题讨论】:

    标签: aws-lambda amazon-dynamodb fastapi serverless fixtures


    【解决方案1】:

    通过查看错误,函数中似乎有一个针对名为“GS1PK-GS1SK-index”的索引的 DynamoDB 请求。该索引不存在,因此请求失败。您需要确保针对正确表上的现有索引。

    【讨论】:

      猜你喜欢
      • 2020-06-27
      • 1970-01-01
      • 2011-01-17
      • 2015-09-12
      • 1970-01-01
      • 1970-01-01
      • 2015-05-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多