func getS3ConfigFile()

in init/fluent_bit_init_process.go [209:253]


func getS3ConfigFile(userInput string) string {
	// Preparation for downloading S3 config files
	if !s3ClientCreated {
		createS3Client()
	}

	// e.g. "arn:aws:s3:::user-bucket/s3_parser.conf"
	s3ARN, err := arn.Parse(userInput)
	if err != nil {
		logrus.Fatalf("[FluentBit Init Process] Could not parse arn: %s\n", userInput)
	}
	bucketAndFile := strings.SplitN(s3ARN.Resource, "/", 2)
	if len(bucketAndFile) != 2 {
		logrus.Fatalf("[FluentBit Init Process] Could not parse arn: %s\n", userInput)
	}

	bucketName := bucketAndFile[0]
	s3FilePath := bucketAndFile[1]

	// get bucket region
	input := &s3.GetBucketLocationInput{
		Bucket: aws.String(bucketName),
	}

	output, err := s3Client.GetBucketLocation(input)
	if err != nil {
		logrus.Errorln(err)
		logrus.Fatalf("[FluentBit Init Process] Cannot get bucket region of %s + %s, you must be the bucket owner to implement this operation\n", bucketName, s3FilePath)
	}

	bucketRegion := aws.StringValue(output.LocationConstraint)
	// Buckets in Region us-east-1 have a LocationConstraint of null
	// https://docs.aws.amazon.com/sdk-for-go/api/service/s3/#GetBucketLocationOutput
	if bucketRegion == "" {
		bucketRegion = "us-east-1"
	}

	// create a downloader
	s3Downloader := createS3Downloader(bucketRegion)

	// download file from S3 and store in the directory "/init/fluent-bit-init-s3-files/"
	downloadS3ConfigFile(s3Downloader, s3FilePath, bucketName, s3FileDirectoryPath)

	return s3FilePath
}