Documentation ¶
Overview ¶
Package task provides simple functions to run task on ECS.
Usage:
import "github.com/h3poteto/ecs-task/task"
Run a task ¶
When you want to run a task on ECS, please use this package as follows.
At first, you have to get a task definition. The task definition is used to run a task.
For example:
t, err := task.NewTask("cluster-name", "container-name", "task-definition-arn or family", "commands", false, "", 300 * time.Second, "profile", "region") // At first you have to get a task definition. taskDef, err := t.taskDefinition.DescribeTaskDefinition(t.TaskDefinitionName) if err != nil { return err } ctx, cancel := context.WithTimeout(context.Background(), t.Timeout) defer cancel() // Call run task API. tasks, err := t.RunTask(ctx, taskDef) if err != nil { return err } // And wait to completion of task execution. err = t.WaitTask(ctx, tasks)
Polling CloudWatch Logs ¶
You can polling CloudWatch Logs log stream.
For example:
// Get log group. group, streamPrefix, err := t.taskDefinition.GetLogGroup(taskDef, "Container Name") if err != nil { return err } w := NewWatcher(group, streamPrefix+"/" + "Container Name" + "Task ID", "AWS profile name", "ap-northeast-1") err = w.Polling(ctx) if err != nil { return err }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Task ¶
type Task struct { // ECS Cluster where you want to run the task. Cluster string // Container name which you want to run. Sometimes Task Definition has some container. So this package have to determine the container for run task. Container string // Name of Task Definition. You can provide full ARN, family or family:revision. TaskDefinitionName string // Command which you want to run. Command []*string // If you set 0, timeout is ignored. Timeout time.Duration // EC2 or Fargate LaunchType string // If you set Fargate as launch type, you have to set your subnet IDs. // Because Fargate demands awsvpc as network configuration, so subnet IDs are required. Subnets []*string // If you want to attach the security groups to ENI of the task, please set this. SecurityGroups []*string // If you don't enable this flag, the task access the internet throguth NAT gateway. // Please read more information: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking.html AssignPublicIP string // contains filtered or unexported fields }
Task has target ECS information, client of aws-sdk-go, command and timeout seconds.
func NewTask ¶
func NewTask(cluster, container, taskDefinitionName, command string, fargate bool, subnetIDs, securityGroupIDs string, timeout time.Duration, profile, region string) (*Task, error)
NewTask returns a new Task struct, and initialize aws ecs API client. If you want to run the task as Fargate, please provide fargate flag to true, and your subnet IDs for awsvpc. If you don't want to run the task as Fargate, please provide empty string for subnetIDs.
type TaskDefinition ¶
type TaskDefinition struct {
// contains filtered or unexported fields
}
TaskDefinition has client of aws-sdk-go.
func NewTaskDefinition ¶
func NewTaskDefinition(profile, region string) *TaskDefinition
NewTaskDefinition returns a new TaskDefinition struct, and initialize aws ecs API client.
func (*TaskDefinition) DescribeTaskDefinition ¶
func (d *TaskDefinition) DescribeTaskDefinition(taskDefinitionName string) (*ecs.TaskDefinition, error)
DescribeTaskDefinition gets a task definition. The family for the latest ACTIVE revision, family and revision (family:revision) for a specific revision in the family, or full Amazon Resource Name (ARN) of the task definition to describe.
func (*TaskDefinition) GetLogGroup ¶
func (d *TaskDefinition) GetLogGroup(taskDef *ecs.TaskDefinition, containerName string) (string, string, error)
GetLogGroup gets cloudwatch logs group and stream prefix.
type Watcher ¶
Watcher has log group information and CloudWatchLogs Client.
func NewWatcher ¶
NewWatcher returns a Watcher struct.
func (*Watcher) GetStreams ¶
func (w *Watcher) GetStreams() ([]*cloudwatchlogs.LogStream, error)
GetStreams get cloudwatch logs streams according to log group name and stream prefix.
func (*Watcher) WaitStream ¶
WaitStream waits until the log stream is generated.