All Projects → lebinh → Aq

lebinh / Aq

Licence: mit
Query AWS resources with SQL

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Aq

Zip It And Ship It
Intelligently prepare Node.js Lambda functions for deployment
Stars: ✭ 104 (-45.26%)
Mutual labels:  aws, cli
Vs Deploy
Visual Studio Code extension that provides commands to deploy files of a workspace to a destination.
Stars: ✭ 123 (-35.26%)
Mutual labels:  aws, sql
Linchpin
ansible based multicloud orchestrator
Stars: ✭ 107 (-43.68%)
Mutual labels:  aws, cli
Torchlambda
Lightweight tool to deploy PyTorch models to AWS Lambda
Stars: ✭ 83 (-56.32%)
Mutual labels:  aws, cli
Aws Nuke
Nuke a whole AWS account and delete all its resources.
Stars: ✭ 2,333 (+1127.89%)
Mutual labels:  aws, cli
Cloudquery
cloudquery transforms your cloud infrastructure into SQL or Graph database for easy monitoring, governance and security.
Stars: ✭ 1,300 (+584.21%)
Mutual labels:  aws, sql
Npdynamodb
A Node.js Simple Query Builder and ORM for AWS DynamoDB
Stars: ✭ 113 (-40.53%)
Mutual labels:  aws, sql
Cognitocurl
🦉🤖Easily sign curl calls to API Gateway with Cognito authorization token.
Stars: ✭ 76 (-60%)
Mutual labels:  aws, cli
Developer Handbook
An opinionated guide on how to become a professional Web/Mobile App Developer.
Stars: ✭ 1,830 (+863.16%)
Mutual labels:  aws, sql
Vscode Deploy Reloaded
Recoded version of Visual Studio Code extension 'vs-deploy', which provides commands to deploy files to one or more destinations.
Stars: ✭ 129 (-32.11%)
Mutual labels:  aws, sql
Pg activity
pg_activity is a top like application for PostgreSQL server activity monitoring.
Stars: ✭ 1,232 (+548.42%)
Mutual labels:  cli, sql
Bitcoin Etl
ETL scripts for Bitcoin, Litecoin, Dash, Zcash, Doge, Bitcoin Cash. Available in Google BigQuery https://goo.gl/oY5BCQ
Stars: ✭ 174 (-8.42%)
Mutual labels:  aws, sql
Sql
MySQL & PostgreSQL pipe
Stars: ✭ 81 (-57.37%)
Mutual labels:  cli, sql
Aws Cli Cheatsheet
☁️ AWS CLI + JQ = Make life easier
Stars: ✭ 94 (-50.53%)
Mutual labels:  aws, cli
Batchit
simple jobs submission via command-line for AWS batch
Stars: ✭ 77 (-59.47%)
Mutual labels:  aws, cli
Athena Express
athena-express makes it easier to execute SQL queries on Amazon Athena by chaining together a bunch of methods in the AWS SDK. This allows you to execute SQL queries AND fetch JSON results in the same synchronous call - well suited for web applications.
Stars: ✭ 111 (-41.58%)
Mutual labels:  aws, sql
Locopy
locopy: Loading/Unloading to Redshift and Snowflake using Python.
Stars: ✭ 73 (-61.58%)
Mutual labels:  aws, sql
Devops Resources
DevOps resources - Linux, Jenkins, AWS, SRE, Prometheus, Docker, Python, Ansible, Git, Kubernetes, Terraform, OpenStack, SQL, NoSQL, Azure, GCP
Stars: ✭ 1,194 (+528.42%)
Mutual labels:  aws, sql
Dynein
DynamoDB CLI written in Rust.
Stars: ✭ 126 (-33.68%)
Mutual labels:  aws, cli
Fselect
Find files with SQL-like queries
Stars: ✭ 3,103 (+1533.16%)
Mutual labels:  cli, sql

================================= aq - Query AWS resources with SQL

aq allows you to query your AWS resources (EC2 instances, S3 buckets, etc.) with plain SQL.

.. image:: https://travis-ci.org/lebinh/aq.svg?branch=master :target: https://travis-ci.org/lebinh/aq

.. image:: https://asciinema.org/a/79468.png :target: https://asciinema.org/a/79468

But why?

Fun, mostly fun. But see sample queries below for useful queries that can be performed with aq.

Usage

::

    Usage:
        aq [--profile=<profile>] [--region=<region>] [--table-cache-ttl=<seconds>] [-v] [--debug]
        aq [--profile=<profile>] [--region=<region>] [--table-cache-ttl=<seconds>] [-v] [--debug] <query>

    Options:
        --profile=<profile>  Use a specific profile from your credential file
        --region=<region>  The region to use. Overrides config/env settings
        --table-cache-ttl=<seconds>  number of seconds to cache the tables
                                     before we update them from AWS again [default: 300]
        -v, --verbose  enable verbose logging

