0

I have am writing a project with the Chalice framework. I need to interact with DynamoDB so I wanted to use library to simplify the code. I am attempting to use pynamodb and I cannot figure out what I am missing.

app.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/init.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)

requirements.txt

pynamodb

Is there something I am missing, or do I need to add something to the requirements.text file?

Without having pynamodb in the requirements.txt file I would get an internal server error for every call. With it added, I can now at least get the hello world to respond. /Skill then gives :

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

I am not sure where to go from here?

  • Could be a policy issue, run this command `chalice gen-policy` on your project folder and see if you have right permission to create DynamoDB tables. – ozbey Oct 06 '17 at 13:41
  • Your first step should be to get details on the exception causing the error. You'll want to understand how to view log/print output for your Lambda function in CloudWatch logs. – dmulter Aug 14 '18 at 23:00

0 Answers0