Internal backend for ultiization reports, alerts and interface for Cablecast Reflect Customers.
For this, I am using PHP alongside the AWS PHP SDK w/ "home directory" Credential Profile & MySQL for housing data locally for histroical reporting.
Running AWS CLI command aws ce get-cost-and-usage --time-period Start=2020-05-01,End=2020-06-01 --granularity MONTHLY --metrics "BlendedCost" --group-by Type=TAG,Key=NetsuiteID
returns all customers with the "NetsuiteID" tag. This can be adapted to the PHP SDK for AWS by running:
$startdate = date("Y-m-j", strtotime( '-2 days' ));
$enddate = date("Y-m-j", strtotime( '-1 days' ));
$data = $client->getCostAndUsage([
'TimePeriod' => [
'End' => $enddate,
'Start' => $startdate,
],
'Granularity' => 'MONTHLY',
'Metrics' => ['BlendedCost','UsageQuantity'],
'GroupBy' => [
[
'Type' => 'TAG',
'Key' => 'NetsuiteID']
]
]);
More information on the syntax and parameters here.
Can't imagine this'll be useful for anyone outside our org. But just incase:
- Clone repo to a webserver of your choice with MySQL and php extensions
- Create database called
reflect_usage
and importcustomer_usage.sql
- Rename
db_connect.php.default
todb_connect.php
- Define db username and password in
db_connect.php
- Setup AWS Credentials.
- Create project & setup AWS PHP SDK
- Setup credendial storage for AWS SDK
- Use proper function to pull costUsage
- Write costUsage json to database
- Setup
get_usage.php
to be a 4am CRON job
- Create "Customers" table
- Tie customers to UsageReports
- (Partially) Generate reports
- Generate email alerts
- AWS for PHP SDK Version 3 https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/getting-started_installation.html
- XAMPP https://www.apachefriends.org/
- Bootstrap CSS 3.4 CDN - https://getbootstrap.com/docs/3.4/css/
- Font Awesome CDN - https://fontawesome.com/