2
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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.