Ejemplo n.º 1
0
func GetRegions(cmd *cobra.Command, args []string) (resp *ec2.DescribeRegionsOutput, err error) {
	var (
		svc         *ec2.EC2
		input       *ec2.DescribeRegionsInput
		regions     []string
		regionNames []*string
	)

	regions, err = cmd.Flags().GetStringSlice("region")
	if err != nil {
		return
	}

	for _, v := range regions {
		regionNames = append(regionNames, aws.String(v))
	}

	if len(regionNames) > 0 {
		input = &ec2.DescribeRegionsInput{RegionNames: regionNames}
	} else {
		input = &ec2.DescribeRegionsInput{}
	}

	svc = ec2.New(session.New(), aws.NewConfig().WithRegion(viper.GetString("DefaultEC2Region")))

	resp, err = svc.DescribeRegions(input)
	return
}
Ejemplo n.º 2
0
// GetRegions returns a slice of all AWS regions.
func GetRegions(ecc *ec2.EC2) ([]*ec2.Region, error) {
	regionlist := []*ec2.Region{}
	resp, err := ecc.DescribeRegions(nil)

	if err != nil {
		fmt.Println(err.Error())
	}

	for _, r := range resp.Regions {
		regionlist = append(regionlist, r)
	}

	return regionlist, nil
}