|
15 | 15 | "metadata": {},
|
16 | 16 | "outputs": [],
|
17 | 17 | "source": [
|
18 |
| - "region = 'us-east-1'" |
| 18 | + "regions = \"'ap-southeast-2', 'us-east-1'\"\n", |
| 19 | + "region = 'ap-southeast-2'" |
19 | 20 | ]
|
20 | 21 | },
|
21 | 22 | {
|
|
29 | 30 | "split_part(instanceState, '\\n', 3) as instanceState, \n",
|
30 | 31 | "count(*) as num_instances\n",
|
31 | 32 | "FROM aws.ec2.instances \n",
|
32 |
| - "WHERE region = '$region' \n", |
| 33 | + "WHERE region IN ($regions)\n", |
33 | 34 | "GROUP BY split_part(instanceState, '\\n', 3)"
|
34 | 35 | ]
|
35 | 36 | },
|
|
49 | 50 | "outputs": [],
|
50 | 51 | "source": [
|
51 | 52 | "%%stackql\n",
|
52 |
| - "SELECT instanceType, COUNT(*) as num_instances \n", |
| 53 | + "SELECT region, instanceType, COUNT(*) as num_instances\n", |
53 | 54 | "FROM aws.ec2.instances\n",
|
54 |
| - "WHERE region = '$region'\n", |
| 55 | + "WHERE region IN ($regions)\n", |
55 | 56 | "GROUP BY instanceType"
|
56 | 57 | ]
|
57 | 58 | },
|
|
95 | 96 | "metadata": {},
|
96 | 97 | "outputs": [],
|
97 | 98 | "source": [
|
98 |
| - "# get multiple regions asynchronously\n", |
99 |
| - "from pystackql import StackQL\n", |
100 |
| - "stackql = StackQL(download_dir='/srv/stackql', output='pandas')\n", |
101 |
| - "stackql.executeStmt(\"REGISTRY PULL aws\")" |
| 99 | + "%%stackql\n", |
| 100 | + "select PolicyName, Arn from aws.iam.policies where region = '$region'" |
102 | 101 | ]
|
103 | 102 | },
|
104 | 103 | {
|
|
107 | 106 | "metadata": {},
|
108 | 107 | "outputs": [],
|
109 | 108 | "source": [
|
110 |
| - "# get multiple regions asynchronously\n", |
111 |
| - "import nest_asyncio, json\n", |
112 |
| - "nest_asyncio.apply()\n", |
113 |
| - "import pandas as pd\n", |
114 |
| - "\n", |
115 |
| - "regions = [\"ap-southeast-2\", \"us-east-1\"]\n", |
116 |
| - "\n", |
117 |
| - "queries = [\n", |
118 |
| - " f\"\"\"\n", |
119 |
| - " SELECT '{region}' as region, instanceType, COUNT(*) as num_instances\n", |
120 |
| - " FROM aws.ec2.instances\n", |
121 |
| - " WHERE region = '{region}'\n", |
122 |
| - " GROUP BY instanceType\n", |
123 |
| - " \"\"\"\n", |
124 |
| - " for region in regions\n", |
125 |
| - "]\n", |
126 |
| - "\n", |
127 |
| - "instances_df = await stackql.executeQueriesAsync(queries)\n", |
128 |
| - "instances_df" |
| 109 | + "%%stackql\n", |
| 110 | + "SELECT region, function_name\n", |
| 111 | + "FROM aws.lambda.functions\n", |
| 112 | + "WHERE region IN (\n", |
| 113 | + "'us-east-1',\n", |
| 114 | + "'us-east-2',\n", |
| 115 | + "'us-west-1',\n", |
| 116 | + "'us-west-2',\n", |
| 117 | + "'ap-south-1',\n", |
| 118 | + "'ap-northeast-3',\n", |
| 119 | + "'ap-northeast-2',\n", |
| 120 | + "'ap-southeast-1',\n", |
| 121 | + "'ap-southeast-2',\n", |
| 122 | + "'ap-northeast-1',\n", |
| 123 | + "'ca-central-1',\n", |
| 124 | + "'eu-central-1',\n", |
| 125 | + "'eu-west-1',\n", |
| 126 | + "'eu-west-2',\n", |
| 127 | + "'eu-west-3',\n", |
| 128 | + "'eu-north-1',\n", |
| 129 | + "'sa-east-1')" |
129 | 130 | ]
|
130 | 131 | },
|
131 | 132 | {
|
|
134 | 135 | "metadata": {},
|
135 | 136 | "outputs": [],
|
136 | 137 | "source": [
|
137 |
| - "%%stackql\n", |
138 |
| - "select PolicyName, Arn from aws.iam.policies where region = '$region'" |
| 138 | + "functions_list = _.to_dict(orient='records')" |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + "cell_type": "code", |
| 143 | + "execution_count": null, |
| 144 | + "metadata": {}, |
| 145 | + "outputs": [], |
| 146 | + "source": [ |
| 147 | + "from pystackql import StackQL\n", |
| 148 | + "stackql = StackQL(download_dir='/srv/stackql', app_root='/jupyter/.stackql', output='pandas')\n", |
| 149 | + "stackql.executeStmt(\"REGISTRY PULL aws\")" |
139 | 150 | ]
|
140 | 151 | },
|
141 | 152 | {
|
|
144 | 155 | "metadata": {},
|
145 | 156 | "outputs": [],
|
146 | 157 | "source": [
|
147 |
| - "import nest_asyncio, json\n", |
| 158 | + "# get all functions across all regions asynchronously using pystackql\n", |
| 159 | + "import nest_asyncio\n", |
148 | 160 | "nest_asyncio.apply()\n",
|
149 |
| - "import pandas as pd\n", |
150 |
| - "\n", |
151 |
| - "regions= [\"us-east-1\",\"us-east-2\",\"us-west-1\",\"us-west-2\",\"ap-south-1\",\"ap-northeast-3\",\"ap-northeast-2\",\"ap-southeast-1\",\n", |
152 |
| - " \"ap-southeast-2\",\"ap-northeast-1\",\"ca-central-1\",\"eu-central-1\",\"eu-west-1\",\"eu-west-2\",\"eu-west-3\",\"eu-north-1\",\n", |
153 |
| - " \"sa-east-1\"]\n", |
154 |
| - "\n", |
155 |
| - "get_fns = [\n", |
156 |
| - " f\"\"\"\n", |
157 |
| - " SELECT *\n", |
158 |
| - " FROM aws.lambda.functions\n", |
159 |
| - " WHERE region = '{region}'\n", |
160 |
| - " \"\"\"\n", |
161 |
| - " for region in regions\n", |
162 |
| - "]\n", |
163 |
| - "\n", |
164 |
| - "functions_df = await stackql.executeQueriesAsync(get_fns)\n", |
165 |
| - "functions_list = functions_df.to_dict(orient='records')\n", |
166 |
| - "\n", |
167 | 161 | "get_fns_details = [\n",
|
168 |
| - " f\"\"\"\n", |
| 162 | + " f'''\n", |
169 | 163 | " SELECT \n",
|
170 | 164 | " function_name,\n",
|
171 | 165 | " region,\n",
|
|
177 | 171 | " FROM aws.lambda.function\n",
|
178 | 172 | " WHERE region = '{function['region']}'\n",
|
179 | 173 | " AND data__Identifier = '{function['function_name']}'\n",
|
180 |
| - " \"\"\"\n", |
| 174 | + " '''\n", |
181 | 175 | " for function in functions_list\n",
|
182 | 176 | "]\n",
|
183 |
| - "\n", |
184 | 177 | "function_details_df = await stackql.executeQueriesAsync(get_fns_details)\n",
|
185 | 178 | "function_details_df"
|
186 | 179 | ]
|
| 180 | + }, |
| 181 | + { |
| 182 | + "cell_type": "code", |
| 183 | + "execution_count": null, |
| 184 | + "metadata": {}, |
| 185 | + "outputs": [], |
| 186 | + "source": [ |
| 187 | + "f" |
| 188 | + ] |
187 | 189 | }
|
188 | 190 | ],
|
189 | 191 | "metadata": {
|
|
0 commit comments