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.
After creating a user-defined docker network (docker network create dev-net
), I did the following:
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.
It turns out that there were two overlapping issues:
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')
Given the above, I suggest that the following changes should be made to the repo:
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too