本文整理汇总了Golang中github.com/aws/aws-sdk-go/aws.Config类的典型用法代码示例。如果您正苦于以下问题:Golang Config类的具体用法?Golang Config怎么用?Golang Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BenchmarkPutItem
func BenchmarkPutItem(b *testing.B) {
cfg := aws.Config{
DisableSSL: aws.Bool(true),
Credentials: credentials.NewStaticCredentials("AKID", "SECRET", ""),
}
server := successRespServer([]byte(`{}`))
cfg.Endpoint = aws.String(server.URL)
svc := dynamodb.New(&cfg)
svc.Handlers.Send.Clear()
svc.Handlers.Send.PushBack(func(r *service.Request) {
r.HTTPResponse = &http.Response{
StatusCode: http.StatusOK,
Status: http.StatusText(http.StatusOK),
Body: noopBody,
}
})
b.ResetTimer()
for i := 0; i < b.N; i++ {
av, err := dynamodbattribute.ConvertToMap(dbItem{Key: "MyKey", Data: "MyData"})
if err != nil {
b.Fatal("benchPutItem, expect no ConvertToMap errors", err)
}
params := &dynamodb.PutItemInput{
Item: av,
TableName: aws.String("tablename"),
}
_, err = svc.PutItem(params)
if err != nil {
b.Error("benchPutItem, expect no request errors", err)
}
}
}
示例2: 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),
})
}
示例3: New
// New initializes a new S3 client connection based on config.
func New() *S3Client {
var (
cfg *aws.Config
)
if config.S3.Endpoint != "" {
cfg = &aws.Config{
Endpoint: aws.String(config.S3.Endpoint),
DisableSSL: aws.Bool(strings.HasPrefix(config.S3.Endpoint, "http://")),
Region: aws.String(config.S3.Region),
S3ForcePathStyle: aws.Bool(config.S3.PathStyle),
}
} else {
cfg = &aws.Config{
Region: aws.String(config.S3.Region),
S3ForcePathStyle: aws.Bool(config.S3.PathStyle),
}
}
if config.S3.Access != "" && config.S3.Secret != "" {
cfg.Credentials = credentials.NewStaticCredentials(
config.S3.Access,
config.S3.Secret,
"",
)
}
return &S3Client{
client: s3.New(
session.New(),
cfg,
),
}
}
示例4: mergeConfigSrcs
func mergeConfigSrcs(cfg, userCfg *aws.Config, envCfg envConfig, sharedCfg sharedConfig, handlers request.Handlers) {
// Merge in user provided configuration
cfg.MergeIn(userCfg)
// Region if not already set by user
if len(aws.StringValue(cfg.Region)) == 0 {
if len(envCfg.Region) > 0 {
cfg.WithRegion(envCfg.Region)
} else if envCfg.EnableSharedConfig && len(sharedCfg.Region) > 0 {
cfg.WithRegion(sharedCfg.Region)
}
}
// Configure credentials if not already set
if cfg.Credentials == credentials.AnonymousCredentials && userCfg.Credentials == nil {
if len(envCfg.Creds.AccessKeyID) > 0 {
cfg.Credentials = credentials.NewStaticCredentialsFromCreds(
envCfg.Creds,
)
} else if envCfg.EnableSharedConfig && len(sharedCfg.AssumeRole.RoleARN) > 0 && sharedCfg.AssumeRoleSource != nil {
cfgCp := *cfg
cfgCp.Credentials = credentials.NewStaticCredentialsFromCreds(
sharedCfg.AssumeRoleSource.Creds,
)
cfg.Credentials = stscreds.NewCredentials(
&Session{
Config: &cfgCp,
Handlers: handlers.Copy(),
},
sharedCfg.AssumeRole.RoleARN,
func(opt *stscreds.AssumeRoleProvider) {
opt.RoleSessionName = sharedCfg.AssumeRole.RoleSessionName
if len(sharedCfg.AssumeRole.ExternalID) > 0 {
opt.ExternalID = aws.String(sharedCfg.AssumeRole.ExternalID)
}
// MFA not supported
},
)
} else if len(sharedCfg.Creds.AccessKeyID) > 0 {
cfg.Credentials = credentials.NewStaticCredentialsFromCreds(
sharedCfg.Creds,
)
} else {
// Fallback to default credentials provider, include mock errors
// for the credential chain so user can identify why credentials
// failed to be retrieved.
cfg.Credentials = credentials.NewCredentials(&credentials.ChainProvider{
VerboseErrors: aws.BoolValue(cfg.CredentialsChainVerboseErrors),
Providers: []credentials.Provider{
&credProviderError{Err: awserr.New("EnvAccessKeyNotFound", "failed to find credentials in the environment.", nil)},
&credProviderError{Err: awserr.New("SharedCredsLoad", fmt.Sprintf("failed to load profile, %s.", envCfg.Profile), nil)},
defaults.RemoteCredProvider(*cfg, handlers),
},
})
}
}
}
示例5: initIamClient
func (r *run) initIamClient() *iam.IAM {
var awsconf aws.Config
if r.c.AccessKey != "" && r.c.SecretKey != "" {
awscreds := awscred.NewStaticCredentials(r.c.AccessKey, r.c.SecretKey, "")
awsconf.Credentials = awscreds
}
return iam.New(session.New(), &awsconf)
}
示例6: 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)
}
示例7: getService
func getService(debug bool) *route53.Route53 {
config := aws.Config{}
// ensures throttled requests are retried
config.MaxRetries = aws.Int(100)
if debug {
config.LogLevel = aws.LogLevel(aws.LogDebug)
}
return route53.New(&config)
}
示例8: newSubmitStateChangeClient
// newSubmitStateChangeClient returns a client intended to be used for
// Submit*StateChange APIs which has the behavior of retrying the call on
// retriable errors for an extended period of time (roughly 24 hours).
func newSubmitStateChangeClient(awsConfig *aws.Config) *ecs.ECS {
sscConfig := awsConfig.Copy()
sscConfig.MaxRetries = submitStateChangeMaxDelayRetries
client := ecs.New(&sscConfig)
client.Handlers.AfterRetry.Clear()
client.Handlers.AfterRetry.PushBack(
extendedRetryMaxDelayHandlerFactory(submitStateChangeExtraRetries))
client.DefaultMaxRetries = submitStateChangeMaxDelayRetries
return client
}
示例9: 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)
}
示例10: newMultiRegion
func newMultiRegion(conf *awsclient.Config, regions []string) *multiRegion {
m := &multiRegion{
regions: make(map[string]*ec2.EC2, 0),
}
for _, region := range regions {
m.regions[region] = ec2.New(conf.Merge(&awsclient.Config{Region: region}))
}
return m
}
示例11: 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,
}
}
示例12: getService
func getService(debug bool, profile string) *route53.Route53 {
config := aws.Config{}
if profile != "" {
config.Credentials = credentials.NewSharedCredentials("", profile)
}
// ensures throttled requests are retried
config.MaxRetries = aws.Int(100)
if debug {
config.LogLevel = aws.LogLevel(aws.LogDebug)
}
return route53.New(session.New(), &config)
}
示例13: mergeConfigSrcs
func mergeConfigSrcs(cfg, userCfg *aws.Config, envCfg envConfig, sharedCfg sharedConfig, handlers request.Handlers) {
// Merge in user provided configuration
cfg.MergeIn(userCfg)
// Region if not already set by user
if len(aws.StringValue(cfg.Region)) == 0 {
if len(envCfg.Region) > 0 {
cfg.WithRegion(envCfg.Region)
} else if envCfg.EnableSharedConfig && len(sharedCfg.Region) > 0 {
cfg.WithRegion(sharedCfg.Region)
}
}
// Configure credentials if not already set
if cfg.Credentials == credentials.AnonymousCredentials && userCfg.Credentials == nil {
if len(envCfg.Creds.AccessKeyID) > 0 {
cfg.Credentials = credentials.NewStaticCredentialsFromCreds(
envCfg.Creds,
)
} else if envCfg.EnableSharedConfig && len(sharedCfg.AssumeRole.RoleARN) > 0 && sharedCfg.AssumeRoleSource != nil {
cfgCp := *cfg
cfgCp.Credentials = credentials.NewStaticCredentialsFromCreds(
sharedCfg.AssumeRoleSource.Creds,
)
cfg.Credentials = stscreds.NewCredentials(
&Session{
Config: &cfgCp,
Handlers: handlers.Copy(),
},
sharedCfg.AssumeRole.RoleARN,
func(opt *stscreds.AssumeRoleProvider) {
opt.RoleSessionName = sharedCfg.AssumeRole.RoleSessionName
if len(sharedCfg.AssumeRole.ExternalID) > 0 {
opt.ExternalID = aws.String(sharedCfg.AssumeRole.ExternalID)
}
// MFA not supported
},
)
} else if len(sharedCfg.Creds.AccessKeyID) > 0 {
cfg.Credentials = credentials.NewStaticCredentialsFromCreds(
sharedCfg.Creds,
)
} else {
// Fallback to default credentials provider
cfg.Credentials = credentials.NewCredentials(
defaults.RemoteCredProvider(*cfg, handlers),
)
}
}
}
示例14: getConfig
func getConfig(c *cli.Context) *aws.Config {
debug := c.Bool("debug")
profile := c.String("profile")
config := aws.Config{}
if profile != "" {
config.Credentials = credentials.NewSharedCredentials("", profile)
}
// ensures throttled requests are retried
config.MaxRetries = aws.Int(100)
if debug {
config.LogLevel = aws.LogLevel(aws.LogDebug)
}
return &config
}
示例15: invokeLambdas
func (t *Test) invokeLambdas(awsConfig *aws.Config, sqsURL string) {
lambdas := numberOfLambdas(t.config.Concurrency, len(t.config.Regions))
for i := 0; i < lambdas; i++ {
region := t.config.Regions[i%len(t.config.Regions)]
requests, requestsRemainder := divide(t.config.TotalRequests, lambdas)
concurrency, _ := divide(t.config.Concurrency, lambdas)
if requestsRemainder > 0 && i == lambdas-1 {
requests += requestsRemainder
}
c := t.config
args := []string{
"-u",
fmt.Sprintf("%s", c.URL),
"-c",
fmt.Sprintf("%s", strconv.Itoa(int(concurrency))),
"-n",
fmt.Sprintf("%s", strconv.Itoa(int(requests))),
"-s",
fmt.Sprintf("%s", sqsURL),
"-q",
fmt.Sprintf("%s", c.Regions[0]),
"-t",
fmt.Sprintf("%s", c.RequestTimeout.String()),
"-f",
fmt.Sprintf("%s", reportingFrequency(lambdas).String()),
"-r",
fmt.Sprintf("%s", region),
"-m",
fmt.Sprintf("%s", c.Method),
"-b",
fmt.Sprintf("%s", c.Body),
}
for _, v := range t.config.Headers {
args = append(args, "-H", fmt.Sprintf("%s", v))
}
invokeargs := invokeArgs{
File: "./goad-lambda",
Args: args,
}
config := awsConfig.WithRegion(region)
go t.invokeLambda(config, invokeargs)
}
}