Deploy serverless containers onto the cloud from your command line
fargate is a command-line interface to deploy containers to AWS Fargate. Using fargate, developers can easily run containers as one-off tasks or managed, highly available services secured by free TLS certificates. It bundles the power of AWS including Amazon Elastic Container Service (ECS), Amazon Elastic Container Registry (ECR), Elastic Load Balancing, AWS Certificate Manager, Amazon CloudWatch Logs, and Amazon Route 53 into an easy-to-use CLI.
Tasks are one-time executions of your container. You can run a task with a public IP address from an image on Docker Hub in a single command:
$ fargate task run web --image nginx:latest [i] Running task web $ fargate task ps web ID IMAGE STATUS RUNNING IP CPU MEMORY 8c35747a-7c1c-4efe-b55a-8dfbc1108d82 nginx:latest Running 35s 22.214.171.124 256 512 $ curl -s http://126.96.36.199 | grep title <title>Welcome to nginx!</title>
If you omit the image flag, fargate will build and push the application in the current working directory to Amazon ECR:
$ fargate task run web [>] docker login --username AWS --password ******* 123456789012.dkr.ecr.us-east-1.amazonaws.com/web [>] docker build --tag 123456789012.dkr.ecr.us-east-1.amazonaws.com/web:20171227050818 . [>] docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/web:20171227050818 . li] Running task web
Services are managed containers that are restarted if a failure occurs. Like a task, you can deploy a service using either a pre-existing Docker container or build and push it using fargate.
$ fargate service create myapp [i] Created service myapp
Services can be placed behind either an HTTP/HTTPS or TCP load balancer to serve requests to multiple instances of your container from a single URL.
$ fargate lb create mylb --port 80 [i] Created load balancer mylb $ fargate service create myapp --lb mylb --port 80 [i] Created service myapp
Use fargate to either push images built separately via continuous integration by using the --image flag or build and push directly from your computer.
$ fargate service deploy myapp ... [i] Deployed 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:abcd1234 to service myapp
Containers running using AWS Fargate can range from a quarter of a vCPU to 4 vCPUs and from 0.5GB of RAM to 30GB. This command scales our containers to a single vCPU and 4GB of RAM:
$ fargate service update myapp --cpu 1024 --memory 4096 [i] Updated service myapp to 1024 CPU / 4096 MiB
Services can scale to any number of instances with a single command.
$ fargate service scale web +2 [i] Scaled service web to 3 $ fargate service ps web ID IMAGE STATUS RUNNING IP CPU MEMORY DEPLOYMENT 8c35747a-7c1c-4efe-b55a-8dfbc1108d82 nginx:latest Running 56s 188.8.131.52 256 512 1 0487456c-8dbe-49ff-b7e7-d772eee447af nginx:latest Running 56s 184.108.40.206 256 512 1 8c35747a-7c1c-4efe-b55a-8dfbc1108d82 nginx:latest Running 2h57m1s 220.127.116.11 256 512 1
Load balancers can use HTTPS ports secured by a TLS certificate for your domain or domains. Domains hosted in Amazon Route 53 can be automatically validated from fargate.
$ fargate certificate request *.somanymachines.com $ fargate certificate validate *.somanymachines.com $ fargate lb create mylb --port 443 --certificate *.somanymachines.com $ fargate service create myapp --lb mylb --port 80
HTTP/HTTPS load balancers can support multiple services and will route to them based upon defined rules that match either the path or hostname of the request. This allows you to run a single service or a dozen microservices behind a single load balancer.
$ fargate lb create mylb --port 80 $ fargate service create myapp --lb mylb --port 80 $ fargate service create myservice --lb mylb --port 80 --rule PATH=/myservice/* $ fargate service create myotherservice --lb mylb --port 80 --rule PATH=/myotherservice/*
fargate configures containers to log to Amazon CloudWatch Logs which allow you to view or follow a log in real-time. Tail logs using --follow or select a range of logs using start and end times expressed as durations (e.g. -1h, -1m30s or timestamps (e.g. 2017-12-12 15:00 EST)
$ fargate task logs myapp --follow --start "-15m" --filter "curl" fargate/web/0487456c-8dbe-49ff-b7e7-d772eee447af 172.31.41.97 - - [27/Dec/2017:05:32:17 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.21.3 (i386-portbld-freebsd8.1) libcurl/7.21.3 OpenSSL/0.9.8n zlib/1.2.3" "18.104.22.168" fargate/web/358c439f-0613-4d69-abe8-fe8b7a25f64e 172.31.4.10 - - [27/Dec/2017:05:32:19 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.21.3 (i386-portbld-freebsd8.1) libcurl/7.21.3 OpenSSL/0.9.8n zlib/1.2.3" "22.214.171.124" fargate/web/8c35747a-7c1c-4efe-b55a-8dfbc1108d82 172.31.53.143 - - [27/Dec/2017:05:32:18 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.21.3 (i386-portbld-freebsd8.1) libcurl/7.21.3 OpenSSL/0.9.8n zlib/1.2.3" "126.96.36.199"
If you're hosting your domain using Amazon Route 53, you can create an alias record to your load balancer in a single command:
$ fargate lb alias mylb app.somanymachines.com [i] Created alias record [app.somanymachines.com -> mylb-518172311.us-east-1.elb.amazonaws.com]