I want to deploy two containers into an ECS cluster, one gets called with HTTP from outside, and then it calls the other container, also via HTTP.
const cluster = new ecs.Cluster(this, "mycluster", {});
cluster.addDefaultCloudMapNamespace({ name: "local" });
new ecsPatterns.ApplicationLoadBalancedFargateService(this, "abc", {
cluster,
taskImageOptions: {
containerPort: 8000,
image: ecs.ContainerImage.fromRegistry("my/abc-image:latest"),
},
});
const xyztask = new ecs.FargateTaskDefinition(this, "xyztask");
const xyz = xyztask.addContainer("xyzcontainer", {
image: ecs.ContainerImage.fromRegistry("my/xyz-image:latest"),
});
xyz.addPortMappings({ containerPort: 8000 });
new ecs.FargateService(this, "xyz", {
cluster,
taskDefinition: xyztask,
cloudMapOptions: { name: "xyz" },
});
The abc service looks like this:
const axios = require("axios");
const bodyParser = require("body-parser");
const express = require("express");
const app = express();
app.use(bodyParser.json());
app.post("/", async ({ body: { x } }, response) => {
response.end(JSON.stringify({ x }));
await axios.post(
`http://xyz.local:8000/`,
{ x },
{ timeout: 3000 }
);
});
app.listen(8000);
The xyz service looks like this:
const axios = require("axios");
const bodyParser = require("body-parser");
const express = require("express");
const app = express();
app.use(bodyParser.json());
app.post("/", async ({ body: { x } }, response) => {
response.end();
});
app.listen(8000);
The abc service is available from the outside, but somehow the request to xyz always fails.