0

我正在用 Chalice 框架编写一个项目。我需要与 DynamoDB 交互,所以我想使用库来简化代码。我正在尝试使用 pynamodb,但我无法弄清楚我错过了什么。

应用程序.py

from chalice import Chalice
from chalicelib import AgentSkill

app = Chalice(app_name='helloworld2')

# this works
@app.route('/')
def index():
    return {'hello': 'world'}

# this throws error
@app.route('/skill')
def addSkill():
    f not AgentSkill.exists():
        AgentSkill.create_table(read_capacity_units=1,
                            write_capacity_units=1, wait=True)

    agsk = AgentSkill()
    agsk.agentID = 1
    agsk.save()
    return {'success': 'true'}

chalicelib/初始化.py

from .AgentSkill import AgentSkill

chalicelib/AgentSkill.py

from pynamodb.models import Model
from pynamodb.attributes import (UnicodeAttribute, NumberAttribute)

class AgentSkill(Model):
    class Meta:
        table_name = 'agent_skill'
        region = 'us-west-2'

    agentID =  NumberAttribute(hash_key=True)

要求.txt

pynamodb

有什么我遗漏的,还是我需要在 requirements.text 文件中添加一些内容?

如果在 requirements.txt 文件中没有 pynamodb,每次调用都会出现内部服务器错误。添加它后,我现在至少可以让 hello world 做出响应。/Skill 然后给出:

{
    "Code": "InternalServerError",
    "Message": "An internal server error occurred."
}

我不知道从这里去哪里?

4

0 回答 0