<commit_before>package main

import (
	"flag"
	"fmt"
	"log"
	//"os"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/ec2metadata"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/ec2"
)

var debug = false

func getRegionString() (string, error) {
	svc := ec2metadata.New(session.New())
	region, err := svc.Region()
	return region, err
}

func getInstanceId() (string, error) {
	svc := ec2metadata.New(session.New())
	identityDocument, err := svc.GetInstanceIdentityDocument()
	if err != nil {
		return "", err
	}
	return identityDocument.InstanceID, nil
}

func getTag(name string, regionString string) (string, error) {
	//svc := ec2.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
	instanceID, err := getInstanceId()
	if err != nil {
		return "", err
	}

	svc := ec2.New(session.New(&aws.Config{Region: aws.String(regionString)}))

	//svc := ec2.New(sess)

	params := &ec2.DescribeInstancesInput{
		//DryRun: aws.Bool(true),
		Filters: []*ec2.Filter{
			{ /*
				// Required
				Name: aws.String("String"),
				Values: []*string{
					aws.String("String"), // Required
					// More values...
				},
			*/
			},
			// More values...
		},
		InstanceIds: []*string{
			//aws.String("i-0c8b43c46be4852d5"), // Required
			aws.String(instanceID),
			// More values...
		},
		//MaxResults: aws.Int64(1),
		//NextToken: aws.String("String"),
	}
	resp, err := svc.DescribeInstances(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return "", err
	}

	// Pretty-print the response data.
	fmt.Println(resp)

	return "", nil
}

func main() {
	//var credentialsFilePath = flag.String("credentials", "credentials.yml", "credentials file")
	var tagName = flag.String("tagname", "Name", "Name of the tag of interest")
	flag.Parse()

	regionString, err := getRegionString()
	if err != nil {
		log.Fatalf("Cannot get Region string %s", err)
	}
	getTag(*tagName, regionString)

}<commit_msg>now via describetags<commit_after>package main

import (
	"flag"
	"fmt"
	"log"
	//"os"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/ec2metadata"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/ec2"
)

var debug = false

func getRegionString() (string, error) {
	svc := ec2metadata.New(session.New())
	region, err := svc.Region()
	return region, err
}

func getInstanceId() (string, error) {
	svc := ec2metadata.New(session.New())
	identityDocument, err := svc.GetInstanceIdentityDocument()
	if err != nil {
		return "", err
	}
	return identityDocument.InstanceID, nil
}

func getTag(name string, regionString string) (string, error) {
	//svc := ec2.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
	instanceID, err := getInstanceId()
	if err != nil {
		return "", err
	}

	svc := ec2.New(session.New(&aws.Config{Region: aws.String(regionString)}))

	//svc := ec2.New(sess)

	params := &ec2.DescribeInstancesInput{
		//DryRun: aws.Bool(true),
		Filters: []*ec2.Filter{
			{ /*
				// Required
				Name: aws.String("String"),
				Values: []*string{
					aws.String("String"), // Required
					// More values...
				},
			*/
			},
			// More values...
		},
		InstanceIds: []*string{
			//aws.String("i-0c8b43c46be4852d5"), // Required
			aws.String(instanceID),
			// More values...
		},
		//MaxResults: aws.Int64(1),
		//NextToken: aws.String("String"),
	}
	resp, err := svc.DescribeInstances(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return "", err
	}

	// Pretty-print the response data.
	fmt.Println(resp)

	describeTagsparams := &ec2.DescribeTagsInput{
		//DryRun: aws.Bool(true),
		Filters: []*ec2.Filter{
			{ // Required
				Name: aws.String("resource-type"),
				Values: []*string{
					aws.String("instance"), // Required
					// More values...
				},
			},
			{
				Name: aws.String("resource-id"),
				Values: []*string{
					aws.String(instanceID), // Required
					// More values...
				},
			},
			// More values...
		},
		MaxResults: aws.Int64(10),
		NextToken:  aws.String("String"),
	}

	resp2, err := svc.DescribeTags(describeTagsparams)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return "", err
	}

	// Pretty-print the response data.
	fmt.Println(resp2)

	return "", nil
}

func main() {
	//var credentialsFilePath = flag.String("credentials", "credentials.yml", "credentials file")
	var tagName = flag.String("tagname", "Name", "Name of the tag of interest")
	flag.Parse()

	regionString, err := getRegionString()
	if err != nil {
		log.Fatalf("Cannot get Region string %s", err)
	}
	getTag(*tagName, regionString)

}
{'fraction_non_alphanumeric': 0.17622696210395528, 'fraction_numerical': 0.011596603851729136, 'mean_word_length': 3.274336283185841, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5542017', 'n_tokens_mistral': 1920, 'n_tokens_neox': 1762, 'n_words': 379}