// Config returns the default configuration without credentials. // To retrieve a config with credentials also included use // `defaults.Get().Config` instead. // // Generally you shouldn't need to use this method directly, but // is available if you need to reset the configuration of an // existing service client or session. func Config() *aws.Config { return aws.NewConfig(). WithCredentials(credentials.AnonymousCredentials). WithRegion(os.Getenv("AWS_REGION")). WithHTTPClient(http.DefaultClient). WithMaxRetries(aws.UseServiceDefaultRetries). WithLogger(aws.NewDefaultLogger()). WithLogLevel(aws.LogOff). WithSleepDelay(time.Sleep) }
func main() { flag.Parse() fmt.Println("Hello world!") log.Println("Step 1: Configuring AWS") ecsCli := ecs.New(session.New(aws.NewConfig(). WithRegion("eu-west-1"). WithCredentials(credentials.NewStaticCredentials(*key, *secret, "foo")))) log.Println("Configuring AWS succeeded") log.Println("Step 2: Check ECS cluster") describeClusterOut, err := ecsCli.DescribeClusters(&ecs.DescribeClustersInput{ Clusters: []*string{clusterName}, }) if err != nil { log.Fatal(err) } if ff := describeClusterOut.Failures; len(ff) > 0 { log.Fatalf("Cluster resource '%s' failed: %v", *ff[0].Arn, *ff[0].Reason) } log.Printf("Checking cluster '%s' succeeded", *clusterName) log.Println("Step 3: Check ECS Service") describeServicesOut, err := ecsCli.DescribeServices(&ecs.DescribeServicesInput{ Services: []*string{serviceName}, }) if err != nil { log.Fatal(err) } origRunningCount := describeServicesOut.Services[0].RunningCount log.Printf("Checking service '%s' succeeded (%d tasks running)", *serviceName, *origRunningCount) log.Println("Step 4: Register New Task Definition") var cd []*ecs.ContainerDefinition taskDefinitionFile, err := os.Open(*taskDefinitionFileName) if err != nil { log.Fatal(err) } defer taskDefinitionFile.Close() err = json.NewDecoder(taskDefinitionFile).Decode(&cd) if err != nil { log.Fatal(err) } registerTaskDefinitionOut, err := ecsCli.RegisterTaskDefinition(&ecs.RegisterTaskDefinitionInput{ ContainerDefinitions: cd, Family: taskDefinitionName, }) if err != nil { log.Fatal(err) } if *registerTaskDefinitionOut.TaskDefinition.Status == "INACTIVE" { log.Fatalf("Task definition (%s) is inactive", *registerTaskDefinitionOut.TaskDefinition.TaskDefinitionArn) } taskDefinitionArn := registerTaskDefinitionOut.TaskDefinition.TaskDefinitionArn log.Printf("Registering task definition '%s' succeeded", *taskDefinitionArn) _, err = ecsCli.UpdateService(&ecs.UpdateServiceInput{ DesiredCount: desiredTasksCount, Service: serviceName, TaskDefinition: taskDefinitionArn, }) if err != nil { log.Fatal(err) } }