func main()

in scripts/go/costcli/costcli.go [278:396]


func main() {
	app := cli.NewApp()
	app.Name = "Cost CLI"
	app.Usage = "Command Line Interface for download, conversion and re-upload of the AWS CUR from/to a S3 Bucket."
	app.Version = "1.0.0"

	var startDate, endDate, database, table, region, roleArn, externalID, configFile, s3ResultsLocation string
	app.Commands = []cli.Command{
		{
			Name:  "costbytag",
			Usage: "Perform CUR Conversion",
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:        "startDate, sd",
					Usage:       "Date in YYYMMDD format",
					Value:       time.Now().Format("201601") + "01",
					Destination: &startDate,
				},
				cli.StringFlag{
					Name:        "endDate, ed",
					Usage:       "Date in YYYMMDD format",
					Value:       time.Now().Format("201601") + "31",
					Destination: &endDate,
				},
				cli.StringFlag{
					Name:        "database, db",
					Usage:       "Athena Database to use",
					Value:       "cur",
					Destination: &database,
				},
				cli.StringFlag{
					Name:        "table, tb",
					Usage:       "Athena Table to use",
					Value:       "",
					Destination: &table,
				},
				cli.StringFlag{
					Name:        "resultsLocation, rl",
					Usage:       "Athena Results Location override",
					Value:       "",
					Destination: &s3ResultsLocation,
				},
				cli.StringFlag{
					Name:        "region, r",
					Usage:       "AWS Region Athena Database and Table exist in (default us-east-1)",
					Value:       "us-east-1",
					Destination: &region,
				},
				cli.StringFlag{
					Name:        "roleArn, arn",
					Usage:       "Optional role ARN to assume when querying Athena",
					Value:       "",
					Destination: &roleArn,
				},
				cli.StringFlag{
					Name:        "externalID, extid",
					Usage:       "Optional role ARN to assume when querying Athena",
					Value:       "",
					Destination: &externalID,
				},
				cli.StringFlag{
					Name:        "config, c",
					Usage:       "JSON tag configuration",
					Value:       "",
					Destination: &configFile,
				},
			},
			Action: func(c *cli.Context) error {

				if len(table) < 1 {
					cli.ShowCommandHelp(c, "costbytag")
					log.Fatalln("Must supply a Athena Table to query")
				}

				// read in config file
				var conf Config
				if err := getConfig(&conf, configFile); err != nil {
					return err
				}
				conf.Database = database
				conf.Table = table

				// Init Session
				sess, err := session.NewSession(&aws.Config{Region: aws.String(region)})
				if err != nil {
					return err
				}

				// if needed set creds for AssumeRole and reset session
				if len(roleArn) > 0 {
					sess = sess.Copy(&aws.Config{Credentials: getCreds(roleArn, externalID, sess)})
				}

				// fetch account ID
				svc := sts.New(sess)
				result, err := svc.GetCallerIdentity(&sts.GetCallerIdentityInput{})
				if err != nil {
					return err
				}
				conf.Account = *result.Account

				// get Athena Data
				svcAthena := athena.New(sess)
				response, err := sendQuery(svcAthena, conf.Database, buildCostQuery(&conf), conf.Account, region, s3ResultsLocation)
				if err != nil {
					return err
				}

				printResults(processResults(response, conf), conf)
				return nil
			},
		},
	}

	err := app.Run(os.Args)
	if err != nil {
		fmt.Println(err)
	}
}