I am new to Docker with multiple containers running. I have 2 services that I need to spin up namely lambda and my api-test app to run test cases in the container.
This is my docker-compose.yml
version: '3.8'
services:
lambda:
build:
context: ../
dockerfile: Dockerfile
ports:
- "9000:8080"
api-test:
build:
context: ./api-test
dockerfile: Dockerfile
ports:
- "8080:8080"
depends_on:
- lambda
My api-test app is not able to connect to lambda (localhost:9000 ) when i try to initiate http request. I’ve confirmed my lambda is up, only the api-test app not able to start successfully.
Getting error:
[RequestError: connect ECONNREFUSED 127.0.0.1:9000]
My Dockerfile:
FROM node:20-alpine
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
CMD ["npm", "test"]
In my index.test.ts, I have this code that generates the error
const sendEventToLambda = async (event: LambdaEvent) => {
try {
return await got
.post(lambdaUrl, {
body: JSON.stringify(event),
timeout: {
request: 50000,
},
})
.json();
} catch (e) {
return e;
}
};
Is there anything that I missed? Any help is much appreciated, thank you so much!
1