Приложение Python / flask с sdk boto3 dynamo db

#html #flask #amazon-dynamodb #boto3

#HTML #flask #amazon-dynamodb #boto3

Вопрос:

Я запускаю приложение Python в Elastic Beanstalk для тестирования, подключаю приложение к DynamoDB и создаю таблицу. Приложение использует фреймворк Flask, html / css и boto3 sdk для подключения к dynamo

проблема в том, что я не могу показать детали таблицы на странице это приложение
это таблица из dynamo

код приложения

 import json

import boto3
from flask import Flask, render_template, request

application = Flask(__name__)


def conectar_dynamo():
    dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
    table = dynamodb.Table('posts')
    return table


def scan():
    table = conectar_dynamo()

    response = table.scan()
    data = response['Items']

    while 'LastEvaluatedKey' in response:
        response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
        data.extend(response['Items'])

    return data


def put_item(data):
    table = conectar_dynamo()

    table.put_item(
        Item={
            'id': data['id'],
            'content': data['content'],
            'title': data['title']
        }
    )
    return 'Concluido com sucesso!'


@application.route('/')
def index():
    return render_template('index.html')


@application.route('/consultar', methods=['GET'])
def consultar():
    return json.dumps(scan(), default=str)


@application.route('/incluir', methods=['POST'])
def incluir():
    body = request.json
    res = put_item(body)
    return res


if __name__ == '__main__':
    application.run(host='0.0.0.0', debug=False)
  

и index.html есть

 {% extends 'base.html' %}

    {% block content %}
        <h1>{% block title %} teste{% endblock %}</h1>
        {% for post in posts %}
            <a href="#">
                <h2>{{ post['title'] }}</h2>
            </a>
            <span class="badge badge-primary">{{ post['created'] }}</span>
            <hr>
        {% endfor %}
    {% endblock %}
  

и мой base.html есть

 <!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

    <title>{% block title %} {% endblock %}</title>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-light bg-light">
        <a class="navbar-brand" href="{{ url_for('index')}}">Barbosa's</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav">
            <li class="nav-item active">
                <a class="nav-link" href="#">Sobre</a>
            </li>
            </ul>
        </div>
    </nav>
    <div class="container">
        {% block content %} {% endblock %}
    </div>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X 965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH 8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM B07jRM" crossorigin="anonymous"></script>
  </body>
</html>
  

что я делаю не так?

Комментарии:

1. Настроили ли вы свой экземпляр EB с ролью для доступа к DdB?

2. Я не уверен, где я могу проверить эту функцию?