chanzuckerberg / happy

Happy Path Deployment Tool

Home Page:https://chanzuckerberg.github.io/happy/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

chore: consolidate tailing aws logs to use the Go SDK

edulop91 opened this issue · comments

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