Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Default Dates
Browse files Browse the repository at this point in the history
Until #9 is resolved I thought it would be useful if the tool defaults
to the last 12 months of activity instead of having hard coded dates
that prevent it from running with an error.

I thought this could be useful since people may try out the utility
after the recent blog post by Mapbox:

https://blog.mapbox.com/how-much-carbon-is-your-server-emitting-d7edf3496fd6
  • Loading branch information
edsu authored and mrchrisadams committed Nov 4, 2019
1 parent 3a1f86d commit 15a3322
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ const creds = {

const costExplorer = new AWS.CostExplorer(creds);

// AWS Cost Explorer API doesn't track data for more than 1 year
const now = new Date()
const endDate = now.toISOString().slice(0, 10)
now.setYear(now.getFullYear() - 1)
const startDate = now.toISOString().slice(0, 10)

const ceParams = {
// Start=2018-08-01,End=2019-05-01
TimePeriod: { /* required */
Start: '2018-08-01', /* required */
End: '2019-05-01' /* required */
TimePeriod: {
Start: startDate,
End: endDate
},
Granularity: 'MONTHLY',
Metrics: [
Expand Down

0 comments on commit 15a3322

Please sign in to comment.