0

I have been attempting to follow the various instructions and troubleshooting to get a docker container to connect to another docker container running local dynamodb via boto3. References/troubleshooting so far:

Dockerfile (docker build -t min-example:latest .):

FROM python:3.8

RUN pip install boto3

RUN mkdir /app
COPY min_example.py /app
WORKDIR /app

Docker compose (min-example.yml):

version: "3.3"

services:

  db:
    container_name: db
    image: amazon/dynamodb-local
    ports:
      - "8000:8000"

  app:
    image: min-example:latest
    container_name: app
    depends_on:
      - db

min_example.py

import boto3


if __name__ == '__main__':
    ddb = boto3.resource('dynamodb',
                         endpoint_url='http://db:8000',
                         region_name='dummy',
                         aws_access_key_id='dummy',
                         aws_secret_access_key='dummy')
    existing_tables = [t.name for t in list(ddb.tables.all())]
    print(existing_tables)
    existing_tables = [t.name for t in list(ddb.tables.all())]
    print(existing_tables)

Run with

docker-compose run -f min-example.yml app python min_example.py

It hangs on the ddb.tables.all() call, and times out with the error:

botocore.exceptions.ReadTimeoutError: Read timeout on endpoint URL: "http://db:8000/"

Interestingly, I can curl:

docker-compose -f min-example.yml run app curl http://db:8000/

{"__type":"com.amazonaws.dynamodb.v20120810#MissingAuthenticationToken","message":"Request must contain either a valid (registered) AWS access key ID or X.509 certificate."}

Which suggests the containers can communicate.

Hanshan
  • 3,656
  • 5
  • 29
  • 36
  • 1
    What happens when you run `docker-compose up` instead of the individual run commands? – Robert Hafner Nov 25 '20 at 05:54
  • Interesting, looks like dynamo image throwing this error: "ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console..." – Hanshan Nov 25 '20 at 06:09
  • Confirmed amazon/dynamodb image is up to date with the latest. – Hanshan Nov 25 '20 at 06:12
  • The error might not be a problem: https://stackoverflow.com/questions/64549078/dynamodb-local-error-statuslogger-log4j2-could-not-find-a-logging-implementatio. Indeed, I can now see that **the script completes successfully**. Why is `run` not working?! – Hanshan Nov 25 '20 at 06:16

0 Answers0