Running ``aq`` without specifying any query will start a REPL to run your queries interactively.

Sample queries

One of the most important benefit of being able to query which SQL is aggregation and join, which can be very complicated or even impossible to do with AWS CLI.

To count how many running instances per instance type

::

> SELECT instance_type, count(*) count
  FROM ec2_instances
  WHERE state->'Name' = 'running'
  GROUP BY instance_type
  ORDER BY count DESC
+-----------------+---------+
| instance_type   |   count |
|-----------------+---------|
| m4.2xlarge      |      15 |
| m4.xlarge       |       6 |
| r3.8xlarge      |       6 |
+-----------------+---------+

Find instances with largest attached EBS volumes size

::

> SELECT i.id, i.tags->'Name' name, count(v.id) vols, sum(v.size) size, sum(v.iops) iops
  FROM ec2_instances i
  JOIN ec2_volumes v ON v.attachments -> 0 -> 'InstanceId' = i.id
  GROUP BY i.id
  ORDER BY size DESC
  LIMIT 3
+------------+-----------+--------+--------+--------+
| id         | name      |   vols |   size |   iops |
|------------+-----------+--------+--------+--------|
| i-12345678 | foo       |      4 |   2000 |   4500 |
| i-12345679 | bar       |      2 |    332 |   1000 |
| i-12345687 | blah      |      1 |    320 |    960 |
+------------+-----------+--------+--------+--------+

Find instances that allows access to port 22 in their security groups

::

> SELECT i.id, i.tags->'Name' name, sg.group_name
  FROM ec2_instances i
  JOIN ec2_security_groups sg ON instr(i.security_groups, sg.id)
  WHERE instr(sg.ip_permissions, '"ToPort": 22,')
+------------+-----------+---------------------+
| id         | name      | group_name          |
|------------+-----------+---------------------|
| i-foobar78 | foobar    | launch-wizard-1     |
| i-foobar87 | blah      | launch-wizard-2     |
+------------+-----------+---------------------+

AWS Credential


``aq`` relies on ``boto3`` for AWS API access so all the
`credential configuration mechanisms <https://boto3.readthedocs.io/en/latest/guide/quickstart.html>`_
of boto3 will work. If you are using the AWS CLI then you can use ``aq`` without any further configurations.

Available tables

AWS resources are specified as table names in <resource>_<collection> format with:

resource one of the resources <https://boto3.readthedocs.io/en/latest/guide/resources.html>_ defined in boto3: ec2, s3, iam, etc. collection one of the resource's collections <https://boto3.readthedocs.io/en/latest/guide/collections.html>_ defined in boto3: instances, images, etc.

An optional schema (i.e. database) name can be used to specify the AWS region to query. If you don't specify the schema name then boto's default region will be used.

::

-- to count the number of ec2 instances in AWS Singapore region
SELECT count(*) FROM ap_southeast_1.ec2_instances

Note that the region name is specified using underscore (ap_southeast_1) instead of dash (ap-southeast-1).

At the moment the full table list for AWS us_east_1 region is

.. list-table::

    • cloudformation_stacks
    • cloudwatch_alarms
    • cloudwatch_metrics
    • dynamodb_tables
    • ec2_classic_addresses
    • ec2_dhcp_options_sets
    • ec2_images
    • ec2_instances
    • ec2_internet_gateways
    • ec2_key_pairs
    • ec2_network_acls
    • ec2_network_interfaces
    • ec2_placement_groups
    • ec2_route_tables
    • ec2_security_groups
    • ec2_snapshots
    • ec2_subnets
    • ec2_volumes
    • ec2_vpc_addresses
    • ec2_vpc_peering_connections
    • ec2_vpcs
    • glacier_vaults
    • iam_groups
    • iam_instance_profiles
    • iam_policies
    • iam_roles
    • iam_saml_providers
    • iam_server_certificates
    • iam_users
    • iam_virtual_mfa_devices
    • opsworks_stacks
    • s3_buckets
    • sns_platform_applications
    • sns_subscriptions
    • sns_topics
    • sqs_queues

Query with structured value


Quite a number of resource contain structured value (e.g. instance tags) that cannot be use directly in SQL.
We keep and present these values as JSON serialized string and add a new operator ``->`` to make querying on them easier.
The ``->`` (replaced to ``json_get`` before execution) can be used to access an object field, ``object->'fieldName'``, or access
an array item, ``array->index``::

    > SELECT '{"foo": "bar"}' -> 'foo'
    +-------------------------------------+
    | json_get('{"foo": "bar"}', 'foo')   |
    |-------------------------------------|
    | bar                                 |
    +-------------------------------------+
    > SELECT '["foo", "bar", "blah"]' -> 1
    +--------------+
    | json_get('   |
    |--------------|
    | bar          |
    +--------------+

Install
~~~~~~~
::

    pip install aq

Tests (with `nose`)
~~~~~~~~~~~~~~~~~~~
::

    nosetests
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].