Skip to content

Commit

Permalink
updated stackql notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyaven committed Nov 20, 2024
1 parent 01089d2 commit 6fe7502
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions notebooks/stackql.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,20 @@
"outputs": [],
"source": [
"%%stackql\n",
"SELECT instanceState, COUNT(*) as num_instances \n",
"FROM aws.ec2.instances \n",
"WHERE region = '$region' GROUP BY instanceState"
"SELECT\n",
"JSON_EXTRACT(state, '$$.Name') as instance_state, COUNT(*) as num_instances\n",
"FROM aws.ec2.instances\n",
"WHERE region = '$region'\n",
"GROUP BY instance_state"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"_.plot(kind='bar', title='Instances by State', x='instance_state', y='num_instances')"
]
},
{
Expand All @@ -88,12 +99,18 @@
"source": [
"%%stackql\n",
"SELECT \n",
"JSON_EXTRACT(Properties, '$$.BucketName') as BucketName,\n",
"JSON_EXTRACT(Properties, '$$.Tags') as Tags\n",
"FROM aws.cloud_control.resources \n",
"WHERE region = '$region' \n",
"AND data__TypeName = 'AWS::S3::Bucket' \n",
"AND data__Identifier = 'stackql-trial-bucket-01'"
"bucket_name,\n",
"json_extract(tag, '$$.Key') as key,\n",
"json_extract(tag, '$$.Value') as value \n",
"FROM \n",
"(\n",
"SELECT\n",
"bucket_name,\n",
"json_each.value as tag\n",
"FROM aws.s3.buckets, json_each(tags)\n",
"WHERE region = '$region'\n",
"AND data__Identifier = 'stackql-trial-bucket-01'\n",
")t"
]
}
],
Expand Down

0 comments on commit 6fe7502

Please sign in to comment.