func NewECRClient(region string) *ECRClientImpl {
	awsConfig := aws.NewConfig()
	awsConfig.WithRegion(region)
	sess := session.New(awsConfig)
	creds := credentials.NewChainCredentials(
		[]credentials.Provider{
			&credentials.EnvProvider{},
			&credentials.SharedCredentialsProvider{},
			&ec2rolecreds.EC2RoleProvider{
				Client: ec2metadata.New(sess),
			},
		})
	awsConfig.WithCredentials(creds)
	return &ECRClientImpl{
		ECRClient: ecr.New(sess),
	}
}
NewECRClient returns a new client for interacting with the ECR API. The
credentials are retrieved from environment variables or from the
`~/.aws/credentials` file.
package aws
import (
	"fmt"
	"sort"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
	"github.com/aws/aws-sdk-go/aws/ec2metadata"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/ecr"
	"github.com/aws/aws-sdk-go/service/ecr/ecriface"
)
const (
	batchRemoveMaxImages = 100
)
type ECRClientImpl struct {
	ECRClient ecriface.ECRAPI
}
type ECRClient interface {
	ListRepositories(repositoryNames []*string, registryID *string) ([]*ecr.Repository, error)
	ListImages(repositoryName *string, registryID *string) ([]*ecr.ImageDetail, error)
	BatchRemoveImages(images []*ecr.ImageDetail) error
}
type ImagesByPushDate []*ecr.ImageDetail
func (slice ImagesByPushDate) Len() int {
	return len(slice)
}
func (slice ImagesByPushDate) Less(i, j int) bool {
	ti := *slice[i].ImagePushedAt
	tj := *slice[j].ImagePushedAt
	return ti.Before(tj)
}
func (slice ImagesByPushDate) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}