I'm getting started with pynamodb (and dynamodb), and can't figure out how to use it.
I have:
- A dynamodb table
- A lambda
Running this code inside a lambda, I can successfully create two entries (I see them in the dynamodb Management Console):
class User(Model):
class Meta:
table_name = dynamodb_table_name
region = "eu-west-1"
email = UnicodeAttribute(hash_key=True)
first_name = UnicodeAttribute(null=False)
last_name = UnicodeAttribute(null=False)
User(email="[email protected]", first_name="John", last_name="Snow").save()
User(email="[email protected]", first_name="Daenerys", last_name="Targaryen").save()
I then attempt to retrieve one of these entries, running the following code:
class User(Model):
class Meta:
table_name = "dynamodb_table_name"
region = "eu-west-1"
email = UnicodeAttribute(hash_key=True)
first_name = UnicodeAttribute(null=False)
last_name = UnicodeAttribute(null=False)
print(User.count())
jon = User.get("[email protected]")
print(jon)
Here's the output I get:
0
dynamodb_table_name<None>
Questions:
- Why do
User.count()
returns zero, when I can clearly see two entries from the Management Console? - Why can't the user be retrieved from the DB?