本文整理匯總了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 = ®ion
}
if region := os.Getenv("AWS_DEFAULT_REGION"); region != "" {
ecsconfig.Region = ®ion
}
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),
})
}
示例2: newClient
func (factory *ecrFactory) newClient(region, endpointOverride string) ECRSDK {
var ecrConfig aws.Config
ecrConfig.Region = ®ion
ecrConfig.HTTPClient = factory.httpClient
if endpointOverride != "" {
ecrConfig.Endpoint = &endpointOverride
}
return ecrapi.New(&ecrConfig)
}
示例3: newClient
func (factory *ecrFactory) newClient(region, endpointOverride string) ECRClient {
var ecrConfig aws.Config
ecrConfig.Region = ®ion
ecrConfig.HTTPClient = factory.httpClient
if endpointOverride != "" {
ecrConfig.Endpoint = &endpointOverride
}
sdkClient := ecrapi.New(session.New(&ecrConfig))
tokenCache := async.NewLRUCache(tokenCacheSize, tokenCacheTTL)
return NewECRClient(sdkClient, tokenCache)
}
示例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,
}
}
示例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,
}
}
示例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(®ion, "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 = ®ion
}
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)
}
}
示例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
}
示例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
}