-
-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Hi,
I have just spent over the day fixing an issue where the local-data-api is being called from another docker container rather than localhost (in this case, I was using SAM to invoke a local lambda container but the situation applies more generally). While this is no a bug with this repo, I think that the repo would benefit from a few small additions / extra clarification.
The Problem
After creating a user-defined docker network (docker network create dev-net), I did the following:
- I used the following postgres docker compose file below (exactly the same as in the README with the addition of a docker network)
- Set up a test table in the database
- Ensured that the lambda container was being launched in this same network
version: '3.1'
services:
local-data-api:
image: koxudaxi/local-data-api
container_name: api
networks:
- dev-net
restart: always
environment:
ENGINE: PostgreSQLJDBC
POSTGRES_HOST: db
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: example
RESOURCE_ARN: 'arn:aws:rds:us-east-1:123456789012:cluster:dummy'
SECRET_ARN: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:dummy'
ports:
- "8080:80"
db:
image: postgres:10.7-alpine
container_name: db
networks:
- dev-net
restart: always
environment:
POSTGRES_PASSWORD: example
POSTGRES_DB: test
ports:
- "5432:5432"
networks:
dev-net:
external: true
I tried to connect to the local-data-api with the following command, with a similar command to that in the README:
rds_client = boto3.client('rds-data', endpoint_url='http://local_local-data-api_1:8080', aws_access_key_id='aaa', aws_secret_access_key='bbb')
with local_local-data-api_1 being the automatically generated name for the api container in the docker compose.
The Solution
It turns out that there were two overlapping issues:
- the URL above is invalid because it has an underscore
- port 8080 sees to be already used so cannot be referred to in the lambda container
I solved this by explicitly naming the containers in the docker compose file as follows:
version: '3.1'
services:
local-data-api:
image: koxudaxi/local-data-api
container_name: api
networks:
- dev-net
restart: always
environment:
ENGINE: PostgreSQLJDBC
POSTGRES_HOST: db
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: example
RESOURCE_ARN: 'arn:aws:rds:us-east-1:123456789012:cluster:dummy'
SECRET_ARN: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:dummy'
ports:
- "8080:80"
db:
image: postgres:10.7-alpine
container_name: db
networks:
- dev-net
restart: always
environment:
POSTGRES_PASSWORD: example
POSTGRES_DB: test
ports:
- "5432:5432"
networks:
dev-net:
external: true
When calling the database from the lambda container, I also switched to port 80, which seemed to work, as follows:
rds_client = boto3.client('rds-data', endpoint_url='http://api:80', aws_access_key_id='aaa', aws_secret_access_key='bbb')
Suggestion
Given the above, I suggest that the following changes should be made to the repo:
- The docker compose files in the repo should explicitly name the containers such that no underscores are generated when they are created
- An extra section should be added to the README to discuss this issue, in particular the required switch to port 80 (unless a fix can be found to switch to 8080)