Not able to call ecs service when service-connect enabled

0

Hello

I am trying to launch 2 ecs services (go containers). I called these services as firstservice and secondservice. I have enabled client service-connect on first service and client and server service-connect on second service. I am making a http request from first service to second service every 5 sec but every request is throwing an error

client: response body: upstream request timeout and status 504 Gateway Timeout

Code for first service

func loop() {
	for true {
		requestURL := "http://secondservice:8082"
		resp, err := http.Get(requestURL)
		if err != nil {
			fmt.Printf("error making http request: %s\n", err)
		} else {
			resBody, err := io.ReadAll(resp.Body)
			if err != nil {
				fmt.Printf("client: could not read response body: %s\n", err)
				os.Exit(1)
			}
			fmt.Printf("client: response body: %s and status %s\n", resBody, resp.Status)
		}

		time.Sleep(5 * time.Second)
	}
}

func main() {

	logger = log.New(os.Stdout, "MyApp: ", log.LstdFlags|log.Lshortfile)

	http.HandleFunc("/", handler)
	go loop()
	logger.Println("Running basic service")
	logger.Fatal(http.ListenAndServe(":8080", nil))
}

docker file for first service

FROM golang:1.20 AS build-stage

# Set destination for COPY
WORKDIR /app

# Download Go modules
COPY go.mod ./
RUN go mod download

# Copy the source code. Note the slash at the end, as explained in
# https://docs.docker.com/engine/reference/builder/#copy
COPY *.go ./

# Build
RUN CGO_ENABLED=0 GOOS=linux go build -o /firstservice

FROM gcr.io/distroless/base-debian11 AS build-release-stage

WORKDIR /

COPY --from=build-stage /firstservice /firstservice

EXPOSE 8080

USER nonroot:nonroot

ENTRYPOINT ["/firstservice"]

code for second service

func handler(w http.ResponseWriter, r *http.Request) {
	_, err := fmt.Fprintf(w, "Hi there, I know that!")
	logger.Println("request received ok bye")
	if err != nil {
		return
	}
}

func health(w http.ResponseWriter, r *http.Request) {
	logger.Println("health request received ok bye")
	w.WriteHeader(http.StatusOK)
	_, err := fmt.Fprintf(w, "OK")
	if err != nil {
		return
	}
}

func main() {

	logger = log.New(os.Stdout, "MyApp: ", log.LstdFlags|log.Lshortfile)

	http.HandleFunc("/", handler)
	http.HandleFunc("/health", health)
	logger.Println("Running basic service")
	logger.Fatal(http.ListenAndServe(":8082", nil))
}

Docker file for second service

FROM golang:1.20 AS build-stage

# Set destination for COPY
WORKDIR /app

# Download Go modules
COPY go.mod ./
RUN go mod download

# Copy the source code. Note the slash at the end, as explained in
# https://docs.docker.com/engine/reference/builder/#copy
COPY *.go ./

# Build
RUN CGO_ENABLED=0 GOOS=linux go build -o /secondservice

FROM gcr.io/distroless/base-debian11 AS build-release-stage

WORKDIR /

COPY --from=build-stage /secondservice /secondservice

EXPOSE 8082

USER nonroot:nonroot

ENTRYPOINT ["/secondservice"]

here is service connect config for second service

service connect

similar i have enabled for firstservice

Can you please help i am not sure what i am missing here

gefragt vor 3 Monaten230 Aufrufe
1 Antwort
0

issue is solved for me. I did not have any outbound rules for security group of these ecs services

beantwortet vor 3 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen