Menu
Amazon EC2 Container Service
Developer Guide (API Version 2014-11-13)

HTTP Proxy Configuration

If you need to configure your Amazon ECS container agent to use an HTTP proxy, you may do so by setting the following variables in the /etc/ecs/ecs.config file at launch time (with Amazon EC2 user data), or you can manually edit the configuration file and restart the agent afterwards:

HTTP_PROXY=10.0.0.131:3128

Set this value to the hostname (or IP address) and port number of an HTTP proxy to use for the ECS agent to connect to the Internet (for example, if your container instances do not have external network access through an Amazon VPC Internet gateway or NAT gateway or instance).

NO_PROXY=169.254.169.254,169.254.170.2,/var/run/docker.sock

Set this value to 169.254.169.254,169.254.170.2,/var/run/docker.sock to filter EC2 instance metadata, IAM roles for tasks, and Docker daemon traffic from the proxy.

The above variable only affect the Amazon ECS container agent; they do not configure Docker or any other services (such as yum) to use the proxy.

Example HTTP proxy user data script

The example user data cloud-boothook script below configures the Amazon ECS container agent, the Docker daemon, and yum to use an HTTP proxy that you specify. You can also specify a cluster name that the container instance will register itself into.

To use this script when you launch a container instance, follow the steps in Launching an Amazon ECS Container Instance, and in Step 10, copy and paste the cloud-boothook script below into the User data field (be sure to substitute the red example values with your own proxy and cluster information).

Copy
#cloud-boothook # Configure Yum, the Docker daemon, and the ECS agent to use an HTTP proxy # Specify proxy host, port number, and ECS cluster name to use PROXY_HOST=10.0.0.131 PROXY_PORT=3128 CLUSTER_NAME=proxy-test # Set Yum HTTP proxy if [ ! -f /var/lib/cloud/instance/sem/config_yum_http_proxy ]; then echo "proxy=http://$PROXY_HOST:$PROXY_PORT" >> /etc/yum.conf echo "$$: $(date +%s.%N | cut -b1-13)" > /var/lib/cloud/instance/sem/config_yum_http_proxy fi # Set Docker HTTP proxy if [ ! -f /var/lib/cloud/instance/sem/config_docker_http_proxy ]; then echo "export HTTP_PROXY=http://$PROXY_HOST:$PROXY_PORT/" >> /etc/sysconfig/docker echo "$$: $(date +%s.%N | cut -b1-13)" > /var/lib/cloud/instance/sem/config_docker_http_proxy fi # Set ECS agent HTTP proxy if [ ! -f /var/lib/cloud/instance/sem/config_ecs-agent_http_proxy ]; then echo "ECS_CLUSTER=$CLUSTER_NAME" >> /etc/ecs/ecs.config echo "HTTP_PROXY=$PROXY_HOST:$PROXY_PORT" >> /etc/ecs/ecs.config echo "NO_PROXY=169.254.169.254,169.254.170.2,/var/run/docker.sock" >> /etc/ecs/ecs.config echo "$$: $(date +%s.%N | cut -b1-13)" > /var/lib/cloud/instance/sem/config_ecs-agent_http_proxy fi