Skip to content

Instantly share code, notes, and snippets.

Last active February 22, 2020 10:39
What would you like to do?
from chalice import Chalice
import boto3
from boto3.dynamodb.conditions import Key
app = Chalice(app_name='blog-demo')
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table('blog-demo-1')
@app.route('/', methods=['GET'])
def index():
response = table.scan()
data = response.get('Items', None)
return {'data': data}
@app.route('/item/{id}', methods=['GET'])
def item_get(id):
response = table.query(
data = response.get('Items', None)
return {'data': data}
@app.route('/item', methods=['POST'])
def item_set():
data = app.current_request.json_body
"id": data['id'],
"text": data['text']
return {'message': 'ok', 'status': 201, "id": data['id']}
except Exception as e:
return {'message': str(e)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment