File size: 177,366 Bytes
dcb5de4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 |
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended and usage information for Amazon Athena. The output will include detailed information about the resource id. The cost will be summed and in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
line_item_usage_type,
line_item_resource_id,
product_region,
line_item_product_code,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_product_code = 'AmazonAthena'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
line_item_usage_start_date,
line_item_usage_type,
line_item_resource_id,
product_region,
line_item_product_code
ORDER BY
sum_line_item_unblended_cost DESC
LIMIT 20;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended and usage information per linked account for AWS Glue. The output will include detailed information about the resource id (Glue Crawler) and API operation. The cost will be summed and in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
line_item_operation,
CASE
WHEN LOWER(line_item_operation) = 'jobrun' THEN SPLIT_PART(line_item_resource_id, 'job/', 2)
WHEN LOWER(line_item_operation) = 'crawlerrun' THEN SPLIT_PART(line_item_resource_id, 'crawler/', 2)
ELSE 'N/A'
END AS case_line_item_resource_id,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16, 8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = ('AWS Glue')
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_operation,
line_item_resource_id
ORDER BY
day_line_item_usage_start_date,
sum_line_item_usage_amount,
sum_line_item_unblended_cost;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended and usage information per linked account for each Kinesis product (Amazon Kinesis, Amazon Kinesis Firehose, and Amazon Kinesis Analytics). The output will include detailed information about the resource id (Stream, Delivery Stream, etc…) and API operation. The cost will be summed and in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
SPLIT_PART(line_item_resource_id,':',6) AS split_line_item_resource_id,
product_product_name,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16, 8))) AS sum_line_item_unblended_cost
FROM
${table_Name}
WHERE
${date_filter}
AND line_item_product_code LIKE '%Kinesis%'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_resource_id,
product_product_name
ORDER BY
day_line_item_usage_start_date,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended and amortized cost as well as usage information per linked account for Amazon Elasticsearch. The output will include detailed information about the resource id (ES Domain), usage type, and API operation. The usage amount and cost will be summed and the cost will be in descending order. This query includes RI and SP true up which will show any upfront fees to the account that purchased the pricing model.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
SPLIT_PART(line_item_resource_id,':',6) AS split_line_item_resource_id,
product_product_family,
product_instance_family,
product_instance_type,
pricing_term,
product_storage_media,
product_transfer_type,
SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN line_item_usage_amount
WHEN (line_item_line_item_type = 'DiscountedUsage') THEN line_item_usage_amount
WHEN (line_item_line_item_type = 'Usage') THEN line_item_usage_amount
ELSE 0
END) AS sum_line_item_usage_amount,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost,
SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN savings_plan_savings_plan_effective_cost
WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN (savings_plan_total_commitment_to_date - savings_plan_used_commitment)
WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0
WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN 0
WHEN (line_item_line_item_type = 'DiscountedUsage') THEN reservation_effective_cost
WHEN (line_item_line_item_type = 'RIFee') THEN (reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee)
WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN 0
ELSE line_item_unblended_cost
END) AS sum_amortized_cost,
SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN (-savings_plan_amortized_upfront_commitment_for_billing_period)
WHEN (line_item_line_item_type = 'RIFee') THEN (-reservation_amortized_upfront_fee_for_billing_period)
ELSE 0
END) AS sum_ri_sp_trueup,
SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN line_item_unblended_cost
WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN line_item_unblended_cost
ELSE 0
END) AS sum_ri_sp_upfront_fees
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name in ('Amazon Elasticsearch Service' ,'Amazon OpenSearch Service')
AND line_item_product_code = 'AmazonES'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
SPLIT_PART(line_item_resource_id,':',6),
product_product_family,
product_instance_family,
product_instance_type,
pricing_term,
product_storage_media,
product_transfer_type
ORDER BY
day_line_item_usage_start_date,
product_product_family,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended cost and usage information per linked account for Amazon EMR. The cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
SPLIT_PART(line_item_usage_type ,':',2) AS split_line_item_usage_type,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'Amazon Elastic MapReduce'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_usage_type,
line_item_line_item_type
ORDER BY
day_line_item_usage_start_date,
sum_line_item_usage_amount,
sum_line_item_unblended_cost DESC,
split_line_item_usage_type;
PROMPT: What SQL query corresponds to the following purpose: This query will provide monthly unblended and usage information per linked account for Amazon QuickSight. The output will include detailed information about the usage type and its usage amount. The cost will be summed and in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
CASE
WHEN LOWER(line_item_usage_type) LIKE 'qs-user-enterprise%' THEN 'Users - Enterprise'
WHEN LOWER(line_item_usage_type) LIKE 'qs-user-standard%' THEN 'Users - Standard'
WHEN LOWER(line_item_usage_type) LIKE 'qs-reader%' THEN 'Reader Usage'
WHEN LOWER(line_item_usage_type) LIKE '%spice' THEN 'SPICE'
WHEN LOWER(line_item_usage_type) LIKE '%alerts%' THEN 'Alerts'
ELSE line_item_usage_type
END AS case_line_item_usage_type,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'Amazon QuickSight'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
4 -- refers to case_line_item_usage_type
ORDER BY
month_line_item_usage_start_date,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide monthly unblended and usage information per linked account for all types of Amazon MSK, including OD and Serverless. The output will include detailed information about the usage type and its usage amount. The cost will be summed and in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
line_item_product_code,
line_item_line_item_description,
line_item_operation,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_product_code = 'AmazonMSK'
AND line_item_line_item_type NOT IN ('Tax','Refund','Credit')
GROUP BY 1,2,3,4,5
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended and amortized cost as well as usage information per linked account for Amazon MQ. The output will include detailed information about the resource id (broker), usage type, and API operation. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
product_broker_engine,
line_item_usage_type,
product_product_family,
pricing_unit,
pricing_term,
SPLIT_PART(line_item_usage_type, ':', 2) AS split_line_item_usage_type,
SPLIT_PART(line_item_resource_id, ':', 7) AS split_line_item_resource_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
line_item_operation,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'Amazon MQ'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
product_broker_engine,
product_product_family,
pricing_unit,
pricing_term,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_usage_type,
line_item_resource_id,
line_item_operation
ORDER BY
day_line_item_usage_start_date,
sum_line_item_unblended_cost DESC,
split_line_item_usage_type;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended and usage information per linked account for Amazon SES. The output will include detailed information about the product family (Sending Attachments, Data Transfer, etc…) and usage type. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
product_product_family,
CASE
WHEN line_item_usage_type LIKE '%%DataTransfer-In-Bytes%%' THEN 'Data Transfer GB (IN) '
WHEN line_item_usage_type LIKE '%%DataTransfer-Out-Bytes%%' THEN 'Data Transfer GB (Out)'
WHEN line_item_usage_type LIKE '%%AttachmentsSize-Bytes%%' THEN 'Attachments GB'
WHEN line_item_usage_type LIKE '%%Recipients' THEN 'Recipients'
WHEN line_item_usage_type LIKE '%%Recipients-EC2' THEN 'Recipients'
WHEN line_item_usage_type LIKE '%%Recipients-MailboxSim' THEN 'Recipients (MailboxSimulator)'
WHEN line_item_usage_type LIKE '%%Message%%' THEN 'Messages'
WHEN line_item_usage_type LIKE '%%ReceivedChunk%%' THEN 'Received Chunk'
ELSE 'Others'
END AS case_line_item_usage_type,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_Name}
WHERE
${date_filter}
AND product_product_name = 'Amazon Simple Email Service'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
product_product_family,
5 --refers to case_line_item_usage_type
ORDER BY
day_line_item_usage_start_date,
sum_line_item_usage_amount,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended cost and usage information per linked account for Amazon SNS. The output will include detailed information about the product family, API Operation, and usage type. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
CONCAT(product_product_family,' - ',line_item_operation) AS concat_product_product_family,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_Name}
WHERE
${date_filter}
AND product_product_name = 'Amazon Simple Notification Service'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
CONCAT(product_product_family,' - ',line_item_operation)
ORDER BY
day_line_item_usage_start_date,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide the top 20 daily unblended costs as well as usage information for a specified linked account for Amazon SQS. The output will include detailed information about the resource id (queue), usage type, and API operation. The cost will be summed and in descending order. This is helpful for tracking down spikes in cost for SQS usage. Cost Explorer will provide you all of this information except the resource ID. This allows your investigation to be targeted to a time range, linked account, API operation, and resource that is generating the usage.?
COMPLETION: SELECT
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
line_item_usage_type,
line_item_operation,
line_item_resource_id,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_Name}
WHERE
${date_filter}
AND line_item_product_code = 'AWSQueueService'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_usage_type,
line_item_operation,
line_item_resource_id
ORDER BY
sum_line_item_unblended_cost DESC
LIMIT 20;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended cost and usage information for Amazon SQS, grouped by account and operation. The operation is also grouped using product_product_family, which results in values such as “Data Transfer - Receive” and “API Request - SendMessageBatch”. Output is ordered by date, then by cost (descending). This can be used to identify specific API operations driving the most daily cost, which allows for targeted investigation into optimization opportunities.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
CONCAT(product_product_family,' - ',line_item_operation) AS concat_product_product_family,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}}
AND line_item_product_code = 'AWSQueueService'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
CONCAT(product_product_family,' - ',line_item_operation)
ORDER BY
day_line_item_usage_start_date,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides AWS Marketplace subscription costs including subscription product name, associated linked account, and monthly total unblended cost. This query includes tax, however this can be filtered out in the WHERE clause. Please refer to the CUR Query Library Helpers section for assistance. CUR Query Library Helpers section?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
CASE line_item_usage_start_date
WHEN NULL THEN DATE_FORMAT(DATE_PARSE(CONCAT(SPLIT_PART('${table_name}','_',5),'01'),'%Y%m%d'),'%Y-%m-01')
ELSE DATE_FORMAT(line_item_usage_start_date,'%Y-%m-01')
END AS case_line_item_usage_start_time,
bill_billing_entity,
product_product_name,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND bill_billing_entity = 'AWS Marketplace'
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
3, --refers to case_line_item_usage_start_time,
bill_billing_entity,
product_product_name
ORDER BY
case_line_item_usage_start_time ASC,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides a list of refunds and credits issued. Output is grouped by payer, linked account, month, line item type, service, and line item description. This allows for analysis of refunds and credits along any of these grouped dimensions. For example, “what refunds or credits were issued to account 111122223333 for service ABC in January 2022?” or “what was the total refund issued across all accounts for payer 444455556666 with line item description XYZ?”?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_TRUNC('month',line_item_usage_start_date) as month_line_item_usage_start_date,
line_item_line_item_type,
CASE
WHEN (bill_billing_entity = 'AWS Marketplace' AND line_item_line_item_type NOT LIKE '%Discount%') THEN product_product_name
WHEN (product_servicecode = '') THEN line_item_product_code
ELSE product_servicecode
END case_service,
line_item_line_item_description,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost
FROM
${tableName}
WHERE
${date_filter}
AND line_item_unblended_cost < 0
AND line_item_line_item_type <> 'SavingsPlanNegation'
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_TRUNC('month',line_item_usage_start_date),
line_item_line_item_type,
5, --refers to case_service
line_item_line_item_description
ORDER BY
month_line_item_usage_start_date ASC,
sum_line_item_unblended_cost ASC;
PROMPT: What SQL query corresponds to the following purpose: This query provides an aggregated report of savings from purchased reservations across multiple services - EC2, Elasticache, OpenSearch (formerly Amazon ElasticSearch), and RDS. This is similar to what can be found in Cost Explorer Reservation Utilization reports, except aggregated across all services offering reservations, allowing for easier organizational reporting on total savings. Output can be used to identify savings per specific reservation ARN, as well as savings per service, savings per linked account, savings per region, and savings per specific instance/node type.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
line_item_product_code,
reservation_reservation_a_r_n,
SPLIT_PART(line_item_usage_type,':', 2) AS split_line_item_usage_type,
SPLIT_PART(reservation_reservation_a_r_n,':', 4) AS split_product_region, -- split ARN for region due to product_region inconsistencies
SUM(CAST(pricing_public_on_demand_cost AS DECIMAL (16,8))) AS sum_pricing_public_on_demand_cost,
SUM(CASE
WHEN line_item_line_item_type = 'DiscountedUsage' THEN reservation_effective_cost
WHEN line_item_line_item_type = 'RIFee' THEN reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee
WHEN line_item_line_item_type = 'Fee' AND reservation_reservation_a_r_n <> '' THEN 0
END) AS sum_case_reservation_effective_cost,
SUM(TRY_CAST(pricing_public_on_demand_cost AS DECIMAL(16, 8)))
- SUM(CASE
WHEN line_item_line_item_type = 'DiscountedUsage' THEN reservation_effective_cost
WHEN line_item_line_item_type = 'RIFee' THEN reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee
WHEN line_item_line_item_type = 'Fee' AND reservation_reservation_a_r_n <> '' THEN 0
END) AS sum_case_reservation_net_savings
FROM
${table_name}
WHERE
${date_filter}
AND line_item_product_code IN ('AmazonEC2','AmazonRedshift','AmazonRDS','AmazonES','AmazonElastiCache')
AND line_item_line_item_type IN ('Fee','RIFee','DiscountedUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
line_item_product_code,
reservation_reservation_a_r_n,
SPLIT_PART(line_item_usage_type,':', 2),
SPLIT_PART(reservation_reservation_a_r_n,':', 4)
ORDER BY
month_line_item_usage_start_date,
line_item_product_code,
split_line_item_usage_type;
PROMPT: What SQL query corresponds to the following purpose: This query provides all rewarded Migration Acceleration Program (MAP) credits grouped by month, year, product credit source and account id. Default is for all time. A line is included as an example if a date filter is desired. Please refer to the CUR Query Library Helpers section for assistance. Migration Acceleration Program CUR Query Library Helpers section?
COMPLETION: select
month,
year,
line_item_line_item_type,
line_item_line_item_description,
line_item_usage_account_id,
sum(line_item_unblended_cost) sum_line_item_unblended_cost
from ${tableName}
where
line_item_line_item_type in ('Refund','Credit') and
line_item_line_item_description like '%_MPE%'
-- default is all MAP credits for the entire account for all time, add next line to filter
-- and ${date_filter}
group by 1,2,3,4,5;
PROMPT: What SQL query corresponds to the following purpose: This query pulls all ACTIVE Reserved Instance ARNs for Amazon EC2 and produces their utilization for last month. This query will give you a very granular look at which Reserved Instance purchases were not being utilized to their full extent last month. This query is written for Amazon EC2, however, commenting the line_item_product_code line in the WHERE clause will output all Reserved Instances.?
COMPLETION: -- EC2 Reservations active in current month ordered by expiration first
SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m') AS month_line_item_usage_start_date,
bill_bill_type,
line_item_product_code,
line_item_usage_type,
product_region,
reservation_subscription_id,
reservation_reservation_a_r_n,
pricing_purchase_option,
pricing_offering_class,
pricing_lease_contract_length,
reservation_number_of_reservations,
reservation_start_time,
reservation_end_time,
reservation_modification_status,
reservation_total_reserved_units,
reservation_unused_quantity,
TRY_CAST(1 - (TRY_CAST(reservation_unused_quantity AS Decimal(16,8)) / TRY_CAST(reservation_total_reserved_units AS Decimal(16,8))) as Decimal(16,8)) AS calc_percentage_utilized
FROM
${table_name}
WHERE
CAST("concat"("year", '-', "month", '-01') AS date) = "date_trunc"('month', current_date) - INTERVAL '1' MONTH --last month
AND pricing_term = 'Reserved'
AND line_item_line_item_type IN ('Fee','RIFee')
AND line_item_product_code = 'AmazonEC2' --EC2 only, comment out for all reservation types
AND bill_bill_type = 'Anniversary' --identify
AND try_cast(date_parse(SPLIT_PART(reservation_end_time, 'T', 1), '%Y-%m-%d') as date) > cast(current_date as date) --res exp time after today's date
GROUP BY
bill_bill_type,
bill_payer_account_id,
line_item_usage_account_id,
reservation_reservation_a_r_n,
reservation_subscription_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m'),
line_item_product_code,
line_item_usage_type,
product_region,
pricing_purchase_option,
pricing_offering_class,
pricing_lease_contract_length,
reservation_number_of_reservations,
reservation_start_time,
reservation_end_time,
reservation_modification_status,
reservation_total_reserved_units,
reservation_unused_quantity
ORDER BY
reservation_unused_quantity DESC,
reservation_end_time ASC,
calc_percentage_utilized ASC
PROMPT: What SQL query corresponds to the following purpose: This query pulls all ACTIVE Savings Plan ARNs and produces their utilization for last month. This query will give you a very granular look at which Savings Plan purchases were not being utilized to their full extent last month.?
COMPLETION: SELECT
SPLIT_PART(savings_plan_savings_plan_a_r_n, '/', 2) AS split_savings_plan_savings_plan_a_r_n,
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m') AS month_line_item_usage_start_date,
savings_plan_offering_type,
savings_plan_region,
DATE_FORMAT(FROM_ISO8601_TIMESTAMP(savings_plan_start_time),'%Y-%m-%d') AS day_savings_plan_start_time,
DATE_FORMAT(FROM_ISO8601_TIMESTAMP(savings_plan_end_time),'%Y-%m-%d') AS day_savings_plan_end_time,
savings_plan_payment_option,
savings_plan_purchase_term,
SUM(TRY_CAST(savings_plan_recurring_commitment_for_billing_period AS DECIMAL(16, 8))) AS sum_savings_plan_recurring_committment_for_billing_period,
SUM(TRY_CAST(savings_plan_total_commitment_to_date AS DECIMAL(16, 8))) AS sum_savings_plan_total_commitment_to_date,
SUM(TRY_CAST(savings_plan_used_commitment AS DECIMAL(16, 8))) AS sum_savings_plan_used_commitment,
AVG(CASE
WHEN line_item_line_item_type = 'SavingsPlanRecurringFee' THEN TRY_CAST(savings_plan_total_commitment_to_date AS DECIMAL(8, 2))
END) AS "Hourly Commitment",
-- (used commitment / total commitment) * 100 = utilization %
TRY_CAST(((SUM(TRY_CAST(savings_plan_used_commitment AS DECIMAL(16, 8))) / SUM(TRY_CAST(savings_plan_total_commitment_to_date AS DECIMAL(16, 8))))) AS DECIMAL(16, 8)) AS calc_savings_plan_utilization_percent
FROM
${table_name}
WHERE
CAST("concat"("year", '-', "month", '-01') AS date) = "date_trunc"('month', current_date) - INTERVAL '1' MONTH --last month
AND savings_plan_savings_plan_a_r_n <> ''
AND line_item_line_item_type = 'SavingsPlanRecurringFee'
AND try_cast(date_parse(SPLIT_PART(savings_plan_end_time, 'T', 1), '%Y-%m-%d') as date) > cast(current_date as date) --res exp time after today's date
GROUP BY
SPLIT_PART(savings_plan_savings_plan_a_r_n, '/', 2),
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m'),
savings_plan_offering_type,
savings_plan_region,
DATE_FORMAT(FROM_ISO8601_TIMESTAMP(savings_plan_start_time),'%Y-%m-%d'),
DATE_FORMAT(FROM_ISO8601_TIMESTAMP(savings_plan_end_time),'%Y-%m-%d'),
savings_plan_payment_option,
savings_plan_purchase_term
ORDER BY
calc_savings_plan_utilization_percent DESC,
day_savings_plan_end_time,
split_savings_plan_savings_plan_a_r_n,
month_line_item_usage_start_date;
PROMPT: What SQL query corresponds to the following purpose: This query produces the top 50 moving resources by 1/ cost delta and 2/ change in percentage. The parameters have been adjusted for comparison of resources from three days prior and two days prior as CUR may take up to 48 hours to update all estimated charges. Additionally, this query only pulls resources with greater than $5 in unblended cost in order to reduce noise from resources which did not exist in one of the look back periods or spun up at the end of one of the look back periods. These parameters may be adjusted as needed.?
COMPLETION: SELECT
a.line_item_usage_account_id AS "line_item_usage_account_id",
old_line_item_resource_id,
old_line_item_unblended_cost AS "cost_three_days_prior",
new_line_item_unblended_cost AS "cost_two_days_prior",
(new_line_item_unblended_cost - old_line_item_unblended_cost) AS "cost_delta",
(((new_line_item_unblended_cost - old_line_item_unblended_cost)/old_line_item_unblended_cost)*100) AS "change_percentage",
a.usage_date AS "date_three_days_prior",
b.usage_date AS "date_two_days_prior",
a.product_product_name AS "product_product_name"
FROM
(
(
SELECT
distinct "line_item_resource_id" as old_line_item_resource_id,
line_item_usage_account_id,
product_product_name,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d') usage_date,
sum(line_item_unblended_cost) as old_line_item_unblended_cost
FROM
${table_name}
WHERE
"line_item_resource_id" <> ''
AND line_item_unblended_cost > 5
AND "line_item_usage_start_date" = current_date - INTERVAL '3' DAY
GROUP BY
1, -- resource id three days prior
2, -- account id
3, -- product name
4 -- usage date
) a
FULL OUTER JOIN
(
SELECT
distinct "line_item_resource_id" as new_line_item_resource_id,
line_item_usage_account_id,
product_product_name,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d') usage_date,
SUM(line_item_unblended_cost) as new_line_item_unblended_cost
FROM
${table_name}
WHERE
"line_item_resource_id" <> ''
AND line_item_unblended_cost > 5
AND "line_item_usage_start_date" = current_date - INTERVAL '2' DAY
GROUP BY
1, -- resource id two days prior
2, -- account id
3, -- product name
4 -- usage date
) b ON a.old_line_item_resource_id = b.new_line_item_resource_id
)
ORDER BY
5 DESC, -- cost delta
6 DESC -- change percentage
LIMIT 50
PROMPT: What SQL query corresponds to the following purpose: This query will display the top costs for all spend with the product code of ‘AmazonEC2’. This will include all pricing categories (i.e. OnDemand, Reserved etc..) as well as charges for storage on EC2 (i.e. gp2). The query will output the product code as well as the product description to provide context. It is ordered by largest to smallest spend.?
COMPLETION: SELECT
line_item_product_code,
line_item_line_item_description,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_product_code = 'AmazonEC2'
AND line_item_line_item_type NOT IN ('Tax','Refund','Credit')
GROUP BY
line_item_product_code,
line_item_line_item_description
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide the EC2 usage quantity measured in hours for each purchase option and each instance type. The output will include detailed information about the instance type, amortized cost, purchase option, and usage quantity. The output will be ordered by usage quantity in descending order. This query will not run against CUR data from accounts which have purchased EC2 Reserved Instances or Savings Plans. This query will not run against CUR data from accounts which have purchased EC2 Reserved Instances or Savings Plans. not Pricing Page Please refer to the EC2 pricing page. EC2 pricing page?
COMPLETION: SELECT
bill_billing_period_start_date,
line_item_usage_start_date,
bill_payer_account_id,
line_item_usage_account_id,
CASE
WHEN (line_item_usage_type LIKE '%SpotUsage%') THEN SPLIT_PART(line_item_usage_type, ':', 2)
ELSE product_instance_type
END AS case_product_instance_type,
CASE
WHEN (savings_plan_savings_plan_a_r_n <> '') THEN 'SavingsPlan'
WHEN (reservation_reservation_a_r_n <> '') THEN 'Reserved'
WHEN (line_item_usage_type LIKE '%Spot%') THEN 'Spot'
ELSE 'OnDemand'
END AS case_purchase_option,
SUM(CASE
WHEN line_item_line_item_type = 'SavingsPlanCoveredUsage' THEN savings_plan_savings_plan_effective_cost
WHEN line_item_line_item_type = 'DiscountedUsage' THEN reservation_effective_cost
WHEN line_item_line_item_type = 'Usage' THEN line_item_unblended_cost
ELSE 0
END) AS sum_amortized_cost,
SUM(line_item_usage_amount) AS sum_line_item_usage_amount
FROM
${table_name}
WHERE
${date_filter}
AND (line_item_product_code = 'AmazonEC2'
AND product_servicecode <> 'AWSDataTransfer'
AND line_item_operation LIKE '%RunInstances%'
AND line_item_usage_type NOT LIKE '%DataXfer%'
)
AND (line_item_line_item_type = 'Usage'
OR (line_item_line_item_type = 'SavingsPlanCoveredUsage')
OR (line_item_line_item_type = 'DiscountedUsage')
)
-- excludes consumed ODCR hours from total
AND product_capacitystatus != 'AllocatedCapacityReservation'
GROUP BY
bill_billing_period_start_date,
line_item_usage_start_date,
bill_payer_account_id,
line_item_usage_account_id,
5, --refers to case_product_instance_type
6 --refers to case_purchase_option
ORDER BY
sum_line_item_usage_amount DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide EC2 consumption of Savings Plans across Compute resources by linked accounts. It also provides you with the savings received from these Savings Plans and which Savings Plans its connected to. The output is ordered by date.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
SPLIT_PART(savings_plan_savings_plan_a_r_n, '/', 2) AS savings_plan_savings_plan_a_r_n,
savings_plan_offering_type,
savings_plan_region,
CASE
WHEN line_item_product_code = 'AmazonECS' THEN 'Fargate'
WHEN line_item_product_code = 'AWSLambda' THEN 'Lambda'
ELSE product_instance_type_family
END AS case_instance_type_family,
savings_plan_end_time,
SUM(TRY_CAST(line_item_unblended_cost AS DECIMAL(16, 8))) AS sum_line_item_unblended_cost,
SUM(TRY_CAST(savings_plan_savings_plan_effective_cost AS DECIMAL(16, 8))) AS sum_savings_plan_savings_plan_effective_cost
FROM
${table_name}
WHERE
${date_filter}
AND savings_plan_savings_plan_a_r_n <> ''
AND line_item_line_item_type = 'SavingsPlanCoveredUsage'
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
SPLIT_PART(savings_plan_savings_plan_a_r_n, '/', 2),
savings_plan_offering_type,
savings_plan_region,
7, -- refers to case_instance_type_family
savings_plan_end_time
ORDER BY
day_line_item_usage_start_date;
PROMPT: What SQL query corresponds to the following purpose: This query will provide details about Compute usage that is covered by Savings Plans. The output will include detailed information about the usage type, usage amount, Savings Plans ARN, line item description, and Savings Plans effective savings as compared to On-Demand pricing. The public pricing on-demand cost will be summed and in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
bill_billing_period_start_date,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
savings_plan_savings_plan_a_r_n,
line_item_product_code,
line_item_usage_type,
SUM(line_item_usage_amount) AS sum_line_item_usage_amount,
line_item_line_item_description,
pricing_public_on_demand_rate,
SUM(pricing_public_on_demand_cost) AS sum_pricing_public_on_demand_cost,
savings_plan_savings_plan_rate,
SUM(savings_plan_savings_plan_effective_cost) AS sum_savings_plan_savings_plan_effective_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_line_item_type LIKE 'SavingsPlanCoveredUsage'
GROUP BY
bill_payer_account_id,
bill_billing_period_start_date,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
savings_plan_savings_plan_a_r_n,
line_item_product_code,
line_item_usage_type,
line_item_unblended_rate,
line_item_line_item_description,
pricing_public_on_demand_rate,
savings_plan_savings_plan_rate
ORDER BY
sum_pricing_public_on_demand_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query focuses on surfacing accounts which have utilized AWS Savings Plans for which they are not a buyer.?
COMPLETION: SELECT
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
bill_payer_account_id,
line_item_usage_account_id,
split(savings_plan_savings_plan_a_r_n,':')[5] AS savings_plan_owner_account_id,
savings_plan_offering_type,
line_item_resource_id,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16, 8))) AS sum_line_item_unblended_cost,
SUM(CAST(savings_plan_savings_plan_effective_cost AS DECIMAL(16, 8))) AS sum_savings_plan_savings_plan_effective_cost
FROM
${table_name}
WHERE
${date_filter}
AND bill_payer_account_id = '111122223333'
AND line_item_usage_account_id = '444455556666'
AND line_item_line_item_type = 'SavingsPlanCoveredUsage'
AND savings_plan_savings_plan_a_r_n NOT LIKE '%444455556666%'
GROUP BY
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
line_item_resource_id,
line_item_usage_account_id,
split(savings_plan_savings_plan_a_r_n,':')[5],
bill_payer_account_id,
savings_plan_offering_type
ORDER BY
sum_savings_plan_savings_plan_effective_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query focuses on Lambda and the breakdown of its costs by different usage element. Split by Resource IDs you can view the usage, unblended costs and amortized cost broken down by different pricing plans. These results will be ordered by date and costs.?
COMPLETION: SELECT *
FROM
(
(
SELECT
bill_payer_account_id,
line_item_usage_account_id,
line_item_line_item_type,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
product_region,
CASE
WHEN line_item_usage_type LIKE '%Lambda-Edge-GB-Second%' THEN 'Lambda EDGE GB x Sec.'
WHEN line_item_usage_type LIKE '%Lambda-Edge-Request%' THEN 'Lambda EDGE Requests'
WHEN line_item_usage_type LIKE '%Lambda-GB-Second%' THEN 'Lambda GB x Sec.'
WHEN line_item_usage_type LIKE '%Request%' THEN 'Lambda Requests'
WHEN line_item_usage_type LIKE '%In-Bytes%' THEN 'Data Transfer (IN)'
WHEN line_item_usage_type LIKE '%Out-Bytes%' THEN 'Data Transfer (Out)'
WHEN line_item_usage_type LIKE '%Regional-Bytes%' THEN 'Data Transfer (Regional)'
ELSE 'Other'
END AS case_line_item_usage_type,
line_item_resource_id,
pricing_term,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost,
SUM(CASE
WHEN line_item_line_item_type = 'SavingsPlanCoveredUsage' THEN savings_plan_savings_plan_effective_cost
WHEN line_item_line_item_type = 'SavingsPlanRecurringFee' THEN savings_plan_total_commitment_to_date - savings_plan_used_commitment
WHEN line_item_line_item_type = 'SavingsPlanNegation' THEN 0
WHEN line_item_line_item_type = 'SavingsPlanUpfrontFee' THEN 0
WHEN line_item_line_item_type = 'DiscountedUsage' THEN reservation_effective_cost
WHEN line_item_line_item_type = 'RIFee' THEN reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee
WHEN line_item_line_item_type = 'Fee' AND reservation_reservation_a_r_n <> '' THEN 0
ELSE line_item_unblended_cost
END) AS sum_amortized_cost
FROM ${table_name}
WHERE ${date_filter}
AND product_product_name = 'AWS Lambda'
AND line_item_line_item_type LIKE '%Usage%'
AND product_product_family IN ('Data Transfer', 'Serverless')
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
line_item_line_item_type,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
product_region,
6, -- refers to case_line_item_usage_type
line_item_resource_id,
pricing_term
)
UNION
(
SELECT
bill_payer_account_id,
line_item_usage_account_id,
line_item_line_item_type,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
product_region,
CASE
WHEN line_item_usage_type LIKE '%Lambda-Edge-GB-Second%' THEN 'Lambda EDGE GB x Sec.'
WHEN line_item_usage_type LIKE '%Lambda-Edge-Request%' THEN 'Lambda EDGE Requests'
WHEN line_item_usage_type LIKE '%Lambda-GB-Second%' THEN 'Lambda GB x Sec.'
WHEN line_item_usage_type LIKE '%Request%' THEN 'Lambda Requests'
WHEN line_item_usage_type LIKE '%In-Bytes%' THEN 'Data Transfer (IN)'
WHEN line_item_usage_type LIKE '%Out-Bytes%' THEN 'Data Transfer (Out)'
WHEN line_item_usage_type LIKE '%Regional-Bytes%' THEN 'Data Transfer (Regional)'
ELSE 'Other'
END AS case_line_item_usage_type,
line_item_resource_id,
savings_plan_offering_type,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(savings_plan_savings_plan_effective_cost AS DECIMAL(16,8))) AS sum_savings_plan_savings_plan_effective_cost,
SUM(CASE
WHEN line_item_line_item_type = 'SavingsPlanCoveredUsage' THEN savings_plan_savings_plan_effective_cost
WHEN line_item_line_item_type = 'SavingsPlanRecurringFee' THEN savings_plan_total_commitment_to_date - savings_plan_used_commitment
WHEN line_item_line_item_type = 'SavingsPlanNegation' THEN 0
WHEN line_item_line_item_type = 'SavingsPlanUpfrontFee' THEN 0
WHEN line_item_line_item_type = 'DiscountedUsage' THEN reservation_effective_cost
WHEN line_item_line_item_type = 'RIFee' THEN reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee
WHEN line_item_line_item_type = 'Fee' AND reservation_reservation_a_r_n <> '' THEN 0
ELSE line_item_unblended_cost
END) AS sum_amortized_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'AWS Lambda'
AND product_product_family IN ('Data Transfer', 'Serverless')
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
line_item_line_item_type,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
product_region,
6, --refers to case_line_item_usage_type
line_item_resource_id,
savings_plan_offering_type
)
) AS aggregatedTable
ORDER BY
day_line_item_usage_start_date,
sum_line_item_usage_amount,
sum_line_item_unblended_cost;
PROMPT: What SQL query corresponds to the following purpose: This query will display cost and usage of Elastic Load Balancers which didn’t receive any traffic last month and ran for more than 336 hours (14 days). Resources returned by this query could be considered for deletion.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
SPLIT_PART(line_item_resource_id, ':', 6) split_line_item_resource_id,
product_region,
pricing_unit,
sum_line_item_usage_amount,
CAST(cost_per_resource AS DECIMAL(16, 8)) AS sum_line_item_unblended_cost
FROM
(
SELECT
line_item_resource_id,
product_region,
pricing_unit,
line_item_usage_account_id,
bill_payer_account_id,
SUM(line_item_usage_amount) AS sum_line_item_usage_amount,
SUM(SUM(line_item_unblended_cost)) OVER (PARTITION BY line_item_resource_id) AS cost_per_resource,
SUM(SUM(line_item_usage_amount)) OVER (PARTITION BY line_item_resource_id, pricing_unit) AS usage_per_resource_and_pricing_unit,
COUNT(pricing_unit) OVER (PARTITION BY line_item_resource_id) AS pricing_unit_per_resource
FROM
${table_name}
WHERE
line_item_product_code = 'AWSELB'
-- get previous month
AND month = CAST(month(current_timestamp + -1 * INTERVAL '1' MONTH) AS VARCHAR)
-- get year for previous month
AND year = CAST(year(current_timestamp + -1 * INTERVAL '1' MONTH) AS VARCHAR)
AND line_item_line_item_type = 'Usage'
GROUP BY
line_item_resource_id,
product_region,
pricing_unit,
line_item_usage_account_id,
bill_payer_account_id
)
WHERE
-- filter only resources which ran more than half month (336 hrs)
usage_per_resource_and_pricing_unit > 336
AND pricing_unit_per_resource = 1
ORDER BY
cost_per_resource DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide an inventory for EC2 Savings Plans. It will show useful information about the Savings Plans purchased including ID (ARN), type, term length, commitment (used, hourly, etc…), and utilization. Cost Explorer can also provide this information in the Inventory and Utilization reports however, this combines elements from both into a single report.?
COMPLETION: SELECT
SPLIT_PART(savings_plan_savings_plan_a_r_n, '/', 2) AS split_savings_plan_savings_plan_a_r_n,
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m') AS month_line_item_usage_start_date,
savings_plan_offering_type,
savings_plan_region,
DATE_FORMAT(FROM_ISO8601_TIMESTAMP(savings_plan_start_time),'%Y-%m-%d') AS day_savings_plan_start_time,
DATE_FORMAT(FROM_ISO8601_TIMESTAMP(savings_plan_end_time),'%Y-%m-%d') AS day_savings_plan_end_time,
savings_plan_payment_option,
savings_plan_purchase_term,
SUM(TRY_CAST(savings_plan_recurring_commitment_for_billing_period AS DECIMAL(16, 8))) AS sum_savings_plan_recurring_committment_for_billing_period,
SUM(TRY_CAST(savings_plan_total_commitment_to_date AS DECIMAL(16, 8))) AS sum_savings_plan_total_commitment_to_date,
SUM(TRY_CAST(savings_plan_used_commitment AS DECIMAL(16, 8))) AS sum_savings_plan_used_commitment,
AVG(CASE
WHEN line_item_line_item_type = 'SavingsPlanRecurringFee' THEN TRY_CAST(savings_plan_total_commitment_to_date AS DECIMAL(8, 2))
END) AS "Hourly Commitment",
-- (used commitment / total commitment) * 100 = utilization %
TRY_CAST(((SUM(TRY_CAST(savings_plan_used_commitment AS DECIMAL(16, 8))) / SUM(TRY_CAST(savings_plan_total_commitment_to_date AS DECIMAL(16, 8)))) * 100) AS DECIMAL(3, 0)) AS calc_savings_plan_utilization_percent
FROM
${table_name}
WHERE
${date_filter}
AND savings_plan_savings_plan_a_r_n <> ''
AND line_item_line_item_type = 'SavingsPlanRecurringFee'
GROUP BY
SPLIT_PART(savings_plan_savings_plan_a_r_n, '/', 2),
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m'),
savings_plan_offering_type,
savings_plan_region,
DATE_FORMAT(FROM_ISO8601_TIMESTAMP(savings_plan_start_time),'%Y-%m-%d'),
DATE_FORMAT(FROM_ISO8601_TIMESTAMP(savings_plan_end_time),'%Y-%m-%d'),
savings_plan_payment_option,
savings_plan_purchase_term
ORDER BY
split_savings_plan_savings_plan_a_r_n,
month_line_item_usage_start_date;
PROMPT: What SQL query corresponds to the following purpose: The Reserved Instance Utilization and Coverage reports are available out-of-the-box in AWS Cost Explorer. This query provides coverage for EC2 Reserved Instances. It shows useful information about the Reserved Instances purchased including Lease ID, instance type and family, used and unused amounts, and On-Demand usage that could be covered by additional Savings Plans if this is your preferred savings method. Reserved Instance Utilization and Coverage reports Cost and Usage columns are dynamic and their visibility in the Athena tables depends on usage. This query will only work if you have reserved instance usage in the table/view you are querying. If you do not have usage you will receive an error that reservation_reservation_a_r_n is an invalid column name. Cost and Usage columns are dynamic and their visibility in the Athena tables depends on usage. This query will only work if you have reserved instance usage in the table/view you are querying. If you do not have usage you will receive an error that reservation_reservation_a_r_n is an invalid column name.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
CASE
WHEN line_item_line_item_type IN ('Usage') THEN 'OnDemand'
WHEN line_item_line_item_type IN ('Fee','RIFee','DiscountedUsage') THEN 'ReservedInstance'
END AS case_purchase_option,
SPLIT_PART(SPLIT_PART(reservation_reservation_a_r_n,':',6),'/',2) AS split_reservation_reservation_a_r_n,
SPLIT_PART(line_item_usage_type ,':',2) AS split_line_item_usage_type_instance_type,
SPLIT_PART(SPLIT_PART(line_item_usage_type ,':',2), '.', 1) AS split_line_item_usage_type_instance_family,
CASE product_region
WHEN NULL THEN 'Global'
WHEN '' THEN 'Global'
ELSE product_region
END AS case_product_region,
line_item_line_item_type,
SUM(TRY_CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(TRY_CAST(reservation_unused_quantity AS DOUBLE)) AS sum_reservation_unused_quantity,
SUM(TRY_CAST(line_item_normalized_usage_amount AS DOUBLE)) AS sum_line_item_normalized_usage_amount,
SUM(TRY_CAST(reservation_unused_normalized_unit_quantity AS DOUBLE)) AS sum_reservation_unused_normalized_unit_quantity,
SUM(CAST(reservation_effective_cost AS DECIMAL(16,8))) AS sum_reservation_effective_cost,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'Amazon Elastic Compute Cloud'
AND line_item_operation LIKE '%RunInstance%'
AND line_item_line_item_type IN ('Usage','Fee','RIFee','DiscountedUsage')
AND product_product_family NOT IN ('Data Transfer')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
4, -- refers to case_purchase_option
SPLIT_PART(SPLIT_PART(reservation_reservation_a_r_n,':',6),'/',2),
SPLIT_PART(line_item_usage_type ,':',2),
SPLIT_PART(SPLIT_PART(line_item_usage_type ,':',2), '.', 1),
8, -- refers to case_product_region
line_item_line_item_type
ORDER BY
day_line_item_usage_start_date,
split_line_item_usage_type_instance_type,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: AWS Services running locally on AWS Outposts will be charged on usage only. Operating system charges are billed based on usage as an uplift to cover the license fee and no minimum fee required. This query will provide the Amazon EC2 software costs (like Windows, RHEL or others) on AWS Outposts. These software fees are not included with the cost of the AWS Outposts racks and are billed separately here. The output will include detailed information about the instance type, pre-installed softwares, operating system, description, amortized cost, and usage quantity. The output will be ordered by amortized cost in descending order. AWS Outposts?
COMPLETION: SELECT
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
bill_payer_account_id,
line_item_usage_account_id,
line_item_resource_id,
product_instance_type,
product_operating_system,
product_pre_installed_sw,
line_item_line_item_description,
SUM(line_item_usage_amount) AS sum_line_item_usage_amount,
SUM(CASE
WHEN line_item_line_item_type = 'SavingsPlanCoveredUsage' THEN savings_plan_savings_plan_effective_cost
WHEN line_item_line_item_type = 'DiscountedUsage' THEN reservation_effective_cost
WHEN line_item_line_item_type = 'Usage' THEN line_item_unblended_cost
ELSE 0
END) AS sum_amortized_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_location_type='AWS Outposts'
AND product_product_family='Compute Instance'
AND line_item_operation LIKE '%RunInstance%'
AND (line_item_line_item_type = 'Usage'
OR (line_item_line_item_type = 'SavingsPlanCoveredUsage')
OR (line_item_line_item_type = 'DiscountedUsage')
)
GROUP BY
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
bill_payer_account_id,
line_item_usage_account_id,
line_item_resource_id,
product_instance_type,
product_operating_system,
product_pre_installed_sw,
line_item_line_item_description
ORDER BY
day_line_item_usage_start_date ASC,
sum_amortized_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will output the daily cost and usage per resource, by operation and service, for Elastic Consainer Services, ECS and EKS, both unblended and amortized costs are shown. To provide you with a complete picture of the data, to match totals in cost explorer, if you are using Savings Plans you will likely see results with blank resource IDs, these represent the Savings Plans Negation values for compute cost already covered by Savings Plans. blank?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
SPLIT_PART(line_item_resource_id,':',6) AS split_line_item_resource_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
line_item_operation,
line_item_product_code,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(line_item_unblended_cost) sum_line_item_unblended_cost,
SUM(CASE
WHEN line_item_line_item_type = 'SavingsPlanCoveredUsage' THEN savings_plan_savings_plan_effective_cost
WHEN line_item_line_item_type = 'SavingsPlanRecurringFee' THEN (savings_plan_total_commitment_to_date - savings_plan_used_commitment)
WHEN line_item_line_item_type = 'SavingsPlanNegation' THEN 0
WHEN line_item_line_item_type = 'SavingsPlanUpfrontFee' THEN 0
WHEN line_item_line_item_type = 'DiscountedUsage' THEN reservation_effective_cost
ELSE line_item_unblended_cost
END) AS sum_amortized_cost
FROM
${table_name}
WHERE
${date_filter}
and line_item_product_code IN ('AmazonECS','AmazonEKS')
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage','SavingsPlanRecurringFee','SavingsPlanNegation','SavingsPlanUpfrontFee')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
SPLIT_PART(line_item_resource_id,':',6),
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_operation,
line_item_product_code
ORDER BY
day_line_item_usage_start_date,
sum_line_item_unblended_cost,
sum_line_item_usage_amount,
line_item_operation;
PROMPT: What SQL query corresponds to the following purpose: This query will output the daily ECS cost and usage per resource, by usage type and purchase option, both unblended and amortized costs are shown. To provide you with a complete picture of the data, to match totals in cost explorer, if you are using Savings Plans you will likely see results with blank resource IDs, these represent the Savings Plans Negation values for compute cost already covered by Savings Plans. blank?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
SPLIT_PART(SPLIT_PART(line_item_resource_id,':',6),'/',2) AS split_line_item_resource_id,
CASE
WHEN line_item_usage_type LIKE '%Fargate-GB%' THEN 'GB per hour'
WHEN line_item_usage_type LIKE '%Fargate-vCPU%' THEN 'vCPU per hour'
END AS case_line_item_usage_type,
CASE line_item_line_item_type
WHEN 'SavingsPlanCoveredUsage' THEN savings_plan_offering_type
WHEN 'SavingsPlanNegation' THEN savings_plan_offering_type
ELSE
CASE pricing_term
WHEN 'OnDemand' THEN 'OnDemand'
WHEN '' THEN 'Spot Instance'
ELSE pricing_term
END
END AS case_purchase_option,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CASE pricing_term
WHEN 'OnDemand' THEN line_item_unblended_cost
WHEN '' THEN line_item_unblended_cost
END) AS sum_line_item_unblended_cost,
SUM(CASE
WHEN line_item_line_item_type = 'SavingsPlanCoveredUsage' THEN savings_plan_savings_plan_effective_cost
WHEN line_item_line_item_type = 'SavingsPlanRecurringFee' THEN savings_plan_total_commitment_to_date - savings_plan_used_commitment
WHEN line_item_line_item_type = 'SavingsPlanNegation' THEN 0
WHEN line_item_line_item_type = 'SavingsPlanUpfrontFee' THEN 0
WHEN line_item_line_item_type = 'DiscountedUsage' THEN reservation_effective_cost
ELSE line_item_unblended_cost
END) AS sum_amortized_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_product_code IN ('AmazonECS')
AND line_item_operation != 'ECSTask-EC2'
AND product_product_family != 'Data Transfer'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage','SavingsPlanNegation','SavingsPlanRecurringFee','SavingsPlanUpfrontFee')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
SPLIT_PART(SPLIT_PART(line_item_resource_id,':',6),'/',2),
5, --refers to case_line_item_usage_type
6 -- refers to case_purchase_option
ORDER BY
day_line_item_usage_start_date ASC,
case_purchase_option,
sum_line_item_usage_amount DESC;
PROMPT: What SQL query corresponds to the following purpose: The cost allocation data generated by Amazon ECS split cost allocation analyzes the resource consumption of each container running on an EC2 instance. It calculates costs by considering the amortized cost of the instance and the proportion of CPU and memory resources utilized by the containers. Once split cost allocation data is configured, the AWS Cost and Usage Report will include additional columns that provide detailed insights into container-level costs. These columns offer a comprehensive breakdown of the costs associated with individual containers and their respective resource consumption. Without these columns, this query will generate errors. configured Two new usage records are added for each ECS task per hour as a result, the Cost and Usage Report may be significantly larger after enabling ECS Split Cost Allocation. This published calculation allows customers to estimate the number of new lines. published calculation?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
line_item_usage_type,
SPLIT_PART(line_item_resource_id,':',6) AS split_line_item_resource_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m') AS month_line_item_usage_start_date,
line_item_operation,
line_item_product_code,
split_line_item_parent_resource_id,
SUM(CAST(split_line_item_split_usage AS DECIMAL(16,8))) AS sum_split_line_item_split_usage,
SUM(CAST(split_line_item_split_cost AS DECIMAL(16,8))) AS sum_split_line_item_split_cost,
SUM(CAST(split_line_item_unused_cost AS DECIMAL(16,8))) sum_split_line_item_unused_cost
FROM
${table_name}
WHERE
${date_filter}
and line_item_product_code IN ('AmazonECS') AND line_item_operation like 'ECSTask%'
and split_line_item_split_usage !='' and split_line_item_split_cost !='' and split_line_item_unused_cost !=''
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
line_item_usage_type,
SPLIT_PART(line_item_resource_id,':',6),
DATE_FORMAT((line_item_usage_start_date),'%Y-%m'),
line_item_operation,
line_item_product_code,
split_line_item_parent_resource_id,
split_line_item_split_usage,
split_line_item_split_cost,
split_line_item_unused_cost
ORDER BY
month_line_item_usage_start_date ASC,
split_line_item_unused_cost DESC,
line_item_operation
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended cost and usage information per linked account for Amazon Connect. The output will include specific details about the usage type, usage description, and product usage region. The cost will be summed and in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
product_region,
CASE
WHEN line_item_usage_type LIKE '%end-customer-mins' THEN 'End customer minutes'
WHEN line_item_usage_type LIKE '%chat-message' THEN 'Chat messages'
WHEN line_item_usage_type LIKE '%did-numbers' THEN 'DID days of use'
WHEN line_item_usage_type LIKE '%tollfree-numbers' THEN 'Toll free days of use'
WHEN line_item_usage_type LIKE '%did-inbound-mins' THEN 'Inbound DID minutes'
WHEN line_item_usage_type LIKE '%outbound-mins' THEN 'Outbound minutes'
WHEN line_item_usage_type LIKE '%tollfree-inbound-mins' THEN 'Inbound Toll Free minutes'
ELSE 'Others'
END AS case_line_item_usage_type,
line_item_line_item_description,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_product_code IN ('AmazonConnect', 'ContactCenterTelecomm')
AND line_item_line_item_type = 'Usage'
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
product_region,
line_item_usage_type,
line_item_line_item_description
ORDER BY
day_line_item_usage_start_date ASC,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides a breakdown of costs associated with an Aurora Global Database deployment, excluding backup costs. Output will be grouped by day, account, charge type, usage type, operation, description, and resource ID. Output will be sorted by day, then cost (descending). Aurora Global Databases are comprised of multiple components, each of which appears as a separate line item in CUR. There is no overarching Aurora Global Database resource ID that can be used to filter query output. This means to get an accurate picture of a specific Aurora Global DB deployment, the relevant cluster and database instance resource IDs in each region where the database is replicated must be added to the WHERE filter. Placeholder variables indicated by a dollar sign and curly braces (${ }) appear where resource IDs should be inserted. Placeholder variables must be replaced before the query will run. Note that depending on your deployment model, you may need to add or remove lines from the WHERE filter as indicated. Resource IDs can be retrieved through the console, CLI, SDK, or other tools, as normal. If you only have access to CUR, consider the simple query SELECT DISTINCT(line_item_resource_id) FROM ${table_name} WHERE line_item_product_code = 'AmazonRDS' which will turn up a list of RDS resource IDs. Even in smaller environments the number of resource IDs returned may make it challenging to identify the right resource IDs. In that case, consider adding additional columns to help differentiate and identify the correct resource, such as columns with user-defined cost allocation tags. For example, SELECT DISTINCT(line_item_resource_id), resource_tags_user_name, resource_tags_user_cost_center FROM ${table_name} WHERE line_item_product_code = 'AmazonRDS'. SELECT DISTINCT(line_item_resource_id) FROM ${table_name} WHERE line_item_product_code = 'AmazonRDS' user-defined cost allocation tags SELECT DISTINCT(line_item_resource_id), resource_tags_user_name, resource_tags_user_cost_center FROM ${table_name} WHERE line_item_product_code = 'AmazonRDS' Consider the following Aurora Global DB deployment example: Primary RegionPrimary writer instanceOne reader instanceSecondary Region 1Three reader instancesSecondary Region 2Zero instances (headless) Primary RegionPrimary writer instanceOne reader instance Primary writer instanceOne reader instance Primary writer instance One reader instance Secondary Region 1Three reader instances Three reader instances Three reader instances Secondary Region 2Zero instances (headless) Zero instances (headless) Zero instances (headless) In this example, the following resource IDs would be needed: Primary region cluster IDPrimary region writer instance namePrimary region reader instance nameSecondary region 1 cluster IDSecondary region 1 reader1 instance nameSecondary region 1 reader2 instance nameSecondary region 1 reader3 instance nameSecondary region 2 cluster ID Primary region cluster ID Primary region writer instance name Primary region reader instance name Secondary region 1 cluster ID Secondary region 1 reader1 instance name Secondary region 1 reader2 instance name Secondary region 1 reader3 instance name Secondary region 2 cluster ID?
COMPLETION: SELECT
DATE_TRUNC('day',line_item_usage_start_date) AS day_line_item_usage_start_date,
line_item_usage_account_id,
line_item_line_item_type,
line_item_usage_type,
line_item_operation,
line_item_line_item_description,
line_item_resource_id,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost,
SUM(line_item_usage_amount) AS sum_line_item_usage_amount
FROM
${table_name}
WHERE
${date_filter}
AND (line_item_resource_id LIKE '%${primary_cluster_id}%' -- primary region cluster id in format 'cluster-xxxxxxxxxxxxxxxxxxxxxxxx'
OR line_item_resource_id LIKE '%${secondary_cluster_id_1}%' -- secondary region cluster id in format 'cluster-xxxxxxxxxxxxxxxxxxxxxxxx'
OR line_item_resource_id LIKE '%${secondary_cluster_id_n}%' -- additional secondary region cluster id. copy and paste this line once per additional region/cluster
OR line_item_resource_id LIKE '%${primary_cluster_db_instance_name_1}%' -- primary region database instance name. user defined string, e.g 'team-a-mysql-db-1'
OR line_item_resource_id LIKE '%${primary_cluster_db_instance_name_n}%' -- additional primary region database instance name. copy and paste this line once per additional instance
OR line_item_resource_id LIKE '%${secondary_cluster_db_instance_name_1}%' -- secondary region database instance name. user defined string, e.g 'team-a-mysql-db-2'. optional if running headless.
OR line_item_resource_id LIKE '%${secondary_cluster_db_instance_name_n}%' -- additional secondary region database instance name. copy and paste this line once per additional instance
)
AND line_item_usage_type NOT LIKE '%BackupUsage%'
GROUP BY
DATE_TRUNC('day', line_item_usage_start_date),
line_item_usage_account_id,
line_item_line_item_type,
line_item_usage_type,
line_item_operation,
line_item_line_item_description,
line_item_resource_id
ORDER BY
day_line_item_usage_start_date,
sum_line_item_unblended_cost DESC
;
PROMPT: What SQL query corresponds to the following purpose: This query will output the daily sum per resource for all RDS purchase options across all RDS usage types.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d') AS day_line_item_usage_start_date,
product_instance_type,
line_item_operation,
line_item_usage_type,
line_item_line_item_type,
pricing_term,
product_product_family,
SPLIT_PART(line_item_resource_id,':',7) AS split_line_item_resource_id,
product_database_engine,
SUM(CASE WHEN line_item_line_item_type = 'DiscountedUsage' THEN line_item_usage_amount
WHEN line_item_line_item_type = 'Usage' THEN line_item_usage_amount
ELSE 0
END) AS sum_line_item_usage_amount,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost,
SUM(CASE WHEN line_item_line_item_type = 'DiscountedUsage' THEN reservation_effective_cost
WHEN line_item_line_item_type = 'RIFee' THEN reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee
WHEN line_item_line_item_type = 'Fee' AND reservation_reservation_a_r_n <> '' THEN 0
ELSE line_item_unblended_cost
END) AS sum_amortized_cost,
SUM(CASE WHEN line_item_line_item_type = 'RIFee' THEN -reservation_amortized_upfront_fee_for_billing_period
ELSE 0
END) AS sum_ri_trueup,
SUM(CASE WHEN line_item_line_item_type = 'Fee' AND reservation_reservation_a_r_n <> '' THEN line_item_unblended_cost
ELSE 0
END) AS sum_ri_upfront_fees
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'Amazon Relational Database Service'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'Fee', 'RIFee')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
product_instance_type,
line_item_operation,
line_item_usage_type,
line_item_line_item_type,
pricing_term,
product_product_family,
SPLIT_PART(line_item_resource_id,':',7),
product_database_engine
ORDER BY
day_line_item_usage_start_date,
sum_line_item_usage_amount,
sum_amortized_cost;
PROMPT: What SQL query corresponds to the following purpose: This query will output the total monthly blended costs for RDS grouped by usage type and a specified tag (e.g. Environment:Test,Dev,Prod). The query can be modified to adjust the Cost dataset from Blended to Unblended by adjusting the specified cost column (line_item_blended_cost -> line_item_unblended_cost). This query would be helpful to visualize a quick monthly breakdown of cost components for RDS usage with a specific tag (Environment:Test,Dev,Prod). Blended to Unblended?
COMPLETION: SELECT
line_item_usage_type,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
resource_tags_user_environment,
SUM(CAST(line_item_blended_cost AS DECIMAL(16,8))) AS sum_line_item_blended_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_product_code='AmazonRDS'
AND resource_tags_user_environment = 'dev'
GROUP BY
line_item_usage_type,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
resource_tags_user_environment
HAVING
SUM(line_item_blended_cost) > 0
ORDER BY
line_item_usage_type,
month_line_item_usage_start_date,
resource_tags_user_environment;
PROMPT: What SQL query corresponds to the following purpose: This query will output the total daily unblended costs for RDS Instances running on AWS Outposts racks. This query will be helpful to visualize a quick breakdown of cost components for RDS usage based on instance type, database engine and deployment option (Multi vs Single-AZ).?
COMPLETION: SELECT
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
bill_payer_account_id,
line_item_usage_account_id,
SPLIT_PART(line_item_resource_id,':',7) AS split_line_item_resource_id,
product_instance_type,
product_database_engine,
product_deployment_option,
SUM(CAST(line_item_usage_amount AS double)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS decimal(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_location_type='AWS Outposts'
AND product_product_family='Database Instance'
AND line_item_product_code = 'AmazonRDS'
AND line_item_line_item_type IN ('Usage', 'DiscountedUsage')
GROUP BY
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
bill_payer_account_id,
line_item_usage_account_id,
line_item_resource_id,
product_instance_type,
product_database_engine,
product_deployment_option
ORDER BY
day_line_item_usage_start_date ASC,
sum_line_item_usage_amount DESC,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will output the total monthly sum per resource for all DynamoDB purchase options (including reserved capacity) across all DynamoDB usage types (including data transfer and storage costs). The unblended cost will be summed and in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
product_location,
SPLIT_PART(line_item_resource_id, 'table/', 2) AS line_item_resource_id,
CASE
WHEN line_item_usage_type LIKE '%CapacityUnit%' THEN 'DynamoDB Provisioned Capacity'
WHEN line_item_usage_type LIKE '%HeavyUsage%' THEN 'DynamoDB Provisioned Capacity'
WHEN line_item_usage_type LIKE '%RequestUnit%' THEN 'DynamoDB On-Demand Capacity'
WHEN line_item_usage_type LIKE '%TimedStorage%' THEN 'DynamoDB Storage'
WHEN line_item_usage_type LIKE '%TimedBackup%' THEN 'DynamoDB Backups'
WHEN line_item_usage_type LIKE '%TimedPITR%' THEN 'DynamoDB Backups'
WHEN line_item_usage_type like '%DataTransfer%'THEN 'DynamoDB Data Transfer'
ELSE 'DynamoDB Other Usage'
END AS case_line_item_usage_type,
CASE
WHEN line_item_line_item_type LIKE '%Fee' THEN 'DynamoDB Reserved Capacity'
WHEN line_item_line_item_type = 'DiscountedUsage' THEN 'DynamoDB Reserved Capacity'
ELSE 'DynamoDB Usage'
END AS case_purchase_option,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_blended_cost AS DECIMAL(16,8))) AS sum_line_item_blended_cost,
SUM(CAST(reservation_unused_quantity AS DOUBLE)) AS sum_reservation_unused_quantity,
SUM(CAST(reservation_unused_recurring_fee AS DECIMAL(16,8))) AS sum_reservation_unused_recurring_fee,
reservation_reservation_a_r_n
FROM
${table_name}
WHERE
{$date_filter}
AND line_item_product_code = 'AmazonDynamoDB'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
product_location,
SPLIT_PART(line_item_resource_id, 'table/', 2),
6, -- refers to case_line_item_usage_type
7, -- refers to case_purchase_option
reservation_reservation_a_r_n
ORDER BY
sum_line_item_blended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended and amortized cost as well as usage information per linked account for Amazon Redshift. The output will include detailed information about the resource id (cluster name), usage type, and API operation. The usage amount and cost will be summed and the cost will be in descending order. This query includes RI and SP true up which will show any upfront fees to the account that purchased the pricing model.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
product_instance_type,
SPLIT_PART(line_item_resource_id,':',7) AS split_line_item_resource_id,
line_item_operation,
line_item_usage_type,
line_item_line_item_type,
pricing_term,
product_usage_family,
product_product_family,
SUM(CASE
WHEN line_item_line_item_type = 'DiscountedUsage' THEN line_item_usage_amount
WHEN line_item_line_item_type = 'Usage' THEN line_item_usage_amount
ELSE 0
END) AS sum_line_item_usage_amount,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost,
SUM(CASE
WHEN line_item_line_item_type = 'DiscountedUsage' THEN reservation_effective_cost
WHEN line_item_line_item_type = 'RIFee' THEN reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee
WHEN line_item_line_item_type = 'Fee' AND reservation_reservation_a_r_n <> '' THEN 0
ELSE line_item_unblended_cost
END) AS sum_amortized_cost,
SUM(CASE
WHEN line_item_line_item_type = 'RIFee' THEN -reservation_amortized_upfront_fee_for_billing_period
ELSE 0
END) AS sum_ri_trueup,
SUM(CASE
WHEN line_item_line_item_type = 'Fee' AND reservation_reservation_a_r_n <> '' THEN line_item_unblended_cost
ELSE 0
END) AS ri_upfront_fees
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'Amazon Redshift'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'RIFee', 'Fee')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
product_instance_type,
SPLIT_PART(line_item_resource_id,':',7),
line_item_operation,
line_item_usage_type,
line_item_line_item_type,
pricing_term,
product_usage_family,
product_product_family
ORDER BY
day_line_item_usage_start_date,
product_product_family,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will output the total monthly sum per resource for all Amazon ElastiCache purchase options (including reserved instances) across all ElastiCache instances types. The unblended and amortized cost will be summed and in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
SPLIT_PART(line_item_resource_id,':',7) AS split_line_item_resource_id,
SPLIT_PART(line_item_usage_type ,':',2) AS split_line_item_usage_type,
CASE
WHEN line_item_line_item_type = 'DiscountedUsage' THEN 'Reserved Instance'
WHEN line_item_line_item_type = 'Usage' THEN 'OnDemand'
ELSE 'Others'
END AS case_purchase_option,
SUM(CASE
WHEN line_item_line_item_type = 'DiscountedUsage' THEN line_item_usage_amount
WHEN line_item_line_item_type = 'Usage' THEN line_item_usage_amount
ELSE 0
END) AS sum_line_item_usage_amount,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost,
SUM(CASE
WHEN line_item_line_item_type = 'DiscountedUsage' THEN reservation_effective_cost
WHEN line_item_line_item_type = 'RIFee' THEN reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee
WHEN line_item_line_item_type = 'Fee' AND reservation_reservation_a_r_n <> '' THEN 0
ELSE line_item_unblended_cost
END) AS sum_amortized_cost,
SUM(CASE
WHEN line_item_line_item_type = 'RIFee' THEN -reservation_amortized_upfront_fee_for_billing_period
ELSE 0
END) AS sum_ri_trueup,
SUM(CASE
WHEN line_item_line_item_type = 'Fee' AND reservation_reservation_a_r_n <> '' THEN line_item_unblended_cost
ELSE 0
END) AS ri_upfront_fees
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'Amazon ElastiCache'
AND product_product_family = 'Cache Instance'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'RIFee', 'Fee')
GROUP BY
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
bill_payer_account_id,
line_item_usage_account_id,
line_item_line_item_type,
line_item_resource_id,
line_item_usage_type
ORDER BY
month_line_item_usage_start_date,
sum_line_item_usage_amount DESC,
sum_line_item_unblended_cost;
PROMPT: What SQL query corresponds to the following purpose: This query will output the total daily cost per DocumentDB cluster. The output will include detailed information about the resource id (cluster name) and usage type. The unblended cost will be summed and in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(("line_item_usage_start_date"),'%Y-%m-%d') AS day_line_item_usage_start_date,
SPLIT_PART(line_item_resource_id,':',7) AS line_item_resource_id,
line_item_usage_type,
product_region,
line_item_product_code,
sum(CAST(line_item_usage_amount AS double)) AS sum_line_item_usage_amount,
sum(CAST(line_item_unblended_cost AS decimal(16,8))) AS sum_line_item_unblended_cost
FROM
${table_Name}
WHERE
${date_filter}
AND line_item_product_code = 'AmazonDocDB'
AND line_item_line_item_type NOT IN ('Tax','Credit','Refund','Fee','RIFee')
GROUP BY
1, -- bill_payer_account_id
2, -- line_item_usage_account_id
3, -- day_line_item_usage_start_date
4, -- line_item_resource_id
5, -- line_item_usage_type
6, -- product_region
7 -- line_item_product_code
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide unblended cost and usage information per linked account for Amazon WorkSpaces. The output will include detailed information about the resource id (WorkSpace ID), usage type, running mode, product bundle, and API operation. The cost will be summed and in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
SPLIT_PART(line_item_resource_id,'/',2) AS split_line_item_resource_id,
SPLIT_PART(product_bundle,'-',1) AS split_product_bundle,
product_operating_system,
product_memory,
product_storage,
product_vcpu,
product_running_mode,
product_license,
product_software_included,
pricing_unit,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'Amazon WorkSpaces'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_resource_id,
product_bundle,
product_operating_system,
product_memory,
product_storage,
product_vcpu,
product_running_mode,
product_license,
product_software_included,
pricing_unit
ORDER BY
day_line_item_usage_start_date,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: AutoStop Workspaces are cost effective when used for several hours per day. If AutoStop Workspaces run for more than 80 hrs per month it is more cost effective to switch to AlwaysOn mode. This query shows AutoStop Workspaces which ran more that 80 hrs in previous month. If the usage pattern for these Workspaces is the same month over month it’s possible to optimize cost by switching to AlwaysOn mode. For example, Windows PowerPro (8 vCPU, 32GB RAM) bundle in eu-west-1 runs for 400 hrs per month. In AutoStop mode it costs $612/month ($8.00/month + 400 * $1.53/hour) while if used in AlwaysOn mode it would cost $141/month.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
SPLIT_PART(line_item_resource_id, '/', 2) AS split_line_item_resource_id,
product_region,
product_operating_system,
product_bundle_description,
product_software_included,
product_license,
product_rootvolume,
product_uservolume,
pricing_unit,
sum_line_item_usage_amount,
CAST(total_cost_per_resource AS DECIMAL(16, 8)) AS "sum_line_item_unblended_cost(incl monthly fee)"
FROM
(
SELECT
bill_payer_account_id,
line_item_usage_account_id,
line_item_resource_id,
product_operating_system,
pricing_unit,
product_region,
product_bundle_description,
product_rootvolume,
product_uservolume,
product_software_included,
product_license,
SUM(line_item_usage_amount) AS sum_line_item_usage_amount,
SUM(SUM(line_item_unblended_cost)) OVER (PARTITION BY line_item_resource_id) AS total_cost_per_resource,
SUM(SUM(line_item_usage_amount)) OVER (PARTITION BY line_item_resource_id, pricing_unit) AS usage_amount_per_resource_and_pricing_unit
FROM
$ {table_name}
WHERE
line_item_product_code = 'AmazonWorkSpaces'
-- get previous month
AND CAST(month AS INT) = CAST(month(current_timestamp + -1 * INTERVAL '1' MONTH) AS INT)
-- get year for previous month
AND CAST(year AS INT) = CAST(year(current_timestamp + -1 * INTERVAL '1' MONTH) AS INT)
AND line_item_line_item_type = 'Usage'
AND line_item_usage_type LIKE '%AutoStop%'
GROUP BY
line_item_usage_account_id,
line_item_resource_id,
product_operating_system,
pricing_unit,
product_region,
product_bundle_description,
product_rootvolume,
product_uservolume,
bill_payer_account_id,
product_software_included,
product_license
)
WHERE
-- return only workspaces which ran more than 80 hrs
usage_amount_per_resource_and_pricing_unit > 80
ORDER BY
total_cost_per_resource DESC,
line_item_resource_id,
line_item_usage_account_id,
product_operating_system,
pricing_unit;
PROMPT: What SQL query corresponds to the following purpose: This query will provide unblended cost and usage information per linked account for Amazon AppStream 2.0. The output will include detailed information about the product family, product instance type, pricing unit, region along with usage amount. The cost will be summed and in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
product_product_family, -- Stopped Instance, Streaming Instance, User Fees
product_instance_type, -- stream.TYPE.SIZE
pricing_unit, -- Hrs, Users
product_region,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
CASE line_item_line_item_type
WHEN 'DiscountedUsage' THEN SUM(CAST(reservation_effective_cost AS DECIMAL(16,8)))
WHEN 'Usage' THEN SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8)))
ELSE SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8)))
END AS sum_line_item_unblended_cost_reservation_effective_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'Amazon AppStream'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
product_product_family,
product_instance_type,
pricing_unit,
product_region,
line_item_line_item_type
ORDER BY
month_line_item_usage_start_date,
sum_line_item_usage_amount DESC,
sum_line_item_unblended_cost_reservation_effective_cost,
product_product_family;
PROMPT: What SQL query corresponds to the following purpose: This query will provide monthly unblended and amortized costs per linked account for all services. The query includes ri_sp_trueup and ri_sp_upfront_fees columns to allow you to visualize the difference between unblended and amortized costs. Unblended cost equals usage plus upfront fees. Amortized cost equals usage plus the portion of upfront fees applicable to the period (both used and unused). True-up therefore represents the difference between total upfront fees incurred in the period using an unblended/cash-based accounting model, and the smaller portion of upfront fees applicable to the period using an amortized/accrual-based accounting model. This query excludes discounts, credits, refunds and taxes, as well as Route 53 Domains usage type due to differences in how usage date is recorded between Cost Explorer and CUR. Notes: Notes: Charges for the current billing month may differ slightly when comparing between Cost Explorer and CUR due to differences in how current month charges are estimated. Charges will match between Cost Explorer and CUR once billing has been finalized at the close of the month.This query expects that you have reserved instances purchased within at least one of the accounts. Running this query as is without reserved instances in the CUR data set will result in an error. To use this query without reserved instances, remove or comment out lines containing reservation_reservation_a_r_n. Charges for the current billing month may differ slightly when comparing between Cost Explorer and CUR due to differences in how current month charges are estimated. Charges will match between Cost Explorer and CUR once billing has been finalized at the close of the month. Charges for the current billing month may differ slightly when comparing between Cost Explorer and CUR due to differences in how current month charges are estimated. Charges will match between Cost Explorer and CUR once billing has been finalized at the close of the month. current month charges are estimated This query expects that you have reserved instances purchased within at least one of the accounts. Running this query as is without reserved instances in the CUR data set will result in an error. To use this query without reserved instances, remove or comment out lines containing reservation_reservation_a_r_n. This query expects that you have reserved instances purchased within at least one of the accounts. Running this query as is without reserved instances in the CUR data set will result in an error. To use this query without reserved instances, remove or comment out lines containing reservation_reservation_a_r_n. reservation_reservation_a_r_n?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-01') AS month_line_item_usage_start_date,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost,
SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN savings_plan_savings_plan_effective_cost
WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN (savings_plan_total_commitment_to_date - savings_plan_used_commitment)
WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0
WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN 0
WHEN (line_item_line_item_type = 'DiscountedUsage') THEN reservation_effective_cost
WHEN (line_item_line_item_type = 'RIFee') THEN (reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee)
WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN 0
ELSE line_item_unblended_cost
END) AS amortized_cost,
(SUM(line_item_unblended_cost)
- SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN savings_plan_savings_plan_effective_cost
WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN (savings_plan_total_commitment_to_date - savings_plan_used_commitment)
WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0
WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN 0
WHEN (line_item_line_item_type = 'DiscountedUsage') THEN reservation_effective_cost
WHEN (line_item_line_item_type = 'RIFee') THEN (reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee)
WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN 0
ELSE line_item_unblended_cost
END)
) AS ri_sp_trueup,
SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN line_item_unblended_cost
WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN line_item_unblended_cost
ELSE 0
END) AS ri_sp_upfront_fees
FROM
${table_name}
WHERE
${date_filter}
AND line_item_usage_type != 'Route53-Domains'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage','SavingsPlanNegation','SavingsPlanRecurringFee','SavingsPlanUpfrontFee','RIFee','Fee')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
3
ORDER BY
month_line_item_usage_start_date ASC,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide monthly unblended and amortized costs per linked account for all services by region where the service is operating. The query includes ri_sp_trueup and ri_sp_upfront_fees columns to allow you to visualize the difference between unblended and amortized costs. Unblended cost equals usage plus upfront fees. Amortized cost equals usage plus the portion of upfront fees applicable to the period (both used and unused). True-up therefore represents the difference between total upfront fees incurred in the period using an unblended/cash-based accounting model, and the smaller portion of upfront fees applicable to the period using an amortized/accrual-based accounting model. This query excludes discounts, credits, refunds and taxes, as well as Route 53 Domains usage type due to differences in how usage date is recorded between Cost Explorer and CUR. Notes: Notes: Charges for the current billing month may differ slightly when comparing between Cost Explorer and CUR due to differences in how current month charges are estimated. Charges will match between Cost Explorer and CUR once billing has been finalized at the close of the month.This query expects that you have reserved instances purchased within at least one of the accounts. Running this query as is without reserved instances in the CUR data set will result in an error. To use this query without reserved instances, remove or comment out lines containing reservation_reservation_a_r_n. Charges for the current billing month may differ slightly when comparing between Cost Explorer and CUR due to differences in how current month charges are estimated. Charges will match between Cost Explorer and CUR once billing has been finalized at the close of the month. Charges for the current billing month may differ slightly when comparing between Cost Explorer and CUR due to differences in how current month charges are estimated. Charges will match between Cost Explorer and CUR once billing has been finalized at the close of the month. current month charges are estimated This query expects that you have reserved instances purchased within at least one of the accounts. Running this query as is without reserved instances in the CUR data set will result in an error. To use this query without reserved instances, remove or comment out lines containing reservation_reservation_a_r_n. This query expects that you have reserved instances purchased within at least one of the accounts. Running this query as is without reserved instances in the CUR data set will result in an error. To use this query without reserved instances, remove or comment out lines containing reservation_reservation_a_r_n. reservation_reservation_a_r_n?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-01') AS month_line_item_usage_start_date,
CASE product_region
WHEN NULL THEN 'Global'
WHEN '' THEN 'Global'
WHEN 'global' THEN 'Global'
ELSE product_region
END AS product_region,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost,
SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN savings_plan_savings_plan_effective_cost
WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN (savings_plan_total_commitment_to_date - savings_plan_used_commitment)
WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0
WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN 0
WHEN (line_item_line_item_type = 'DiscountedUsage') THEN reservation_effective_cost
WHEN (line_item_line_item_type = 'RIFee') THEN (reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee)
WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN 0
ELSE line_item_unblended_cost
END) AS amortized_cost,
(SUM(line_item_unblended_cost)
- SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN savings_plan_savings_plan_effective_cost
WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN (savings_plan_total_commitment_to_date - savings_plan_used_commitment)
WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0
WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN 0
WHEN (line_item_line_item_type = 'DiscountedUsage') THEN reservation_effective_cost
WHEN (line_item_line_item_type = 'RIFee') THEN (reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee)
WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN 0
ELSE line_item_unblended_cost
END)
) AS ri_sp_trueup,
SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN line_item_unblended_cost
WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN line_item_unblended_cost
ELSE 0
END) AS ri_sp_upfront_fees
FROM
${table_name}
WHERE
${date_filter}
AND line_item_usage_type != 'Route53-Domains'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage','SavingsPlanNegation','SavingsPlanRecurringFee','SavingsPlanUpfrontFee','RIFee','Fee')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
3,
4;
PROMPT: What SQL query corresponds to the following purpose: This query will provide monthly unblended and amortized costs per linked account for all services by service. Data Transfer is also broken out for each service. The query includes ri_sp_trueup and ri_sp_upfront_fees columns to allow you to visualize the difference between unblended and amortized costs. Unblended cost equals usage plus upfront fees. Amortized cost equals usage plus the portion of upfront fees applicable to the period (both used and unused). True-up therefore represents the difference between total upfront fees incurred in the period using an unblended/cash-based accounting model, and the smaller portion of upfront fees applicable to the period using an amortized/accrual-based accounting model. This query excludes discounts, credits, refunds and taxes, as well as Route 53 Domains usage type due to differences in how usage date is recorded between Cost Explorer and CUR. Notes: Notes: Charges for the current billing month may differ slightly when comparing between Cost Explorer and CUR due to differences in how current month charges are estimated. Charges will match between Cost Explorer and CUR once billing has been finalized at the close of the month.This query expects that you have reserved instances purchased within at least one of the accounts. Running this query as is without reserved instances in the CUR data set will result in an error. To use this query without reserved instances, remove or comment out lines containing reservation_reservation_a_r_n. Charges for the current billing month may differ slightly when comparing between Cost Explorer and CUR due to differences in how current month charges are estimated. Charges will match between Cost Explorer and CUR once billing has been finalized at the close of the month. Charges for the current billing month may differ slightly when comparing between Cost Explorer and CUR due to differences in how current month charges are estimated. Charges will match between Cost Explorer and CUR once billing has been finalized at the close of the month. current month charges are estimated This query expects that you have reserved instances purchased within at least one of the accounts. Running this query as is without reserved instances in the CUR data set will result in an error. To use this query without reserved instances, remove or comment out lines containing reservation_reservation_a_r_n. This query expects that you have reserved instances purchased within at least one of the accounts. Running this query as is without reserved instances in the CUR data set will result in an error. To use this query without reserved instances, remove or comment out lines containing reservation_reservation_a_r_n. reservation_reservation_a_r_n?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-01') AS month_line_item_usage_start_date,
CASE
WHEN (line_item_line_item_type = 'Usage' AND product_product_family = 'Data Transfer') THEN CONCAT('DataTransfer-',line_item_product_code)
ELSE line_item_product_code
END AS service_line_item_product_code,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost,
SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN savings_plan_savings_plan_effective_cost
WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN (savings_plan_total_commitment_to_date - savings_plan_used_commitment)
WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0
WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN 0
WHEN (line_item_line_item_type = 'DiscountedUsage') THEN reservation_effective_cost
WHEN (line_item_line_item_type = 'RIFee') THEN (reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee)
WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN 0
ELSE line_item_unblended_cost
END) AS amortized_cost,
(SUM(line_item_unblended_cost)
- SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN savings_plan_savings_plan_effective_cost
WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN (savings_plan_total_commitment_to_date - savings_plan_used_commitment)
WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0
WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN 0
WHEN (line_item_line_item_type = 'DiscountedUsage') THEN reservation_effective_cost
WHEN (line_item_line_item_type = 'RIFee') THEN (reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee)
WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN 0
ELSE line_item_unblended_cost
END)
) AS ri_sp_trueup,
SUM(CASE
WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN line_item_unblended_cost
WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN line_item_unblended_cost
ELSE 0
END) AS ri_sp_upfront_fees
FROM
${table_name}
WHERE
${date_filter}
AND line_item_usage_type != 'Route53-Domains'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage','SavingsPlanNegation','SavingsPlanRecurringFee','SavingsPlanUpfrontFee','RIFee','Fee')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
3,
4
ORDER BY
month_line_item_usage_start_date ASC,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide a monthly cost summary by AWS Service Charge which is an approximation to the monthly bill in the billing console.?
COMPLETION: SELECT
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-01') AS month_line_item_usage_start_date,
bill_bill_type,
CASE
WHEN (product_product_family = 'Data Transfer') THEN 'Data Transfer'
ELSE replace(replace(replace(product_product_name, 'Amazon '),'Amazon'),'AWS ')
END AS product_product_name,
product_location,
line_item_line_item_description,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost,
SUM(line_item_usage_amount) AS sum_line_item_usage_amount
FROM
${table_name}
WHERE
${date_filter}
GROUP BY
1,
bill_bill_type,
3,
product_location,
line_item_line_item_description
HAVING SUM(line_item_usage_amount) > 0
ORDER BY
month_line_item_usage_start_date,
bill_bill_type,
product_product_name,
product_location,
line_item_line_item_description;
PROMPT: What SQL query corresponds to the following purpose: This query will provide a monthly individual account chargeback for the premium support cost based on its contribution to overall AWS bill. This query computes the total monthly aws bill (without tax and support charges) and then calculates just the support charges. Based on the Individual accounts usage/spend percentage, its equivalent support fee is computed.?
COMPLETION: SELECT bill_payer_account_id,
line_item_usage_account_id,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost,
ROUND(total_support_cost *((SUM(line_item_unblended_cost)/total_cost)),2) AS support_cost,
ROUND(SUM(line_item_unblended_cost)/total_cost*100,
2) AS percentage_of_total_cost,
${table_name}.year,
${table_name}.month
FROM ${table_name}
RIGHT JOIN -- Total AWS bill without support
(SELECT SUM(line_item_unblended_cost) AS total_cost,
year,
month
FROM ${table_name}
WHERE line_item_line_item_type <> 'Tax'
AND line_item_product_code <> 'OCBPremiumSupport'
GROUP BY
year,
month) AS aws_total_without_support
ON (${table_name}.year = aws_total_without_support.year AND ${table_name}.month = aws_total_without_support.month)
RIGHT JOIN -- Total support
(SELECT SUM(line_item_unblended_cost) AS total_support_cost,
year,
month
FROM ${table_name}
WHERE line_item_product_code = 'OCBPremiumSupport'
AND line_item_line_item_type <> 'Tax'
GROUP BY year, month ) AS aws_support
ON (${table_name}.year=aws_support.year AND ${table_name}.month = aws_support.month)
WHERE line_item_line_item_type <> 'Tax'
AND line_item_product_code <> 'OCBPremiumSupport'
AND ${table_name}.year = '2020' AND (${table_name}.month BETWEEN '7' AND '9' OR ${table_name}.month BETWEEN '07' AND '09')
GROUP BY
bill_payer_account_id,
total_support_cost,
total_cost,
${table_name}.year,
${table_name}.month,
line_item_usage_account_id
ORDER BY
support_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will aggregate charge types for one or more payers. For more information on various charge types please reference our Cost Explorer documentation. This query will replicate Cost Explorer results when filtering by charge type in the cost explore filters as shown below. Cost Explorer documentation In order to obtain more granular data, try adding the column ‘line_item_line_item_description’ into the SELECT and Group By Sections (see example #2). Note: This query expects that you have reserved instances purchased within at least one of the accounts. This query will not run correctly without reserved instances within the CUR data set. Note:?
COMPLETION: SELECT bill_payer_account_id,
CASE
WHEN (line_item_line_item_type = 'Fee' AND product_product_name = 'AWS Premium Support') THEN 'Support fee'
WHEN (line_item_line_item_type = 'Fee' AND reservation_reservation_a_r_n <> '') THEN 'Upfront reservation fee'
ELSE line_item_line_item_type
END charge_type,
round(sum(line_item_unblended_cost),2) sum_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
GROUP BY
bill_payer_account_id,
2 -- reference to charge_type case statement
ORDER BY
sum_unblended_cost DESC
;
PROMPT: What SQL query corresponds to the following purpose: This query will provide monthly unblended cost for all Serverless products in use across all regions. This query is helpful in tracking Serverless product adoption as application teams modernize their applications. You can expand the query to include line_item_usage_account_id to show individual service charges per linked account. This query helps provide a view that is difficult to achieve within Cost Explorer. Serverless products?
COMPLETION: SELECT
bill_payer_account_id,
-- if uncommenting, also uncomment three other occurrences of line_item_usage_account_id:
-- two in SELECTs that are UNIONed and one in GROUP BY or ^F.
-- line_item_usage_account_id,
month_line_item_usage_start_date,
line_item_product_code,
split_line_item_usage_type,
SUM(CAST(line_item_usage_amount AS double)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS decimal(16,8))) AS sum_line_item_unblended_cost
FROM (
SELECT
bill_payer_account_id,
-- line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
line_item_product_code,
CASE REGEXP_REPLACE(SPLIT_PART(line_item_usage_type, ':', 1), '^[^-]*-')
WHEN 'Fargate-GB-Hours' THEN 'Fargate'
WHEN 'Fargate-vCPU-Hours' THEN 'Fargate'
WHEN 'SpotUsage-Fargate-GB-Hours' THEN 'Fargate'
WHEN 'SpotUsage-Fargate-vCPU-Hours' THEN 'Fargate'
ELSE '--' -- should not be reached!
END AS split_line_item_usage_type,
line_item_usage_amount,
line_item_unblended_cost,
year,
month
FROM ${table_name}
WHERE
(
line_item_line_item_type IN ('DiscountedUsage',
'Usage',
'Credit',
'RIFee',
'SavingsPlanCoveredUsage',
'SavingsPlanNegation')
)
AND
(
line_item_usage_type LIKE '%Fargate%' AND
line_item_product_code IN ('AmazonECS', 'AmazonEKS')
)
UNION ALL
SELECT
bill_payer_account_id,
-- line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
line_item_product_code,
CASE SPLIT_PART(line_item_usage_type, ':', 2)
WHEN 'ProxyUsage' THEN 'RDS Proxy Usage'
WHEN 'ServerlessUsage' THEN 'Aurora Serverless'
ELSE '--'
END AS split_line_item_usage_type,
line_item_usage_amount,
line_item_unblended_cost,
year,
month
FROM ${table_name}
WHERE
(
line_item_line_item_type IN ('DiscountedUsage',
'Usage',
'Credit',
'RIFee',
'SavingsPlanCoveredUsage',
'SavingsPlanNegation')
)
AND
(
(
line_item_product_code = 'AmazonRDS' AND
SPLIT_PART(line_item_usage_type, ':', 2) IN ('ServerlessUsage', 'ProxyUsage')
)
OR
(
line_item_product_code IN ('AmazonDynamoDB', 'AmazonDAX',
'AmazonS3', 'AWSAppSync',
'AmazonApiGateway',
'Amazon Simple Notification Service',
'AWSQueueService', 'AWSLambda',
'AWSEvents'
)
)
)
)
WHERE
${date_filter}
GROUP BY
bill_payer_account_id,
-- line_item_usage_account_id,
month_line_item_usage_start_date,
line_item_product_code,
split_line_item_usage_type
ORDER BY
month_line_item_usage_start_date,
line_item_product_code,
split_line_item_usage_type
PROMPT: What SQL query corresponds to the following purpose: This query provides amortized cost by charge type for a given month. The output includes payer account ID, the month, charge types and the amortized cost for the charge type. It closely matches Cost Explorer result when “show costs as” amortized cost is selected under the advanced options and grouped by charge type.?
COMPLETION: SELECT
bill_payer_account_id,
CASE
WHEN (line_item_line_item_type = 'Fee' AND product_product_name = 'AWS Premium Support') THEN 'Support fee'
WHEN (line_item_line_item_type = 'Fee' AND bill_billing_entity <> 'AWS') THEN 'Marketplace fee'
WHEN (line_item_line_item_type = 'DiscountedUsage') THEN 'Reservation applied usage'
ELSE line_item_line_item_type
END charge_type,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m') AS month_line_item_usage_start_date
,
round(sum(CASE
WHEN (line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN savings_plan_savings_plan_effective_cost
WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN round((savings_plan_total_commitment_to_date - savings_plan_used_commitment),8)
WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0
WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN 0
WHEN (line_item_line_item_type = 'DiscountedUsage') THEN reservation_effective_cost
WHEN (line_item_line_item_type = 'RIFee') THEN (reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee)
WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN 0 ELSE line_item_unblended_cost END),2) sum_amortized_cost
FROM
${table_name}
WHERE
${date_filter}
GROUP BY
bill_payer_account_id,
2, -- month_line_item_usage_start_date
3 -- sum_amortized_cost
ORDER BY
sum_amortized_cost DESC
;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended and usage information per linked account for Amazon Rekognition. The output will include detailed information about the usage type and usage region. The cost will be summed by day, account, and usage type, and displayed in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
line_item_usage_type,
product_region,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
{$table_name}
WHERE
${date_filter}
AND line_item_product_code = 'AmazonRekognition'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_usage_type,
product_region
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended cost and usage information per resource ID for Amazon SageMaker. The output will include detailed information about associated usage types. The cost and usage will be summed by day, account, resource ID, and usage type, and displayed in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
line_item_resource_id,
line_item_usage_type,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
{$table_name}
WHERE
${date_filter}
AND line_item_product_code = 'AmazonSageMaker'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_resource_id,
line_item_usage_type
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended and usage information per linked account for Amazon Textract. The output will include detailed information about the usage type and usage region. The cost and usage will be summed by day, account, and usage type, and displayed in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
line_item_usage_type,
product_region,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
{$table_name}
WHERE
${date_filter}
AND line_item_product_code = 'AmazonTextract'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_usage_type,
product_region
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended and usage information per linked account for AWS Config. The output will include detailed information about the usage type and usage region. The cost will be summed by day, account, and usage type.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
product_region,
CASE
WHEN line_item_usage_type LIKE '%%ConfigurationItemRecorded%%' THEN 'ConfigurationItemRecorded'
WHEN line_item_usage_type LIKE '%%ActiveConfigRules%%' THEN 'ActiveConfigRules'
WHEN line_item_usage_type LIKE '%%SecurityHubConfigRules%%' THEN 'SecurityHubConfigRules'
WHEN line_item_usage_type LIKE '%%ConfigRuleEvaluations%%' THEN 'ConfigRuleEvaluations'
ELSE 'Others'
END AS case_line_item_usage_type,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${tableName}
WHERE
(year = '2020' AND month IN ('1','01') OR year = '2020' AND month IN ('2','02'))
AND product_product_name = 'AWS Config'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
product_region,
line_item_usage_type
ORDER BY
day_line_item_usage_start_date,
sum_line_item_usage_amount,
sum_line_item_unblended_cost,
case_line_item_usage_type;
PROMPT: What SQL query corresponds to the following purpose: This query will provide monthly unblended and usage information per linked account for AWS CloudTrail. The output will include detailed information about the usage type and usage region. The cost will be summed by month, account, and usage type, and displayed in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
product_product_name,
SPLIT_PART(line_item_usage_type,'-',2) AS split_line_item_usage_type,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM ${table_name}
WHERE
${date_filter}
AND product_product_name = 'AWS CloudTrail'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
SPLIT_PART(line_item_usage_type,'-',2),
product_product_name
ORDER BY
sum_line_item_unblended_cost DESC,
month_line_item_usage_start_date,
sum_line_item_usage_amount;
PROMPT: What SQL query corresponds to the following purpose: This query will provide monthly unblended and usage information per linked account for AWS CloudWatch. The output will include detailed information about the usage type. The cost will be summed by month, account, and usage type, and displayed in descending order. Resource ID can also be included by uncommenting the appropriate lines in the query. Resource ID can also be included by uncommenting the appropriate lines in the query.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') month_line_item_usage_start_date,
CASE
WHEN line_item_usage_type LIKE '%%Requests%%' THEN 'Requests'
WHEN line_item_usage_type LIKE '%%DataProcessing-Bytes%%' THEN 'DataProcessing'
WHEN line_item_usage_type LIKE '%%TimedStorage-ByteHrs%%' THEN 'Storage'
WHEN line_item_usage_type LIKE '%%DataScanned-Bytes%%' THEN 'DataScanned'
WHEN line_item_usage_type LIKE '%%AlarmMonitorUsage%%' THEN 'AlarmMonitors'
WHEN line_item_usage_type LIKE '%%DashboardsUsageHour%%' THEN 'Dashboards'
WHEN line_item_usage_type LIKE '%%MetricMonitorUsage%%' THEN 'MetricMonitor'
WHEN line_item_usage_type LIKE '%%VendedLog-Bytes%%' THEN 'VendedLogs'
WHEN line_item_usage_type LIKE '%%GMD-Metrics%%' THEN 'GetMetricData'
ELSE 'Others'
END AS line_item_usage_type,
-- if uncommenting, also uncomment one other occurrence of line_item_resource_id in GROUP BY
-- SPLIT_PART(line_item_resource_id,':',7) as ResourceID,
line_item_operation,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM ${tableName}
WHERE
${date_filter}
AND product_product_name = 'AmazonCloudWatch'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
line_item_usage_type,
-- line_item_resource_id,
line_item_operation
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: Amazon Web Services publishes our most up-to-the-minute information on our Service Health Dashboard. This dashboard is based on region and service. While we try to notify you of ongoing problems that may be impactful to your workloads via your Personal Health Dashboard you may want to proactively check where you currently have service usage and cost that may be impacted by our event or another regional issue. Service Health Dashboard Personal Health Dashboard This Regional Service Usage Mapping query transforms your billing data into a summarized view of your usage of AWS services by region and availability zone, providing your operations teams with the ability to respond quickly and accurately during impacting service events.?
COMPLETION: SELECT
CASE
WHEN (bill_billing_entity = 'AWS Marketplace' AND line_item_line_item_type NOT LIKE '%Discount%') THEN product_product_name
WHEN (product_product_name = '') THEN line_item_product_code
ELSE product_product_name
END AS product_name,
CASE product_region
WHEN NULL THEN 'Global'
WHEN '' THEN 'Global'
WHEN 'global' THEN 'Global'
ELSE product_region
END AS product_region,
line_item_availability_zone,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
1,
line_item_product_code,
line_item_availability_zone,
product_region
HAVING
SUM(line_item_unblended_cost) > 0
ORDER BY
product_region,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will return a the percentage of resources which are tagged by linked account and product for a specific tag. This will help you determine how good your tagging quality is. For example, if they wish to use to use this field for chargeback or automation. Currently this using the resource_tags_user_name tag but this can be swapped out for any other tags in your CUR. To see these tags use this query: resource_tags_user_name SELECT column_name
FROM information_schema.columns
WHERE table_schema = '${database_name}'
AND table_name = '${table_name}'
AND column_name LIKE 'resource_tags%'
SELECT column_name
FROM information_schema.columns
WHERE table_schema = '${database_name}'
AND table_name = '${table_name}'
AND column_name LIKE 'resource_tags%'
SELECT column_name
FROM information_schema.columns
WHERE table_schema = '${database_name}'
AND table_name = '${table_name}'
AND column_name LIKE 'resource_tags%'
SELECT FROM WHERE = '${database_name}' AND = '${table_name}' AND LIKE 'resource_tags%'?
COMPLETION: WITH allresources AS (
SELECT
line_item_usage_account_id
, line_item_product_code
, count(DISTINCT line_item_resource_id) AS count_resource
, CASE
WHEN resource_tags_user_name = '' THEN 'NoTag'
ELSE 'Tag'
END AS Tag_Status
FROM ${table_name}
WHERE ${date_filter}
GROUP BY line_item_usage_account_id, line_item_product_code, 4 -- 4 represents the Tag_Status column
)
SELECT
line_item_usage_account_id
, line_item_product_code
, sum(count_resource) AS "resources"
, sum(CASE WHEN Tag_Status = 'Tag' THEN count_resource ELSE 0 END) AS "tagged_resources"
, round(sum(CASE WHEN Tag_Status = 'Tag' THEN CAST(count_resource AS double) ELSE 0. END)/ sum(count_resource) * 100., 1) AS "percentage_tagged"
FROM allresources
GROUP BY 1,2
PROMPT: What SQL query corresponds to the following purpose: This query provides daily unblended cost and usage information about Amazon API Gateway usage including the resource id. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
SPLIT_PART(line_item_resource_id, 'apis/', 2) AS split_line_item_resource_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d') AS day_line_item_usage_start_date,
CASE
WHEN line_item_usage_type LIKE '%%ApiGatewayRequest%%' OR line_item_usage_type LIKE '%%ApiGatewayHttpRequest%%' THEN 'Requests'
WHEN line_item_usage_type LIKE '%%DataTransfer%%' THEN 'Data Transfer'
WHEN line_item_usage_type LIKE '%%Message%%' THEN 'Messages'
WHEN line_item_usage_type LIKE '%%Minute%%' THEN 'Minutes'
WHEN line_item_usage_type LIKE '%%CacheUsage%%' THEN 'Cache Usage'
ELSE 'Other'
END AS case_line_item_usage_type,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'Amazon API Gateway'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d'),
line_item_resource_id,
line_item_usage_type
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides daily unblended cost and usage information about Amazon CloudFront usage including the distribution name, region, and operation. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d') AS day_line_item_usage_start_date,
product_region,
product_product_family, -- NOTE: product_product_family used in place of large line_item_usage_type CASE
line_item_operation,
SPLIT_PART(line_item_resource_id, 'distribution/', 2) AS split_line_item_resource_id,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_product_code = 'AmazonCloudFront'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d'),
product_region,
product_product_family,
line_item_operation,
line_item_resource_id
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides daily unblended cost and usage information about Data Transfer usage including resource id that sourced the traffic, the product code corresponding to the source traffic, and the to/from locations of the usage. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
line_item_product_code,
line_item_usage_account_id ,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d') AS date_line_item_usage_start_date,
line_item_usage_type,
product_from_location,
product_to_location,
product_product_family,
line_item_resource_id,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM ${tableName}
WHERE
${date_filter}
AND product_product_family = 'Data Transfer'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
line_item_product_code,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date, '%Y-%m-%d'),
line_item_resource_id,
line_item_usage_type,
product_from_location,
product_to_location,
product_product_family
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides monthly unblended cost and usage information about Data Transfer Regional (Inter AZ) usage including resource id that sourced the traffic and the product code corresponding to the source traffic. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m') AS day_line_item_usage_start_date,
line_item_product_code,
product_product_family,
product_region,
line_item_line_item_description,
line_item_resource_id,
sum(line_item_unblended_cost) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_line_item_description LIKE '%regional data transfer%'
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m'),
line_item_product_code,
product_product_family,
product_region,
line_item_line_item_description,
line_item_resource_id
ORDER BY
sum_line_item_unblended_cost DESC
;
PROMPT: What SQL query corresponds to the following purpose: This query provides monthly unblended cost and usage information about Data Transfer related to Amazon MSK including resource id. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
line_item_product_code,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d') AS date_line_item_usage_start_date,
line_item_resource_id,
line_item_usage_type,
line_item_line_item_description,
product_product_family,
SUM(line_item_usage_amount)/1024 AS sum_line_item_usage_amount,
ROUND(SUM(line_item_unblended_cost),2) AS sum_line_item_unblended_cost
FROM ${table_name}
WHERE
${date_filter}
AND line_item_product_code = 'AmazonMSK'
AND line_item_usage_type LIKE '%DataTransfer%'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
line_item_product_code,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date, '%Y-%m-%d'),
line_item_resource_id,
line_item_usage_type,
product_product_family,
line_item_line_item_description
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides monthly unblended cost and usage information about NAT Gateway Usage including resource id. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
line_item_resource_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
CASE
WHEN line_item_usage_type LIKE '%%NatGateway-Bytes' THEN 'NAT Gateway Data Processing Charge' -- Charge for per GB data processed by NatGateways
WHEN line_item_usage_type LIKE '%%NatGateway-Hours' THEN 'NAT Gateway Hourly Charge' -- Hourly charge for NAT Gateways
ELSE line_item_usage_type
END AS line_item_usage_type,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_family = 'NAT Gateway'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
line_item_resource_id,
line_item_usage_type
ORDER BY
sum_line_item_unblended_cost DESC,
sum_line_item_usage_amount;
PROMPT: What SQL query corresponds to the following purpose: This query shows cost and usage of NAT Gateways which didn’t receive any traffic last month and ran for more than 336 hrs. Resources returned by this query could be considered for deletion.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
SPLIT_PART(line_item_resource_id, ':', 6) split_line_item_resource_id,
product_region,
pricing_unit,
sum_line_item_usage_amount,
CAST(cost_per_resource AS DECIMAL(16, 8)) AS sum_line_item_unblended_cost
FROM
(
SELECT
line_item_resource_id,
product_region,
pricing_unit,
line_item_usage_account_id,
bill_payer_account_id,
SUM(line_item_usage_amount) AS sum_line_item_usage_amount,
SUM(SUM(line_item_unblended_cost)) OVER (PARTITION BY line_item_resource_id) AS cost_per_resource,
SUM(SUM(line_item_usage_amount)) OVER (PARTITION BY line_item_resource_id, pricing_unit) AS usage_per_resource_and_pricing_unit,
COUNT(pricing_unit) OVER (PARTITION BY line_item_resource_id) AS pricing_unit_per_resource
FROM
${table_name}
WHERE
line_item_product_code = 'AmazonEC2'
AND line_item_usage_type LIKE '%Nat%'
-- get previous month
AND CAST(month AS INT) = CAST(month(current_timestamp + -1 * INTERVAL '1' MONTH) AS INT)
-- get year for previous month
AND CAST(year AS INT) = CAST(year(current_timestamp + -1 * INTERVAL '1' MONTH) AS INT)
AND line_item_line_item_type = 'Usage'
GROUP BY
line_item_resource_id,
product_region,
pricing_unit,
line_item_usage_account_id,
bill_payer_account_id
)
WHERE
-- filter only resources which ran more than half month (336 hrs)
usage_per_resource_and_pricing_unit > 336
AND pricing_unit_per_resource = 1
ORDER BY
cost_per_resource DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides monthly unblended cost and usage information about AWS Transit Gateway Usage including attachment type, and resource id. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
CASE
WHEN line_item_resource_id LIKE 'arn%' THEN CONCAT(SPLIT_PART(line_item_resource_id,'/',2),' - ',product_location)
ELSE CONCAT(line_item_resource_id,' - ',product_location)
END AS line_item_resource_id,
product_location,
product_attachment_type,
pricing_unit,
CASE
WHEN pricing_unit = 'hour' THEN 'Hourly charges'
WHEN pricing_unit = 'GigaBytes' THEN 'Data processing charges'
END AS pricing_unit,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_group = 'AWSTransitGateway'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
line_item_resource_id,
product_location,
product_attachment_type,
pricing_unit
ORDER BY
sum_line_item_unblended_cost DESC,
month_line_item_usage_start_date,
sum_line_item_usage_amount,
product_attachment_type;
PROMPT: What SQL query corresponds to the following purpose: This query provides daily unblended cost and usage information about AWS Network Usage including VPCPeering, PublicIP, InterZone, LoadBalancing, and resource id. Usage will be in ascending order and cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
line_item_operation,
line_item_resource_id,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_operation IN (
'LoadBalancing-PublicIP-In',
'LoadBalancing-PublicIP-Out',
'InterZone-In',
'InterZone-Out',
'PublicIP-In',
'PublicIP-Out',
'VPCPeering-In',
'VPCPeering-Out'
)
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_operation,
line_item_resource_id
ORDER BY
day_line_item_usage_start_date ASC,
sum_line_item_usage_amount DESC,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query shows cost and usage of inbalance inter-az data transfer last month. These resources are commonly collectors or aggregators mostly receiving data from other resources in different Availability Zones. Distributing the resource functionality to each of the Availability Zones and redirect the data transfer from sending sources to be within the same Availability Zone will eliminate the $0.01/GB data transfer charges between Availability Zones.?
COMPLETION: SELECT
line_item_usage_account_id as "account",
product_region as "region",
line_item_resource_id as "resource",
round (sum (IF ((line_item_operation = 'InterZone-In'), line_item_unblended_cost, 0)), 2) as "interaz_in_cost",
round (sum (IF ((line_item_operation = 'InterZone-Out'), line_item_unblended_cost, 0)), 2) as "interaz_out_cost"
FROM $(table_name)
WHERE (line_item_usage_type LIKE '%DataTransfer-Regional-Bytes%')
and (line_item_line_item_type = 'Usage')
and ((line_item_operation = 'InterZone-In') or (line_item_operation = 'InterZone-Out'))
and (month(bill_billing_period_start_date) = month((current_date) - INTERVAL '1' month))
and (year(bill_billing_period_start_date) = year((current_date) - INTERVAL '1' month))
GROUP BY line_item_usage_account_id, product_region, line_item_resource_id
HAVING ((round (sum (IF ((line_item_operation LIKE 'InterZone-In'), line_item_unblended_cost, 0)), 2) / (round (sum (IF ((line_item_operation LIKE 'InterZone-Out'), line_item_unblended_cost, 0)), 2))) > 20)
and ((round (sum (IF ((line_item_operation LIKE 'InterZone-In'), line_item_unblended_cost, 0)), 2)) > 1000)
ORDER BY "interaz_in_cost" DESC, "interaz_out_cost" DESC, account ASC, region ASC, resource ASC
PROMPT: What SQL query corresponds to the following purpose: This query shows cost and usage of Interface Endpoints which did not receive significant traffic last month. Resources returned by this query could be considered for deletion or rearchitecture for centralized deployment.?
COMPLETION: SELECT
line_item_usage_account_id as "account",
product_region as "region",
split_part(line_item_resource_id, ':', 6) as "resource",
round (sum (IF ((line_item_usage_type LIKE '%Endpoint-Hour%'), line_item_unblended_cost, 0)), 2) as "hourly_cost",
round (sum (IF ((line_item_usage_type LIKE '%Endpoint-Bytes%'), line_item_blended_cost, 0)), 2) as "traffic_cost"
FROM ${table_name}
WHERE (line_item_product_code = 'AmazonVPC')
and (line_item_line_item_type = 'Usage')
and ((line_item_usage_type LIKE '%Endpoint-Hour%') or (line_item_usage_type LIKE '%Endpoint-Byte%'))
and (month(bill_billing_period_start_date) = month((current_date) - INTERVAL '1' month))
and (year(bill_billing_period_start_date) = year((current_date) - INTERVAL '1' month))
GROUP BY line_item_usage_account_id, product_region, line_item_resource_id
HAVING ((round (sum (IF ((line_item_usage_type LIKE '%Endpoint-Hour%'), line_item_unblended_cost, 0)), 2) / (round (sum (IF ((line_item_usage_type LIKE '%Endpoint-Bytes%'), line_item_blended_cost, 0)), 2))) > 20)
ORDER BY "hourly_cost" DESC, "traffic_cost" DESC, account ASC, region ASC, resource ASC
PROMPT: What SQL query corresponds to the following purpose: This query shows cost and usage of Network Firewall Endpoints which did not receive significant traffic last month. Resources returned by this query could be considered for deletion or rearchitecture for centralized deployment.?
COMPLETION: SELECT
line_item_usage_account_id as "account",
product_region as "region",
split_part(line_item_resource_id, ':', 6) as "resource",
round (sum (IF ((line_item_usage_type LIKE '%Endpoint-Hour%'), line_item_unblended_cost, 0)), 2) as "hourly_cost",
round (sum (IF ((line_item_usage_type LIKE '%Traffic-GB%'), line_item_unblended_cost, 0)), 2) as "traffic_cost"
FROM ${table_name}
WHERE (line_item_product_code = 'AWSNetworkFirewall')
and (line_item_line_item_type = ('Usage'))
and ((line_item_usage_type LIKE '%Endpoint-Hour%') or (line_item_usage_type LIKE '%Traffic-GB%'))
and (month(bill_billing_period_start_date) = month((current_date) - INTERVAL '1' month))
and (year(bill_billing_period_start_date) = year((current_date) - INTERVAL '1' month))
GROUP BY line_item_usage_account_id, product_region, line_item_resource_id
HAVING (round (sum (IF ((line_item_usage_type LIKE '%Endpoint-Hour%'), line_item_unblended_cost, 0)), 2)/round (sum (IF ((line_item_usage_type LIKE '%Traffic-GB%'), line_item_unblended_cost, 0)), 2) > 20)
ORDER BY "hourly_cost" DESC, "traffic_cost" DESC, account ASC, region ASC, resource ASC
PROMPT: What SQL query corresponds to the following purpose: This query provides daily unblended cost and usage information about AWS CodeBuild Usage. The usage amount and cost will be summed.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
line_item_resource_id,
line_item_usage_type,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM ${table_name}
WHERE ${date_filter}
AND line_item_product_code = 'CodeBuild'
GROUP BY
1, 2, 3, 4, 5
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides daily unblended cost and usage information about Amazon GuardDuty Usage. The usage amount and cost will be summed.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
line_item_usage_type,
TRIM(REPLACE(product_group, 'Security Services - Amazon GuardDuty ', '')) AS trim_product_group,
pricing_unit,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${tableName}
WHERE
${date_filter}
AND product_product_name = 'Amazon GuardDuty'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_usage_type,
product_group,
pricing_unit
ORDER BY
day_line_item_usage_start_date,
sum_line_item_usage_amount,
sum_line_item_unblended_cost,
trim_product_group;
PROMPT: What SQL query corresponds to the following purpose: This query provides daily unblended cost and usage information about Amazon Cognito Usage. The usage amount and cost will be summed.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
product_product_name,
line_item_operation,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${tableName}
WHERE
${date_filter}
AND product_product_name = 'Amazon Cognito'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
product_product_name,
line_item_operation
ORDER BY
day_line_item_usage_start_date,
sum_line_item_usage_amount,
sum_line_item_unblended_cost,
line_item_operation;
PROMPT: What SQL query corresponds to the following purpose: AWS Shield Advanced is a paid service that provides additional protections for internet-facing applications. See AWS Shield Pricing Page for details. AWS Shield Advanced charges a monthly fee, plus a usage fee based on data transfer out. The result generated by the query below will contain the resource’s ID and protected resource type. This information enables customers to identify the primary account and resource responsible for the majority of their AWS Shield cost. AWS Shield Pricing Page?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
line_item_resource_id,
line_item_operation,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
line_item_product_code = 'AWSShield'
AND product_product_family IN ('Shield-DataTransfer', 'Shield Advanced Monthly Fee')
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
${date_filter}
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
line_item_resource_id,
line_item_operation
ORDER BY
sum_line_item_unblended_cost DESC,
line_item_resource_id
;
PROMPT: What SQL query corresponds to the following purpose: This query provides daily unblended cost and usage information about AWS WAF Usage including web acl, rule id, and region. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d') AS day_line_item_usage_start_date,
SPLIT_PART(SPLIT_PART(line_item_resource_id,'/',2),'+',1) AS split_webaclid_line_item_resource_id,
SPLIT_PART(SPLIT_PART(line_item_resource_id,'/',2),'+',2) AS split_ruleid_line_item_resource_id,
line_item_usage_type,
product_group,
product_group_description,
product_location,
product_location_type,
line_item_line_item_description,
pricing_unit,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${tableName}
WHERE
${date_filter}
AND product_product_name = 'AWS WAF'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d'),
line_item_resource_id,
line_item_usage_type,
product_group,
product_group_description,
product_location,
product_location_type,
line_item_line_item_description,
pricing_unit
ORDER BY
day_line_item_usage_start_date,
sum_line_item_usage_amount,
sum_line_item_unblended_cost,
product_group;
PROMPT: What SQL query corresponds to the following purpose: This query provides daily unblended cost and usage information for Amazon S3. The output will include detailed information about the resource id (bucket name), operation, and usage type. The usage amount and cost will be summed, and rows will be sorted by cost (descending).?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
line_item_resource_id,
line_item_operation,
CASE
--S3 Early Delete
WHEN line_item_usage_type LIKE '%EarlyDelete-ByteHrs' THEN 'Early Delete Glacier'
WHEN line_item_usage_type LIKE '%EarlyDelete%' THEN 'Early Delete ' || SPLIT_PART(line_item_usage_type,'EarlyDelete-',2)
--S3 Requests
WHEN line_item_usage_type LIKE '%Requests-INT%' THEN 'Requests INT'
WHEN (line_item_usage_type LIKE '%Requests-Tier1' OR line_item_usage_type LIKE '%Requests-Tier2') THEN 'Requests Standard'
WHEN (line_item_usage_type LIKE '%Requests-GLACIER%' OR line_item_usage_type LIKE '%Requests-Tier3' OR line_item_usage_type LIKE '%Requests-Tier5' OR line_item_usage_type LIKE '%Requests-Tier6') THEN 'Requests Glacier'
WHEN line_item_usage_type LIKE '%Requests-GDA%' THEN 'Requests GDA'
WHEN line_item_usage_type LIKE '%Requests-GIR%' THEN 'Requests GIR'
WHEN (line_item_usage_type LIKE '%Requests-Tier4' OR line_item_usage_type LIKE '%Requests-SIA%') THEN 'Requests SIA'
WHEN line_item_usage_type LIKE '%Requests-ZIA%' THEN 'Requests ZIA'
--S3 Retrieval
WHEN (line_item_usage_type LIKE '%Retrieval-Bytes' AND line_item_operation = 'RestoreObject') THEN 'Retrieval Glacier'
WHEN (line_item_usage_type LIKE '%Retrieval-Bytes' AND line_item_operation = 'DeepArchiveRestoreObject') THEN 'Retrieval GDA'
WHEN line_item_usage_type LIKE '%Retrieval%' THEN 'Retrieval ' || SPLIT_PART(line_item_usage_type,'Retrieval-',2)
--S3 Storage
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'StandardStorage') THEN 'Storage Standard'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'StandardIAStorage') THEN 'Storage SIA'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'StandardIASizeOverhead') THEN 'Storage SIA-Overhead'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'OneZoneIAStorage') THEN 'Storage ZIA'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'OneZoneIASizeOverhead') THEN 'Storage ZIA-Overhead'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'GlacierInstantRetrievalStorage') THEN 'Storage GIR'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'GlacierIRSizeOverhead') THEN 'Storage GIR-Overhead'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'GlacierStorage') THEN 'Storage Glacier'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'GlacierStagingStorage') THEN 'Storage Glacier-Staging'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND (line_item_operation = 'GlacierObjectOverhead' or line_item_operation = 'GlacierS3ObjectOverhead')) THEN 'Storage Glacier-Overhead'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'RestoreObject') THEN 'Storage Glacier-Restored'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'DeepArchiveStorage') THEN 'Storage GDA'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'DeepArchiveStagingStorage') THEN 'Storage GDA-Staging'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND (line_item_operation = 'DeepArchiveObjectOverhead' or line_item_operation = 'DeepArchiveS3ObjectOverhead')) THEN 'Storage GDA-Overhead'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'DeepArchiveRestoreObject') THEN 'Storage GDA-Restored'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation = 'ReducedRedundancyStorage') THEN 'Storage RRS'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation LIKE 'IntelligentTieringAA%') THEN 'Storage INT-AA'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND (line_item_operation = 'IntAAObjectOverhead' or line_item_operation = 'IntAAS3ObjectOverhead')) THEN 'Storage INT-AA-Overhead'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation LIKE 'IntelligentTieringDAA%') THEN 'Storage INT-DAA'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND (line_item_operation = 'IntDAAObjectOverhead' or line_item_operation = 'IntDAAS3ObjectOverhead')) THEN 'Storage INT-DAA-Overhead'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation LIKE 'IntelligentTieringFA%') THEN 'Storage INT-FA'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation LIKE 'IntelligentTieringIA%') THEN 'Storage INT-IA'
WHEN (line_item_usage_type LIKE '%TimedStorage%' AND line_item_operation LIKE 'IntelligentTieringAIA%') THEN 'Storage INT-AIA'
--Data Transfer
WHEN line_item_usage_type LIKE '%AWS-In-Bytes%' THEN 'Data Transfer Region to Region (In)'
WHEN line_item_usage_type LIKE '%AWS-In-ABytes%'THEN 'Data Transfer Accelerated Region to Region (In)'
WHEN line_item_usage_type LIKE '%AWS-Out-Bytes%' THEN 'Data Transfer Region to Region (Out)'
WHEN line_item_usage_type LIKE '%AWS-Out-ABytes%' THEN 'Data Transfer Accelerated Region to Region (Out)'
WHEN line_item_usage_type LIKE '%CloudFront-In-Bytes%' THEN 'Data Transfer CloudFront (In)'
WHEN line_item_usage_type LIKE '%CloudFront-Out-Bytes%' THEN 'Data Transfer CloudFront (Out)'
WHEN line_item_usage_type LIKE '%DataTransfer-Regional-Bytes%' THEN 'Data Transfer Inter AZ'
WHEN line_item_usage_type LIKE '%DataTransfer-In-Bytes%' THEN 'Data Transfer Internet (In)'
WHEN line_item_usage_type LIKE '%DataTransfer-Out-Bytes%' THEN 'Data Transfer Internet (Out)'
WHEN line_item_usage_type LIKE '%DataTransfer-In-ABytes%' THEN 'Data Transfer Accelerated Internet (In)'
WHEN line_item_usage_type LIKE '%DataTransfer-Out-ABytes%' THEN 'Data Transfer Accelerated Internet (Out)'
WHEN line_item_usage_type LIKE '%S3RTC-In-Bytes%' THEN 'Data Transfer Replication Time Control (In)'
WHEN line_item_usage_type LIKE '%S3RTC-Out-Bytes%' THEN 'Data Transfer Replication Time Control (Out)'
--S3 Fees & Misc
WHEN line_item_usage_type LIKE '%Monitoring-Automation-INT' THEN 'S3 INT Monitoring Fee'
WHEN line_item_usage_type LIKE '%StorageAnalytics%' THEN 'S3 Storage Analytics'
WHEN line_item_usage_type LIKE '%BatchOperations-Jobs%' THEN 'S3 Batch Operations-Jobs'
WHEN line_item_usage_type LIKE '%BatchOperations-Objects%' THEN 'S3 Batch Operations-Objects'
WHEN line_item_usage_type LIKE '%TagStorage%' THEN 'S3 Tag Storage'
WHEN (line_item_usage_type LIKE '%Select-Returned%' OR line_item_usage_type LIKE '%Select-Scanned%') THEN 'S3 Select'
WHEN line_item_usage_type LIKE '%Inventory%' THEN 'S3 Inventory'
WHEN line_item_operation LIKE '%StorageLens%' THEN 'Storage Lens'
ELSE 'Other ' || line_item_usage_type
END as case_line_item_usage_type,
SUM(CAST(line_item_usage_amount AS double)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS decimal(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_product_code = 'AmazonS3'
AND line_item_line_item_type in ('DiscountedUsage','Usage', 'SavingsPlanCoveredUsage')
AND product_product_family != 'Data Transfer'
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_resource_id,
line_item_operation,
6 --refers to case_line_item_usage_type
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides an overview of cost and usage for Amazon EC2 EBS. Output includes daily unblended cost and usage quantity by payer account, linked account, usage type, and resource ID. The usage amount and cost will be summed, and rows will be sorted by day (ascending), then cost (descending).?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
CASE
WHEN line_item_usage_type LIKE '%SnapshotUsage%' THEN 'Snapshots'
WHEN line_item_usage_type LIKE '%VolumeIOUsage%' THEN 'Magnetic IO'
WHEN line_item_usage_type LIKE '%VolumeUsage' THEN 'Magnetic'
WHEN line_item_usage_type LIKE '%VolumeUsage.gp2' THEN 'GP2'
WHEN line_item_usage_type LIKE '%VolumeUsage.gp3' THEN 'GP3'
WHEN line_item_usage_type LIKE '%VolumeP-IOPS.gp3' THEN 'GP3 IOPS'
WHEN line_item_usage_type LIKE '%VolumeP-Throughput.gp3' THEN 'GP3 Throughput'
WHEN line_item_usage_type LIKE '%VolumeUsage.piops' THEN 'io1'
WHEN line_item_usage_type LIKE '%VolumeP-IOPS.piops' THEN 'io1 IOPS'
WHEN line_item_usage_type LIKE '%VolumeUsage.io2%' THEN 'io2'
WHEN line_item_usage_type LIKE '%VolumeP-IOPS.io2%' THEN 'io2 IOPS'
WHEN line_item_usage_type LIKE '%VolumeUsage.st1' THEN 'st1'
WHEN line_item_usage_type LIKE '%VolumeUsage.sc1' THEN 'sc1'
WHEN line_item_usage_type LIKE '%directAPI%' THEN 'Direct API Requests'
WHEN line_item_usage_type LIKE '%FastSnapshotRestore' THEN 'Fast Snapshot Restore'
ELSE SPLIT_PART(line_item_usage_type,':',2)
END AS case_line_item_usage_type,
CASE
WHEN line_item_resource_id LIKE '%snap%' THEN SPLIT_PART(line_item_resource_id,'/',2)
ELSE line_item_resource_id
END AS case_line_item_resource_id,
SUM(line_item_usage_amount) AS sum_line_item_usage_amount,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost
FROM
{$tableName}
WHERE
{$date_filter}
AND line_item_product_code = 'AmazonEC2' AND line_item_usage_type LIKE '%EBS:%'
AND line_item_line_item_type = 'Usage'
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
4, --refers to case_line_item_usage_type
5 --refers to case_line_item_resource_id
ORDER BY
day_line_item_usage_start_date ASC,
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides daily unblended cost and usage information about Amazon EBS Snapshot Usage per account including region. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d') AS date_line_item_usage_start_date,
product_region,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${tableName}
WHERE
${date_filter}
AND product_product_name = 'Amazon Elastic Compute Cloud'
AND line_item_usage_type LIKE '%%EBS%%Snapshot%%'
AND product_product_family LIKE 'Storage Snapshot'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m-%d'),
product_region
ORDER BY
sum_line_item_unblended_cost DESC,
sum_line_item_usage_amount DESC,
date_line_item_usage_start_date ASC;
PROMPT: What SQL query corresponds to the following purpose: This query helps correlate cross-region data transfer cost and usage with EBS Snapshot Copy operations for specific EBS snapshots. Understanding the amount of data transfer associated with specific snapshots, and tangentially how much data change is happening on the associated volume, can be used to inform changes to snapshotting strategy. The query provides total unblended cost and usage information grouped by snapshot, usage type, and line item description. Output is sorted by cost in descending order.?
COMPLETION: SELECT
line_item_resource_id,
line_item_usage_type,
line_item_line_item_description,
SUM(line_item_usage_amount) as sum_line_item_usage_amount,
SUM(line_item_unblended_cost) as sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND line_item_operation = 'EBS Snapshot Copy'
GROUP BY
line_item_resource_id,
line_item_usage_type,
line_item_line_item_description
ORDER BY
SUM(line_item_unblended_cost) DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides daily unblended cost and usage information about Amazon EBS Volume Usage per account. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
CASE SPLIT_PART(line_item_usage_type,':',2)
WHEN 'VolumeUsage' THEN 'EBS - Magnetic'
WHEN 'VolumeIOUsage' THEN 'EBS Magnetic IO'
WHEN 'VolumeUsage.gp2' THEN 'EBS GP2'
WHEN 'VolumeUsage.gp3' THEN 'EBS GP3'
WHEN 'VolumeP-IOPS.gp3' THEN 'EBS GP3 IOPS'
WHEN 'VolumeP-Throughput.gp3' THEN 'EBS GP3 Throughput'
WHEN 'VolumeUsage.piops' THEN 'EBS io1'
WHEN 'VolumeP-IOPS.piops' THEN 'EBS io1 IOPS'
WHEN 'VolumeUsage.io2' THEN 'EBS io2'
WHEN 'VolumeP-IOPS.io2' THEN 'EBS io2 IOPS'
WHEN 'VolumeUsage.st1' THEN 'EBS st1'
WHEN 'VolumeUsage.sc1' THEN 'EBS sc1'
WHEN 'directAPI' THEN 'EBS Direct API Requests'
WHEN 'FastSnapshotRestore' THEN 'EBS Fast Snapshot Restore'
ELSE SPLIT_PART(line_item_usage_type,':',2)
END AS line_item_usage_type,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${tableName}
WHERE
${date_filter}
AND product_product_name = 'Amazon Elastic Compute Cloud'
AND line_item_usage_type LIKE '%%EBS%%Volume%%'
AND product_product_family IN ('Storage','System Operation')
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m'),
line_item_usage_type
ORDER BY
sum_line_item_unblended_cost DESC;
PROMPT: What SQL query corresponds to the following purpose: This query provides monthly ratio of unblended cost and usage information between Amazon EBS Volume vs Amazon EBS Snapshots Usage per account and region. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id ,
line_item_usage_account_id,
DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date,
CASE
WHEN product_product_family = 'Storage' THEN 'EBS Volume'
WHEN product_product_family = 'Storage Snapshot' THEN 'EBS Snapshot'
END AS usage_type_product_product_family,
product_region,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${tableName}
WHERE
${date_filter}
AND product_product_name = 'Amazon Elastic Compute Cloud'
AND (product_product_family = 'Storage Snapshot' OR product_product_family = 'Storage')
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m'),
CASE
WHEN product_product_family = 'Storage' THEN 'EBS Volume'
WHEN product_product_family = 'Storage Snapshot' THEN 'EBS Snapshot'
END,
product_region
ORDER BY
month_line_item_usage_start_date ASC,
sum_line_item_unblended_cost DESC,
sum_line_item_usage_amount DESC;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended cost and usage information per linked account for Amazon EFS. The output will include detailed information about the resource id (File System), usage type, and API operation. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
SPLIT_PART(line_item_resource_id, 'file-system/', 2) AS split_line_item_resource_id,
line_item_usage_type,
product_product_family,
product_storage_class,
pricing_unit,
line_item_operation,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'Amazon Elastic File System'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_usage_type,
pricing_unit,
product_product_family,
product_storage_class,
line_item_resource_id,
line_item_operation
ORDER BY
day_line_item_usage_start_date,
sum_line_item_usage_amount,
sum_line_item_unblended_cost DESC,
line_item_usage_type;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended cost and usage information per linked account for Amazon FSx. The output will include detailed information about the resource id (FSx file system), usage type, and Storage type. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date,
SPLIT_PART(line_item_resource_id, ':', 6) AS split_line_item_resource_id,
product_deployment_option,
line_item_usage_type,
product_product_family,
pricing_unit,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name = 'Amazon FSx'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
SPLIT_PART(line_item_resource_id, ':', 6),
product_deployment_option,
line_item_usage_type,
product_product_family,
pricing_unit
ORDER BY
day_line_item_usage_start_date,
sum_line_item_usage_amount,
sum_line_item_unblended_cost;
PROMPT: What SQL query corresponds to the following purpose: This query will provide daily unblended cost and usage information per linked account for AWS Backup. The output will include detailed information about the usage type, product family, pricing unit and others. The usage amount and cost will be summed and the cost will be in descending order.?
COMPLETION: SELECT
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date), '%Y-%m-%d') AS day_line_item_usage_start_date,
pricing_unit,
product_product_family,
line_item_usage_type,
line_item_operation,
SPLIT_PART(line_item_usage_type, '-', 4) AS split_line_item_usage_type,
SUM(CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM
${table_name}
WHERE
${date_filter}
AND product_product_name LIKE '%Backup%'
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage', 'SavingsPlanCoveredUsage')
GROUP BY
bill_payer_account_id,
line_item_usage_account_id,
DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
line_item_usage_type,
product_product_family,
pricing_unit,
line_item_operation
ORDER BY
day_line_item_usage_start_date,
sum_line_item_usage_amount,
sum_line_item_unblended_cost,
line_item_usage_type;
PROMPT: What SQL query corresponds to the following purpose: This query will display cost and usage of Elastic Block Storage Volumes that are type gp3. These resources returned by this query could be considered for upgrade to gp3 as with up to 20% cost savings, gp3 volumes help you achieve more control over your provisioned IOPS, giving the ability to provision storage with your unique applications in mind. This query uses 0.088 gp3 pricing please check the pricing page to confirm you are using the correct pricing for your applicable region. For Additional information checkout this AWS Blog Post. AWS Blog Post.?
COMPLETION: SELECT * FROM
(SELECT bill_payer_account_id,
line_item_usage_account_id,
product_location,
product_region,
month,
pricing_public_on_demand_rate,
line_item_resource_id,
line_item_usage_type,
SPLIT_PART(SPLIT_PART(line_item_usage_type ,
':',2),'.',2) AS ebs_type,
SUM(line_item_usage_amount) AS gb_charged,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost,
SUM(line_item_usage_amount)*.088 AS gp3_price -- 0.088 eu-west-1 pricing
, (SUM(line_item_unblended_cost)-(SUM(line_item_usage_amount)*.088)) AS gp3_savings -- 0.088 eu-west-1 pricing
FROM ${table}
WHERE ${date_filter}
AND product_product_name = 'Amazon Elastic Compute Cloud'
AND line_item_usage_type LIKE '%%EBS%%Volume%%'
AND product_product_family IN ('Storage','System Operation')
AND line_item_line_item_type = ('Usage')
AND product_region = 'eu-west-1'
AND SPLIT_PART(SPLIT_PART(line_item_usage_type,':',2),'.',2) = 'gp2'
GROUP BY bill_payer_account_id, line_item_usage_account_id, month, line_item_usage_type, product_location, product_region, line_item_resource_id, pricing_public_on_demand_rate, month
ORDER BY sum_line_item_unblended_cost DESC)
WHERE gb_charged < 1000;
|