package main import ( "context" "fmt" "github.com/aws/aws-lambda-go/lambda" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ecs" ) type Event struct { Cluster string `json:"cluster"` Service string `json:"service"` Status string `json:"status"` DesiredCount int64 `json:"desiredCount"` } func HandleLambdaEvent(ctx context.Context, event Event) error { ecsRegion := "sa-east-1" params := struct { Cluster string Service string Status string DesiredCount int64 }{event.Cluster, event.Service, event.Status, event.DesiredCount} if event.Status == "stop" { params.DesiredCount = 0 } else if params.DesiredCount == 0{ params.DesiredCount = 1 }else{ params.DesiredCount = event.DesiredCount } sess := session.Must(session.NewSession(&aws.Config{ Region: aws.String(ecsRegion), })) svc := ecs.New(sess) input := &ecs.UpdateServiceInput{Cluster: aws.String(params.Cluster), Service: aws.String(params.Service), DesiredCount: aws.Int64(params.DesiredCount)} fmt.Println("Valores do cluster: ", params.Cluster, params.Service, params.DesiredCount) _, err := svc.UpdateService(input) if err != nil { fmt.Println(err) } else { println("sucesso, Cluster: " + params.Cluster,"Quantidade de Task:", params.DesiredCount) } return nil } func main() { lambda.Start(HandleLambdaEvent) }