Run nginx + express with fargate 4 core

--Packing nginx + express into fargate --Connect using unix socket --express launches 4 processes --Because the pattern that node cluster is not used, socket conflicts. --Set api1.sock on common volume --api4.sock and upstream from nginx

api

Set the common volume to Volume

VOLUME /usr/src/tmp

Have the sock path specified by an environment variable

main.js



const sock = process.env.SOCK_PATH;
app.listen(sock, () => {
  fs.chmodSync(sock, '666');
  console.log(`Server running on ${sock} with pid ` + process.pid);
});
  

nginx

api1.sock --upstream to api4.sock

nginx.conf


upstream api {
    server unix:///usr/src/tmp/api_1.sock;
    server unix:///usr/src/tmp/api_2.sock;
    server unix:///usr/src/tmp/api_3.sock;
    server unix:///usr/src/tmp/api_4.sock;
}
server {
    listen       80 default;
    listen  [::]:80;

    location / {
        proxy_pass http://api;       
        break;
    }
}

Task definition

Connect with ECS task definition

task-define.json


{
"containerDefinitions": [
  {
    "name": "nginx",
    "portMappings": [
      { "hostPort": 80, "protocol": "tcp", "containerPort": 80 }
    ],
    "mountPoints": [
      {
        "readOnly": true,
        "containerPath": "/usr/src/tmp",
        "sourceVolume": "etc"
      }
    ]
  },
  {
    "name": "api1",
    "mountPoints": [
      { "containerPath": "/usr/src/tmp", "sourceVolume": "etc" }
    ],
    "environment": [
      { "name": "SOCK_PATH", "value": "/usr/src/tmp/api_1.sock" }
    ]
  },
  {
    "name": "api2",
    "mountPoints": [
      { "containerPath": "/usr/src/tmp", "sourceVolume": "etc" }
    ],
    "environment": [
      { "name": "SOCK_PATH", "value": "/usr/src/tmp/api_2.sock" }
    ]
  },
  {
    "name": "api3",
    "mountPoints": [
      { "containerPath": "/usr/src/tmp", "sourceVolume": "etc" }
    ],
    "environment": [
      { "name": "SOCK_PATH", "value": "/usr/src/tmp/api_3.sock" }
    ]
  },
  {
    "name": "api4",
    "mountPoints": [
      { "containerPath": "/usr/src/tmp", "sourceVolume": "etc" }
    ],
    "environment": [
      { "name": "SOCK_PATH", "value": "/usr/src/tmp/api_4.sock" }
    ]
  }
],
"volumes": [{ "name": "etc" }],
}

Recommended Posts

Run nginx + express with fargate 4 core
Run TAO Core with Docker
Run Pico with docker
Run Payara with Docker
Clogged with Express npm install
Run batch with docker-compose with Java batch
[Rails] Express polymorphic with graphql-ruby
Run Tensorflow with THETA V
Run LIFF with Spring Boot
Run chromium-mir-kiosk on Ubuntu Core
Run Rails whenever with docker
Run Java VM with WebAssembly