Robert
Robert

Reputation: 3483

Flask Dynamo connection issue(AttributeError: 'Dynamo' object has no attribute 'tables')

from flask import Flask
from flask_dynamo import Dynamo
import os
os.environ['AWS_ACCESS_KEY_ID'] = ''
os.environ['AWS_SECRET_ACCESS_KEY'] = ''
os.environ['AWS_REGION'] = 'ap-south-1'
app = Flask(__name__)
app.config['DYNAMO_TABLES'] = [
{
    'TableName': 'users',
    'KeySchema': [dict(AttributeName='username', KeyType='HASH')],
    'AttributeDefinitions': [dict(AttributeName='username', AttributeType='S')],
    'ProvisionedThroughput': dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
}, {
     'TableName': 'groups',
    'KeySchema': [dict(AttributeName='name', KeyType='HASH')],
    'AttributeDefinitions': [dict(AttributeName='name', AttributeType='S')],
    'ProvisionedThroughput': dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
}
      ]
app.config['DYNAMO_ENABLE_LOCAL'] = True
app.config['DYNAMO_LOCAL_HOST'] = 'localhost'
app.config['DYNAMO_LOCAL_PORT'] = 9000
dynamo = Dynamo()

The table configuration for flask-dynamo has been defined and dynamo instance created,when i try to get the create all tables get error of builtins.AttributeError AttributeError: 'Dynamo' object has no attribute 'tables'

@app.route('/', methods=['GET'])
def hello_world():
    with app.app_context():
        dynamo.create_all()
    return 'table created!'

environment

python3 flask-dynamo

Thanks in advance

Upvotes: 2

Views: 579

Answers (1)

Mekicha
Mekicha

Reputation: 851

This line:

dynamo = Dynamo()

should be:

dynamo = Dynamo(app)

That way, the dynamo instance can access the tables and other configurations you defined on the app object.

Upvotes: 1

Related Questions