當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Config.Region方法代碼示例

本文整理匯總了Golang中github.com/aws/aws-sdk-go/aws.Config.Region方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.Region方法的具體用法?Golang Config.Region怎麽用?Golang Config.Region使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/aws/aws-sdk-go/aws.Config的用法示例。


在下文中一共展示了Config.Region方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: init

func init() {
	var ecsconfig aws.Config
	if region := os.Getenv("AWS_REGION"); region != "" {
		ecsconfig.Region = &region
	}
	if region := os.Getenv("AWS_DEFAULT_REGION"); region != "" {
		ecsconfig.Region = &region
	}
	if ecsconfig.Region == nil {
		if iid, err := ec2.GetInstanceIdentityDocument(); err == nil {
			ecsconfig.Region = &iid.Region
		}
	}
	if envEndpoint := os.Getenv("ECS_BACKEND_HOST"); envEndpoint != "" {
		ecsconfig.Endpoint = &envEndpoint
	}

	ECS = ecs.New(session.New(&ecsconfig))
	Cluster = "ecs-functional-tests"
	if envCluster := os.Getenv("ECS_CLUSTER"); envCluster != "" {
		Cluster = envCluster
	}
	ECS.CreateCluster(&ecs.CreateClusterInput{
		ClusterName: aws.String(Cluster),
	})
}
開發者ID:instacart,項目名稱:amazon-ecs-agent,代碼行數:26,代碼來源:utils.go

示例2: newClient

func (factory *ecrFactory) newClient(region, endpointOverride string) ECRSDK {
	var ecrConfig aws.Config
	ecrConfig.Region = &region
	ecrConfig.HTTPClient = factory.httpClient
	if endpointOverride != "" {
		ecrConfig.Endpoint = &endpointOverride
	}
	return ecrapi.New(&ecrConfig)
}
開發者ID:bmanas,項目名稱:amazon-ecs-agent,代碼行數:9,代碼來源:factory.go

示例3: newClient

func (factory *ecrFactory) newClient(region, endpointOverride string) ECRClient {
	var ecrConfig aws.Config
	ecrConfig.Region = &region
	ecrConfig.HTTPClient = factory.httpClient
	if endpointOverride != "" {
		ecrConfig.Endpoint = &endpointOverride
	}
	sdkClient := ecrapi.New(session.New(&ecrConfig))
	tokenCache := async.NewLRUCache(tokenCacheSize, tokenCacheTTL)
	return NewECRClient(sdkClient, tokenCache)
}
開發者ID:umaptechnologies,項目名稱:amazon-ecs-agent,代碼行數:11,代碼來源:factory.go

示例4: MakeS3Backend

func MakeS3Backend(bucket string, prefix string, opts *ConnectOptions) ArchiveBackend {
	cfg := aws.Config{}
	if opts != nil && opts.S3Region != "" {
		cfg.Region = aws.String(opts.S3Region)
	}
	sess := session.New(&cfg)
	return &S3ArchiveBackend{
		svc:    s3.New(sess),
		bucket: bucket,
		prefix: prefix,
	}
}
開發者ID:stellar,項目名稱:bridge-server,代碼行數:12,代碼來源:s3_archive.go

示例5: NewECSClient

func NewECSClient(credentialProvider *credentials.Credentials, config *config.Config, httpClient *http.Client, ec2MetadataClient ec2.EC2MetadataClient) ECSClient {
	var ecsConfig aws.Config
	ecsConfig.Credentials = credentialProvider
	ecsConfig.Region = &config.AWSRegion
	ecsConfig.HTTPClient = httpClient
	if config.APIEndpoint != "" {
		ecsConfig.Endpoint = &config.APIEndpoint
	}
	standardClient := ecs.New(&ecsConfig)
	submitStateChangeClient := newSubmitStateChangeClient(&ecsConfig)
	return &ApiECSClient{
		credentialProvider:      credentialProvider,
		config:                  config,
		standardClient:          standardClient,
		submitStateChangeClient: submitStateChangeClient,
		ec2metadata:             ec2MetadataClient,
	}
}
開發者ID:bmanas,項目名稱:amazon-ecs-agent,代碼行數:18,代碼來源:api_client.go

示例6: main

