Skip to content

Instantly share code, notes, and snippets.

@DocX
Last active September 5, 2023 12:58
Show Gist options
  • Select an option

  • Save DocX/80e92f4c4c55d9ab6c4a to your computer and use it in GitHub Desktop.

Select an option

Save DocX/80e92f4c4c55d9ab6c4a to your computer and use it in GitHub Desktop.

Revisions

  1. DocX revised this gist Dec 10, 2015. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions ecs-console.sh
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,15 @@ CLUSTER=$1
    SERVICE=$2

    if [ -z "$CLUSTER" -o -z "$SERVICE" ]; then
    echo "Usage:"
    echo "ecs-console cluster-name service-name"
    exit 1
    fi

    TASK_ID=$( aws ecs list-tasks --cluster=$CLUSTER --service-name=$SERVICE | jq -r '.taskArns[0]' )
    CONTAINER_INSTANCE_ID=$( aws ecs describe-tasks --cluster=$CLUSTER --tasks $TASK_ID | jq -r '.tasks[0].containerInstanceArn' )
    EC2_INSTANCE=$( aws ecs describe-container-instances --cluster=staging --container-instances $CONTAINER_INSTANCE_ID | jq -r '.containerInstances[0].ec2InstanceId' )
    EC2_IP=$( aws ec2 describe-instances --instance-ids $EC2_INSTANCE | jq -r '.Reservations[0].Instances[0].PublicIpAddress' )
    TASK_ID=$( aws ecs list-tasks --cluster=$CLUSTER --service-name=$SERVICE --output json | jq -r '.taskArns[0]' )
    CONTAINER_INSTANCE_ID=$( aws ecs describe-tasks --cluster=$CLUSTER --tasks $TASK_ID --output json | jq -r '.tasks[0].containerInstanceArn' )
    EC2_INSTANCE=$( aws ecs describe-container-instances --cluster=staging --container-instances $CONTAINER_INSTANCE_ID --output json | jq -r '.containerInstances[0].ec2InstanceId' )
    EC2_IP=$( aws ec2 describe-instances --instance-ids $EC2_INSTANCE --output json | jq -r '.Reservations[0].Instances[0].PublicIpAddress' )

    echo Connecting to: $EC2_IP

  2. DocX revised this gist Nov 13, 2015. 2 changed files with 3 additions and 3 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ Requires

    Configure path to your ECS SSH key file ~/.bashrc

    echo 'ECS_PEM_FILE=$HOME/docker.pem' >> ~/.bashrc
    echo 'export ECS_PEM_FILE=$HOME/docker.pem' >> ~/.bashrc
    . ~/.bashrc

    Run
    4 changes: 2 additions & 2 deletions ecs-console.sh
    Original file line number Diff line number Diff line change
    @@ -10,10 +10,10 @@ fi

    TASK_ID=$( aws ecs list-tasks --cluster=$CLUSTER --service-name=$SERVICE | jq -r '.taskArns[0]' )
    CONTAINER_INSTANCE_ID=$( aws ecs describe-tasks --cluster=$CLUSTER --tasks $TASK_ID | jq -r '.tasks[0].containerInstanceArn' )
    EC2_INSTANCE=$( aws ecs describe-container-instances --cluster=staging --container-instances $CONTAINER_INSTANCE_ID | jq -r '.containerInstances[0].ec$
    EC2_INSTANCE=$( aws ecs describe-container-instances --cluster=staging --container-instances $CONTAINER_INSTANCE_ID | jq -r '.containerInstances[0].ec2InstanceId' )
    EC2_IP=$( aws ec2 describe-instances --instance-ids $EC2_INSTANCE | jq -r '.Reservations[0].Instances[0].PublicIpAddress' )

    echo Connecting to: $EC2_IP

    ssh -i $ECS_PEM_FILE ec2-user@$EC2_IP -t 'bash -c "docker exec -it $( docker ps -a -q -f name=ecs-'$SERVICE' | head -n 1 ) bash"'

  3. DocX revised this gist Nov 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ Requires
    - aws-cli - https://aws.amazon.com/cli/
    - jq - https://stedolan.github.io/jq/

    Configure path to your PEM file ~/.bashrc
    Configure path to your ECS SSH key file ~/.bashrc

    echo 'ECS_PEM_FILE=$HOME/docker.pem' >> ~/.bashrc
    . ~/.bashrc
  4. DocX revised this gist Nov 13, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@ Connect to ECS container
    ==

    Requires
    - aws-cli - https://aws.amazon.com/cli/
    - jq - https://stedolan.github.io/jq/

    Configure path to your PEM file ~/.bashrc
  5. DocX revised this gist Nov 13, 2015. 2 changed files with 6 additions and 1 deletion.
    5 changes: 5 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,11 @@ Connect to ECS container
    Requires
    - jq - https://stedolan.github.io/jq/

    Configure path to your PEM file ~/.bashrc

    echo 'ECS_PEM_FILE=$HOME/docker.pem' >> ~/.bashrc
    . ~/.bashrc

    Run

    ecs-console cluster-name service-name
    2 changes: 1 addition & 1 deletion ecs-console.sh
    Original file line number Diff line number Diff line change
    @@ -16,4 +16,4 @@ EC2_IP=$( aws ec2 describe-instances --instance-ids $EC2_INSTANCE | jq -r '.Rese
    echo Connecting to: $EC2_IP
    ssh -i $ECS_PEM_FILE ec2-user@$EC2_IP -t 'bash -c "docker exec -it $( docker ps -a -q -f name=ecs-'$SERVICE' ) bash"'
    ssh -i $ECS_PEM_FILE ec2-user@$EC2_IP -t 'bash -c "docker exec -it $( docker ps -a -q -f name=ecs-'$SERVICE' | head -n 1 ) bash"'
  6. DocX revised this gist Nov 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,4 @@ Requires

    Run

    ecs-console cluster-name service-name
    ecs-console cluster-name service-name
  7. DocX revised this gist Nov 13, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,5 @@ Requires
    - jq - https://stedolan.github.io/jq/

    Run

    ecs-console cluster-name service-name
  8. DocX revised this gist Nov 13, 2015. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,7 @@ Connect to ECS container
    ==

    Requires
    - jq - https://stedolan.github.io/jq/
    - jq - https://stedolan.github.io/jq/

    Run
    ecs-console cluster-name service-name
  9. DocX revised this gist Nov 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    Connect to ECS container
    =====
    ==

    Requires
    - jq - https://stedolan.github.io/jq/
  10. DocX revised this gist Nov 13, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    == Connect to ECS container ==
    Connect to ECS container
    =====

    Requires
    - jq - https://stedolan.github.io/jq/
  11. DocX revised this gist Nov 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    == ecs-console
    == Connect to ECS container ==

    Requires
    - jq - https://stedolan.github.io/jq/
  12. DocX revised this gist Nov 13, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    == ecs-console

    Requires
    - jq - https://stedolan.github.io/jq/
  13. DocX revised this gist Nov 13, 2015. No changes.
  14. DocX created this gist Nov 13, 2015.
    19 changes: 19 additions & 0 deletions ecs-console.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #!/bin/bash

    CLUSTER=$1
    SERVICE=$2

    if [ -z "$CLUSTER" -o -z "$SERVICE" ]; then
    echo "ecs-console cluster-name service-name"
    exit 1
    fi

    TASK_ID=$( aws ecs list-tasks --cluster=$CLUSTER --service-name=$SERVICE | jq -r '.taskArns[0]' )
    CONTAINER_INSTANCE_ID=$( aws ecs describe-tasks --cluster=$CLUSTER --tasks $TASK_ID | jq -r '.tasks[0].containerInstanceArn' )
    EC2_INSTANCE=$( aws ecs describe-container-instances --cluster=staging --container-instances $CONTAINER_INSTANCE_ID | jq -r '.containerInstances[0].ec$
    EC2_IP=$( aws ec2 describe-instances --instance-ids $EC2_INSTANCE | jq -r '.Reservations[0].Instances[0].PublicIpAddress' )
    echo Connecting to: $EC2_IP
    ssh -i $ECS_PEM_FILE ec2-user@$EC2_IP -t 'bash -c "docker exec -it $( docker ps -a -q -f name=ecs-'$SERVICE' ) bash"'