Advanced Use of AWS CLI for 3DS OUTSCALE

By leveraging several AWS CLI aliases you can manipulate your OUTSCALE resources with ease. Here are a few examples you can start with:

You need to create the following file: ~/.aws/cli/alias

.aws/cli/alias
 [toplevel]
 # List all your instances running
 ls-vm=ec2 describe-instances \
     --filter Name=instance-state-name,Values=running \
     --query 'Reservations[].Instances[].{ID: InstanceId, VPC: VpcId, "Private IP": PrivateIpAddress, "Public IP": PublicIpAddress,Key: KeyName,Name: Tags[?Key==`Name`].Value |    [0],"Security Group": SecurityGroups[0].GroupId ,Type: InstanceType, Volumes: BlockDeviceMappings[0].Ebs.VolumeId}' \
     --output table
 # List all your volumes
 ls-volumes=ec2 describe-volumes \
     --query 'Volumes[].{VolumeId: VolumeId,State: State,Size: Size,Name: Tags[0].Value,AZ: AvailabilityZone}' \
     --output table
 # List all your snapshots
 ls-snapshots=ec2 describe-snapshots \
     --query 'Snapshots[].{SnapshotId: SnapshotId,Description: Description, VolumeId: VolumeId,Size: VolumeSize,Name: Tags[0].Value}' \
     --output table
 # List all security groups port ranges open to 0.0.0.0/0
 ls-open-ports=ec2 describe-security-groups \
   --filters Name=ip-permission.cidr,Values=0.0.0.0/0 \
   --query 'SecurityGroups[].{
     GroupName:GroupName,
     GroupId:GroupId,
     PortRanges:
       IpPermissions[?contains(IpRanges[].CidrIp, `0.0.0.0/0`)].[
         join(`:`, [IpProtocol, join(`-`, [to_string(FromPort), to_string(ToPort)])])
       ][]
   }' \
   --output text
AWS CLI command with alias
$ aws ls-vm --region eu-west-2
Output
--------------------------------------------------------------------------------------------------------------------------------------------
|                                                             DescribeInstances                                                            |
+------------+-------------------+----------+-----------+-------------+-----------------+-----------------+---------------+----------------+
|     ID     |        Key        |  Name    | Platform  | Private IP  |    Public IP    | Security Group  |     Type      |      VPC       |
+------------+-------------------+----------+-----------+-------------+-----------------+-----------------+---------------+----------------+
|  i-5f070bbd|  user-eu-west-2   |  Fedora  |  Linux    |  10.8.13.28 |  171.33.95.101  |  sg-20cc20e7    |  t2.medium    |  None          |
|  i-1e80fc41|  Bees             |  None    |  Linux    |  10.0.3.144 |  None           |  sg-175cc268    |  tinav4.c4r2  |  vpc-d6f90876  |
|  i-2a43891f|  Bees             |  None    |  Linux    |  10.0.3.181 |  None           |  sg-175cc268    |  tinav4.c4r2  |  vpc-d6f90876  |
|  i-052a86ef|  Bees             |  Bouncer |  Linux    |  10.0.1.21  |  171.33.120.213 |  sg-f9cd8117    |  c4.large     |  vpc-d6f90876  |
+------------+-------------------+----------+-----------+-------------+-----------------+-----------------+---------------+----------------+

If you want to leverage AWS CLI with the OUTSCALE Cloud without specifying the different endpoints every time, you should do as follow:

Ensure you update the endpoints when 3DS OUTSCALE releases new Regions and services. For more information, see About Regions and Subregions.

~/.aws/models/endpoints.json
{
  "partitions": [
    {
      "defaults": {
        "hostname": "{service}.{region}.{dnsSuffix}",
        "protocols": [
          "https"
        ],
        "signatureVersions": [
          "v4"
        ]
      },
      "dnsSuffix": "outscale.com",
      "partition": "osc",
      "partitionName": "Outscale",
      "regionRegex": "^(cloudgouv|us|eu|ap)\\-\\w+\\-\\d+$",
      "regions": {
        "eu-west-2": {
          "description": "EU (Paris)"
        },
        "cloudgouv-eu-west-1": {
          "description": "CloudGouv EU (Paris)"
        },
        "us-east-2": {
          "description": "US East (NY)"
        },
        "us-west-1": {
          "description": "US West (California)"
        },
        "ap-northeast-1": {
          "description": "Japan (Tokyo)"
        }
      },
      "services": {
        "ec2": {
          "endpoints": {
            "eu-west-2": {"hostname": "fcu.eu-west-2.outscale.com"},
            "cloudgouv-eu-west-1": {"hostname": "fcu.cloudgouv-eu-west-1.outscale.com"},
            "us-east-2": {"hostname": "fcu.us-east-2.outscale.com"},
            "us-west-1": {"hostname": "fcu.us-west-1.outscale.com"},
            "ap-northeast-1": {"hostname": "fcu.ap-northeast-1.outscale.com"}
          }
        },
       "elasticloadbalancing": {
          "endpoints": {
            "eu-west-2": {"hostname": "lbu.eu-west-2.outscale.com"},
            "cloudgouv-eu-west-1": {"hostname": "lbu.cloudgouv-eu-west-1.outscale.com"},
            "us-east-2": {"hostname": "lbu.us-east-2.outscale.com"},
            "us-west-1": {"hostname": "lbu.us-west-1.outscale.com"},
            "ap-northeast-1": {"hostname": "lbu.ap-northeast-1.outscale.com"}
          }
        },
        "iam": {
          "endpoints": {
            "eu-west-2": {"hostname": "eim.eu-west-2.outscale.com"},
            "cloudgouv-eu-west-1": {"hostname": "eim.cloudgouv-eu-west-1.outscale.com"},
            "us-east-2": {"hostname": "eim.us-east-2.outscale.com"},
            "us-west-1": {"hostname": "eim.us-west-1.outscale.com"},
            "ap-northeast-1": {"hostname": "eim.ap-northeast-1.outscale.com"}
          }
        },
        "directconnect": {
          "endpoints": {
            "eu-west-2": {"hostname": "directlink.eu-west-2.outscale.com"},
            "cloudgouv-eu-west-1": {"hostname": "directlink.cloudgouv-eu-west-1.outscale.com"},
            "us-east-2": {"hostname": "directlink.us-east-2.outscale.com"},
            "us-west-1": {"hostname": "directlink.us-west-1.outscale.com"}
          }
        },
        "s3": {
          "endpoints": {
            "eu-west-2": {"hostname": "oos.eu-west-2.outscale.com"},
            "cloudgouv-eu-west-1": {"hostname": "oos.cloudgouv-eu-west-1.outscale.com"},
            "us-east-2": {"hostname": "oos.us-east-2.outscale.com"},
            "us-west-1": {"hostname": "oos.us-west-1.outscale.com"}
          }
        }
      }
    }
  ],
  "version": 3
}

By using this new model, your AWS CLI commands will look like:

Before
aws ec2 describe-instances --instance-ids i-12345678 i-87654321 i-12348765 i-56784321 --endpoint https://fcu.eu-west-2.outscale.com
After
aws ec2 describe-instances --instance-ids i-12345678 i-87654321 i-12348765 i-56784321

You will need to use the parameter region to switch from a Region to another.

Related Page

AWS™ and Amazon Web Services™ are trademarks of Amazon Technologies, Inc or its affiliates in the United States and/or other countries.