func main() {
	var (
		region    = ""
		follow    = false
		limit     = 100
		startStr  string
		startTime time.Time
		endStr    string
		endTime   time.Time
		config    aws.Config
	)

	flag.StringVar(&region, "region", region, "AWS region name")
	flag.BoolVar(&follow, "f", follow, "output appended data as the logs grow (conflicts with -t and -T)")
	flag.IntVar(&limit, "n", limit, "specify the number of lines to output (conflicts with -T)")
	flag.StringVar(&startStr, "t", startStr, "load messages since YYYY-MM-DDTHH:MM:[email protected] (conflicts with -f)")
	flag.StringVar(&endStr, "T", endStr, "load messages until YYYY-MM-DDTHH:MM:[email protected] (conflicts with -n)")
	flag.Parse()

	if startStr != "" {
		startTime = parseTime(startStr)
	}

	if endStr != "" {
		endTime = parseTime(endStr)
	}

	if region != "" {
		config.Region = &region
	}

	sess := session.New(&config)

	if err := awslogtail.Run(sess, flag.Args(), follow, limit, startTime, endTime); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
開發者ID:ninchat,項目名稱:awslogtail,代碼行數:38,代碼來源:main.go

示例7: NewGoofys

func NewGoofys(bucket string, awsConfig *aws.Config, flags *flagStorage) *Goofys {
	// Set up the basic struct.
	fs := &Goofys{
		bucket: bucket,
		flags:  flags,
		umask:  0122,
	}

	if flags.DebugS3 {
		awsConfig.LogLevel = aws.LogLevel(aws.LogDebug)
	}

	fs.awsConfig = awsConfig
	fs.s3 = s3.New(awsConfig)

	params := &s3.GetBucketLocationInput{Bucket: &bucket}
	resp, err := fs.s3.GetBucketLocation(params)
	var fromRegion, toRegion string
	if err != nil {
		if mapAwsError(err) == fuse.ENOENT {
			log.Printf("bucket %v does not exist", bucket)
			return nil
		}
		fromRegion, toRegion = parseRegionError(err)
	} else {
		fs.logS3(resp)

		if resp.LocationConstraint == nil {
			toRegion = "us-east-1"
		} else {
			toRegion = *resp.LocationConstraint
		}

		fromRegion = *awsConfig.Region
	}

	if len(toRegion) != 0 && fromRegion != toRegion {
		log.Printf("Switching from region '%v' to '%v'", fromRegion, toRegion)
		awsConfig.Region = &toRegion
		fs.s3 = s3.New(awsConfig)
		_, err = fs.s3.GetBucketLocation(params)
		if err != nil {
			log.Println(err)
			return nil
		}
	} else if len(toRegion) == 0 && *awsConfig.Region != "milkyway" {
		log.Printf("Unable to detect bucket region, staying at '%v'", *awsConfig.Region)
	}

	now := time.Now()
	fs.rootAttrs = fuseops.InodeAttributes{
		Size:   4096,
		Nlink:  2,
		Mode:   flags.DirMode | os.ModeDir,
		Atime:  now,
		Mtime:  now,
		Ctime:  now,
		Crtime: now,
		Uid:    fs.flags.Uid,
		Gid:    fs.flags.Gid,
	}

	fs.bufferPool = NewBufferPool(100*1024*1024, 20*1024*1024)

	fs.nextInodeID = fuseops.RootInodeID + 1
	fs.inodes = make(map[fuseops.InodeID]*Inode)
	root := NewInode(aws.String(""), aws.String(""), flags)
	root.Id = fuseops.RootInodeID
	root.Attributes = &fs.rootAttrs

	fs.inodes[fuseops.RootInodeID] = root
	fs.inodesCache = make(map[string]*Inode)

	fs.nextHandleID = 1
	fs.dirHandles = make(map[fuseops.HandleID]*DirHandle)

	fs.fileHandles = make(map[fuseops.HandleID]*FileHandle)

	return fs
}
開發者ID:ketqi,項目名稱:goofys,代碼行數:80,代碼來源:goofys.go

示例8: getInstances

func getInstances(region string, maxCacheAge int, profile Profile) (error, map[string]*Instance) {
	instances := getInstanceCache(region, profile.Name, maxCacheAge)
	if instances != nil {
		return nil, instances
	}

	var creds *credentials.Credentials
	if profile.AWSAccessKey != "" && profile.AWSSecretKey != "" {
		creds = credentials.NewStaticCredentials(
			profile.AWSAccessKey,
			profile.AWSSecretKey,
			"",
		)
	} else if profile.AWSProfile != "" {
		creds = credentials.NewSharedCredentials(
			fmt.Sprintf("%s/.aws/credentials", homeDir),
			profile.AWSProfile,
		)
	} else {
		creds = credentials.NewEnvCredentials()
	}

	config := aws.Config{Credentials: creds}

	if region != "" {
		config.Region = aws.String(region)
	}

	svc := ec2.New(session.New(), &config)
	resp, err := svc.DescribeInstances(nil)

	if err != nil {
		return err, nil
	}

	instances = make(map[string]*Instance)
	for _, res := range resp.Reservations {
		for _, inst := range res.Instances {
			instance := new(Instance)

			instance.Tags = make([]string, len(inst.Tags))
			for index, keys := range inst.Tags {
				instance.Tags[index] = *keys.Value
				if *keys.Key == "Name" {
					instance.Name = *keys.Value
					instance.Id = *inst.InstanceId
				}
			}

			instance.PublicDnsName = *inst.PublicDnsName
			instance.InstanceType = *inst.InstanceType
			instance.CertName = *inst.KeyName

			if inst.PublicIpAddress != nil {
				instance.Addr = *inst.PublicIpAddress
			} else if inst.PrivateIpAddress != nil {
				instance.Addr = *inst.PrivateIpAddress
			}

			if instance.Name != "" && instance.Addr != "" {
				instances[instance.getNormalisedName()] = instance
			}
		}
	}

	if err = storeInstanceCache(region, profile.Name, instances); err != nil {
		return err, nil
	}

	return nil, instances
}
開發者ID:markwallsgrove,項目名稱:ec2.cli,代碼行數:71,代碼來源:main.go


注:本文中的github.com/aws/aws-sdk-go/aws.Config.Region方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。