1 Answer
- Newest
- Most votes
- Most comments
0
Hi, you can define multiple container definitions in your task definition. For example. the following task definition (in YAML) has an Apache HTTP Server container on port 80 and a Node.js Application Server container on port 3000.
Resources: TaskDefinition: Type: AWS::ECS::TaskDefinition Properties: Family: Fn::Sub: ${AWS::StackName}-TaskDefinition Cpu: 256 Memory: 512 NetworkMode: awsvpc RequiresCompatibilities: - FARGATE RuntimePlatform: OperatingSystemFamily: LINUX ExecutionRoleArn: Fn::GetAtt: ECSExecutionRole.Arn TaskRoleArn: Fn::GetAtt: ECSTaskRole.Arn ContainerDefinitions: - Name: httpd Image: httpd:latest Command: - /bin/sh - -c - | cat <<EOF > /usr/local/apache2/htdocs/index.html <h1>It works!</h1> <p>Your container hostname is `hostname`.</p> EOF sed -i \ -e 's/^#\(LoadModule .*mod_proxy_http.so\)/\1/' \ -e 's/^#\(LoadModule .*mod_proxy.so\)/\1/' \ conf/httpd.conf cat <<\EOF >> conf/httpd.conf <IfModule proxy_module> Include conf/extra/proxy.conf </IfModule> EOF cat <<\EOF >> conf/extra/proxy.conf ProxyPass "/proxy" "http://localhost:3000/" ProxyPassReverse "/proxy" "http://localhost:3000/" EOF apt update -y && apt install -y curl httpd-foreground Essential: true PortMappings: - ContainerPort: 80 HostPort: 80 Protocol: tcp LogConfiguration: LogDriver: awslogs Options: awslogs-region: Ref: AWS::Region awslogs-group: Ref: ECSLogGroup awslogs-stream-prefix: httpd HealthCheck: Command: - CMD-SHELL - curl -f http://localhost || exit 1 StartPeriod: 30 - Name: node Image: node:latest Command: - /bin/sh - -c - | cat <<\EOF > main.js const http = require("http"); const hostname = "0.0.0.0"; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader("Content-Type", "text/html"); res.end("<h1>Hello World!</h1>\n"); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); }); EOF node main.js LogConfiguration: LogDriver: awslogs Options: awslogs-region: Ref: AWS::Region awslogs-group: Ref: ECSLogGroup awslogs-stream-prefix: node HealthCheck: Command: - CMD-SHELL - curl -f http://localhost:3000 || exit 1 StartPeriod: 30
For detailed reference about task definition, read the following documentations.
answered 7 months ago
Relevant content
- asked 3 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago