func WriteToFile(c *Credentials, filename string, section string) error {
	cfg, err := ini.LooseLoad(filename)
	if err != nil {
		return err
	}
	cfg.DeleteSection(section)
	_, err = cfg.Section(section).NewKey("aws_access_key_id", c.AccessKeyID)
	if err != nil {
		return err
	}
	_, err = cfg.Section(section).NewKey("aws_secret_access_key", c.SecretAccessKey)
	if err != nil {
		return err
	}
	_, err = cfg.Section(section).NewKey("aws_session_token", c.SessionToken)
	if err != nil {
		return err
	}
	_, err = cfg.Section(section).NewKey(expireKey, c.Expiration.UTC().Format(time.RFC3339))
	if err != nil {
		return err
	}
	for _, s := range cfg.Sections() {
		if !s.HasKey(expireKey) {
			continue
		}
		v, err := s.Key(expireKey).TimeFormat(time.RFC3339)
		if err != nil {
			log.Printf(color.YellowString("Cannot parse date (%v) in section %s: %s"),
				s.Key(expireKey), s.Name(), err)
			continue
		}
		if time.Now().UTC().Unix() > v.Unix() {
			cfg.DeleteSection(s.Name())
		}
	}
	return cfg.SaveTo(filename)
}
WriteToFile writes credentials to an AWS CLI credentials file
(https://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html). In addition, this
function removes expired temporary credentials from the credentials file.
package aws
import (
	"fmt"
	"io"
	"log"
	"time"
	"github.com/fatih/color"
	"github.com/go-ini/ini"
)
type Credentials struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
	Expiration      time.Time
}
type Profile struct {
	Name         string
	LifetimeLeft time.Duration
	ExpireAtUnix int64
}
const expireKey = "aws_expiration"