Skip to content

Commit 8fa8664

Browse files
committed
Added dynamodb
1 parent c06460a commit 8fa8664

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
from flask import Flask, render_template
2+
3+
from pynamodb.models import Model
4+
from pynamodb.attributes import UnicodeAttribute
5+
26
app = Flask(__name__)
37

8+
class OneTable(Model):
9+
'''
10+
DynamoDB works best with a single table. This table. Use this table to model
11+
other data requests.
12+
'''
13+
class Meta:
14+
table_name = os.environ['DYNAMODB_TABLE_NAME']
15+
16+
pk = UnicodeAttribute(hash_key=True)
17+
sk = UnicodeAttribute(range_key=True)
18+
419
@app.route("/")
520
def cats():
621
return render_template('index.html')

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pytest
22
Flask
3-
requests
3+
requests
4+
pynamodb

serverless.yml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ provider:
66
region: us-west-2
77
deploymentBucket:
88
name: infra.opszero.com
9-
# environment:
10-
# DYNAMODB_TABLE_NAME: <service_name>-${sls:stage}
9+
environment:
10+
DYNAMODB_TABLE_NAME: ${self:service}}-${sls:stage}
1111
httpApi:
1212
cors: true
1313
# iamRoleStatements:
@@ -66,25 +66,25 @@ package:
6666
patterns:
6767
- '!node_modules/**'
6868

69-
# resources:
70-
# Resources:
71-
# oneTable:
72-
# Type: AWS::DynamoDB::Table
73-
# Properties:
74-
# TableName: <service_name>-${sls:stage}
75-
# AttributeDefinitions:
76-
# - AttributeName: pk
77-
# AttributeType: S
78-
# - AttributeName: sk
79-
# AttributeType: S
80-
# KeySchema:
81-
# - AttributeName: pk
82-
# KeyType: HASH
83-
# - AttributeName: sk
84-
# KeyType: RANGE
85-
# ProvisionedThroughput:
86-
# ReadCapacityUnits: 3
87-
# WriteCapacityUnits: 3
69+
resources:
70+
Resources:
71+
oneTable:
72+
Type: AWS::DynamoDB::Table
73+
Properties:
74+
TableName: ${self:service}-${sls:stage}
75+
AttributeDefinitions:
76+
- AttributeName: pk
77+
AttributeType: S
78+
- AttributeName: sk
79+
AttributeType: S
80+
KeySchema:
81+
- AttributeName: pk
82+
KeyType: HASH
83+
- AttributeName: sk
84+
KeyType: RANGE
85+
ProvisionedThroughput:
86+
ReadCapacityUnits: 1
87+
WriteCapacityUnits: 1
8888
# s3bucket:
8989
# Type: AWS::S3::Bucket
9090
# Properties:

0 commit comments

Comments
 (0)