Skip to content

chore: consolidate tailing aws logs to use the Go SDK #133

@edulop91

Description

@edulop91

We should phase out shelling out to external dependencies and instead directly use Go clients + sdks. One particular example is we have 2 paths for tailing aws logs:

  • aws cli --
    func (s *Orchestrator) Logs(stackName string, service string, since string) error {
    // TODO get logs path from ECS instead of generating
    logPrefix := s.backend.Conf().LogGroupPrefix()
    logPath := fmt.Sprintf("%s/%s/%s", logPrefix, stackName, service)
    awsProfile := s.backend.Conf().AwsProfile()
    regionName := "us-west-2"
    awsArgs := []string{"aws", "--profile", awsProfile, "--region", regionName, "logs", "tail", "--since", since, "--follow", logPath}
    awsCmd, err := exec.LookPath("aws")
    if err != nil {
    return errors.Wrap(err, "failed to locate the AWS cli")
    }
    cmd := &exec.Cmd{
    Path: awsCmd,
    Args: awsArgs,
    Stderr: os.Stderr,
    Stdout: os.Stdout,
    }
    log.Println(cmd)
    if err := s.executor.Run(cmd); err != nil {
    return errors.Wrap(err, "failed to get logs from AWS")
    }
    return nil
    }
  • go sdk --
    package aws
    import (
    "context"
    cwlv2 "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
    )
    type GetLogsFunc func(*cwlv2.GetLogEventsOutput, error) error
    func (b *Backend) getLogs(
    ctx context.Context,
    input *cwlv2.GetLogEventsInput,
    f GetLogsFunc,
    ) error {
    paginator := cwlv2.NewGetLogEventsPaginator(
    b.cwlGetLogEventsAPIClient,
    input,
    )
    for paginator.HasMorePages() {
    err := f(paginator.NextPage(ctx))
    if isStop(err) {
    return nil
    }
    if err != nil {
    return err
    }
    }
    return nil
    }

We should get rid of the aws cli path and replace it with the Go SDK path

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions