本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/autoscaling.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExampleAutoScaling_DetachInstances
func ExampleAutoScaling_DetachInstances() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := autoscaling.New(sess)
params := &autoscaling.DetachInstancesInput{
AutoScalingGroupName: aws.String("ResourceName"), // Required
ShouldDecrementDesiredCapacity: aws.Bool(true), // Required
InstanceIds: []*string{
aws.String("XmlStringMaxLen19"), // Required
// More values...
},
}
resp, err := svc.DetachInstances(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
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例2: ExampleAutoScaling_PutLifecycleHook
func ExampleAutoScaling_PutLifecycleHook() {
svc := autoscaling.New(session.New())
params := &autoscaling.PutLifecycleHookInput{
AutoScalingGroupName: aws.String("ResourceName"), // Required
LifecycleHookName: aws.String("AsciiStringMaxLen255"), // Required
DefaultResult: aws.String("LifecycleActionResult"),
HeartbeatTimeout: aws.Int64(1),
LifecycleTransition: aws.String("LifecycleTransition"),
NotificationMetadata: aws.String("XmlStringMaxLen1023"),
NotificationTargetARN: aws.String("ResourceName"),
RoleARN: aws.String("ResourceName"),
}
resp, err := svc.PutLifecycleHook(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
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例3: ExampleAutoScaling_PutScheduledUpdateGroupAction
func ExampleAutoScaling_PutScheduledUpdateGroupAction() {
svc := autoscaling.New(session.New())
params := &autoscaling.PutScheduledUpdateGroupActionInput{
AutoScalingGroupName: aws.String("ResourceName"), // Required
ScheduledActionName: aws.String("XmlStringMaxLen255"), // Required
DesiredCapacity: aws.Int64(1),
EndTime: aws.Time(time.Now()),
MaxSize: aws.Int64(1),
MinSize: aws.Int64(1),
Recurrence: aws.String("XmlStringMaxLen255"),
StartTime: aws.Time(time.Now()),
Time: aws.Time(time.Now()),
}
resp, err := svc.PutScheduledUpdateGroupAction(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
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例4: ExampleAutoScaling_UpdateAutoScalingGroup
func ExampleAutoScaling_UpdateAutoScalingGroup() {
svc := autoscaling.New(session.New())
params := &autoscaling.UpdateAutoScalingGroupInput{
AutoScalingGroupName: aws.String("ResourceName"), // Required
AvailabilityZones: []*string{
aws.String("XmlStringMaxLen255"), // Required
// More values...
},
DefaultCooldown: aws.Int64(1),
DesiredCapacity: aws.Int64(1),
HealthCheckGracePeriod: aws.Int64(1),
HealthCheckType: aws.String("XmlStringMaxLen32"),
LaunchConfigurationName: aws.String("ResourceName"),
MaxSize: aws.Int64(1),
MinSize: aws.Int64(1),
PlacementGroup: aws.String("XmlStringMaxLen255"),
TerminationPolicies: []*string{
aws.String("XmlStringMaxLen1600"), // Required
// More values...
},
VPCZoneIdentifier: aws.String("XmlStringMaxLen255"),
}
resp, err := svc.UpdateAutoScalingGroup(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
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例5: ExampleAutoScaling_DescribeScheduledActions
func ExampleAutoScaling_DescribeScheduledActions() {
svc := autoscaling.New(session.New())
params := &autoscaling.DescribeScheduledActionsInput{
AutoScalingGroupName: aws.String("ResourceName"),
EndTime: aws.Time(time.Now()),
MaxRecords: aws.Int64(1),
NextToken: aws.String("XmlString"),
ScheduledActionNames: []*string{
aws.String("ResourceName"), // Required
// More values...
},
StartTime: aws.Time(time.Now()),
}
resp, err := svc.DescribeScheduledActions(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
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例6: ExampleAutoScaling_DetachInstances
func ExampleAutoScaling_DetachInstances() {
svc := autoscaling.New(nil)
params := &autoscaling.DetachInstancesInput{
AutoScalingGroupName: aws.String("ResourceName"), // Required
ShouldDecrementDesiredCapacity: aws.Boolean(true), // Required
InstanceIDs: []*string{
aws.String("XmlStringMaxLen16"), // Required
// More values...
},
}
resp, err := svc.DetachInstances(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS Error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, the SDK should always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.StringValue(resp))
}
示例7: deleteAutoScaleGroups
// Private function without the confirmation terminal prompts
func deleteAutoScaleGroups(asgList *AutoScaleGroups, force, dryRun bool) (err error) {
for _, asg := range *asgList {
svc := autoscaling.New(session.New(&aws.Config{Region: aws.String(asg.Region)}))
params := &autoscaling.DeleteAutoScalingGroupInput{
AutoScalingGroupName: aws.String(asg.Name),
ForceDelete: aws.Bool(force),
}
// Delete it!
if !dryRun {
_, err := svc.DeleteAutoScalingGroup(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
return errors.New(awsErr.Message())
}
return err
}
terminal.Information("Deleted AutoScaling Group [" + asg.Name + "] in [" + asg.Region + "]!")
} else {
fmt.Println(params)
}
}
return nil
}
示例8: getAutoScalingInstances
// Returns all instances that are in autoscaling groups within the given region
// if a autoscaling group name is specified then only the instances within that group are returned
func getAutoScalingInstances() []*autoscaling.InstanceDetails {
instances := make([]*autoscaling.InstanceDetails, 0, 50)
var token *string
var resp *autoscaling.DescribeAutoScalingInstancesOutput
var err error
svc := autoscaling.New(session.New(), &aws.Config{Region: aws.String(flag_region)})
// DescribeAutoscalinginstances() only returns 50 instances a time so...
// keep calling for more until all have been retrieved
for {
params := &autoscaling.DescribeAutoScalingInstancesInput{
NextToken: token,
}
resp, err = svc.DescribeAutoScalingInstances(params)
if err != nil {
fmt.Println(err.Error())
return nil
}
instances = append(instances, resp.AutoScalingInstances...)
token = resp.NextToken
// no more instances to get. We done hehr
if token == nil {
break
}
}
if flag_asgName == "" {
return instances
}
return filterByASGName(instances)
}
示例9: ExampleAutoScaling_DescribePolicies
func ExampleAutoScaling_DescribePolicies() {
svc := autoscaling.New(nil)
params := &autoscaling.DescribePoliciesInput{
AutoScalingGroupName: aws.String("ResourceName"),
MaxRecords: aws.Int64(1),
NextToken: aws.String("XmlString"),
PolicyNames: []*string{
aws.String("ResourceName"), // Required
// More values...
},
PolicyTypes: []*string{
aws.String("XmlStringMaxLen64"), // Required
// More values...
},
}
resp, err := svc.DescribePolicies(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
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例10: main
func main() {
kingpin.Parse()
me := ec2metadata.New(session.New(), &aws.Config{})
region, err := me.Region()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
cw := cloudwatch.New(session.New(&aws.Config{Region: aws.String(region)}))
as := autoscaling.New(session.New(&aws.Config{Region: aws.String(region)}))
// Get the name of this instance.
instance, err := me.GetMetadata("instance-id")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
log.Printf("Instance: %s", instance)
// Check if this instance is in an auto scaling group.
gps, err := as.DescribeAutoScalingInstances(&autoscaling.DescribeAutoScalingInstancesInput{
InstanceIds: []*string{
aws.String(instance),
},
})
if err == nil && len(gps.AutoScalingInstances) > 0 {
group = *gps.AutoScalingInstances[0].AutoScalingGroupName
log.Printf("AutoScaling group: %s", group)
}
// Loop and send to the backend.
limiter := time.Tick(time.Second * 60)
for {
<-limiter
// Submit all the values.
for _, mn := range strings.Split(*cliMetrics, ",") {
m, err := metric.New(mn)
if err != nil {
log.Printf("Cannot find metric: %s" + mn)
continue
}
v, err := m.Value()
if err != nil {
log.Println("Cannot get metric.")
}
// Send the instance metrics.
Send(cw, "InstanceId", instance, m.Name(), v)
// Send the autoscaling.
if group != "" {
Send(cw, "AutoScalingGroupName", group, m.Name(), v)
}
}
}
}
示例11: ExampleAutoScaling_DescribeAutoScalingInstances
func ExampleAutoScaling_DescribeAutoScalingInstances() {
svc := autoscaling.New(nil)
params := &autoscaling.DescribeAutoScalingInstancesInput{
InstanceIDs: []*string{
aws.String("XmlStringMaxLen16"), // Required
// More values...
},
MaxRecords: aws.Long(1),
NextToken: aws.String("XmlString"),
}
resp, err := svc.DescribeAutoScalingInstances(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS Error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, The SDK should alwsy return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.StringValue(resp))
}
示例12: ExampleAutoScaling_DeleteScheduledAction
func ExampleAutoScaling_DeleteScheduledAction() {
svc := autoscaling.New(nil)
params := &autoscaling.DeleteScheduledActionInput{
ScheduledActionName: aws.String("ResourceName"), // Required
AutoScalingGroupName: aws.String("ResourceName"),
}
resp, err := svc.DeleteScheduledAction(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS Error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, The SDK should alwsy return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.StringValue(resp))
}
示例13: GetLaunchConfigurationsByName
// GetLaunchConfigurationsByName returns a slice of Launch Configurations for a given region and name
func GetLaunchConfigurationsByName(region, name string) (LaunchConfigs, error) {
svc := autoscaling.New(session.New(&aws.Config{Region: aws.String(region)}))
params := &autoscaling.DescribeLaunchConfigurationsInput{
LaunchConfigurationNames: []*string{
aws.String(name),
},
}
result, err := svc.DescribeLaunchConfigurations(params)
if err != nil || len(result.LaunchConfigurations) == 0 {
return LaunchConfigs{}, err
}
secGrpList := new(SecurityGroups)
err = GetRegionSecurityGroups(region, secGrpList, "")
imgList := new(Images)
GetRegionImages(region, imgList, "", false)
lcList := make(LaunchConfigs, len(result.LaunchConfigurations))
for i, config := range result.LaunchConfigurations {
lcList[i].Marshal(config, region, secGrpList, imgList)
}
if len(lcList) == 0 {
return lcList, errors.New("No Launch Configurations found with name of [" + name + "] in [" + region + "].")
}
return lcList, err
}
示例14: ExampleAutoScaling_CompleteLifecycleAction
func ExampleAutoScaling_CompleteLifecycleAction() {
svc := autoscaling.New(nil)
params := &autoscaling.CompleteLifecycleActionInput{
AutoScalingGroupName: aws.String("ResourceName"), // Required
LifecycleActionResult: aws.String("LifecycleActionResult"), // Required
LifecycleActionToken: aws.String("LifecycleActionToken"), // Required
LifecycleHookName: aws.String("AsciiStringMaxLen255"), // Required
}
resp, err := svc.CompleteLifecycleAction(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS Error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, the SDK should always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.StringValue(resp))
}
示例15: ExampleAutoScaling_PutLifecycleHook
func ExampleAutoScaling_PutLifecycleHook() {
svc := autoscaling.New(nil)
params := &autoscaling.PutLifecycleHookInput{
AutoScalingGroupName: aws.String("ResourceName"), // Required
LifecycleHookName: aws.String("AsciiStringMaxLen255"), // Required
DefaultResult: aws.String("LifecycleActionResult"),
HeartbeatTimeout: aws.Long(1),
LifecycleTransition: aws.String("LifecycleTransition"),
NotificationMetadata: aws.String("XmlStringMaxLen1023"),
NotificationTargetARN: aws.String("ResourceName"),
RoleARN: aws.String("ResourceName"),
}
resp, err := svc.PutLifecycleHook(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS Error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, the SDK should always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.StringValue(resp))
}