Skip to content

Instantly share code, notes, and snippets.

@niski84
Created March 2, 2023 21:23
Show Gist options
  • Save niski84/82d5277743216176369e4891099f1426 to your computer and use it in GitHub Desktop.
Save niski84/82d5277743216176369e4891099f1426 to your computer and use it in GitHub Desktop.
get EB app logs
package main
import (
"errors"
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/elasticbeanstalk"
)
func getEBAppLogs(sess *session.Session, envName string, outputFile string) error {
// Create Elastic Beanstalk client
svc := elasticbeanstalk.New(sess)
// Retrieve logs for Elastic Beanstalk environment
params := &elasticbeanstalk.RequestEnvironmentInfoInput{
EnvironmentName: aws.String(envName),
InfoType: aws.String("tail"),
}
resp, err := svc.RequestEnvironmentInfo(params)
if err != nil {
return err
}
// Write logs to output file
file, err := os.Create(outputFile)
if err != nil {
return err
}
defer file.Close()
_, err = file.WriteString(*resp.Message)
if err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment