lambda_s3

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2023 License: Unlicense Imports: 10 Imported by: 0

README

GoLangS3Lambda

Simplest utility to upload and download files to S3 through AWS Lambda

How to Build locally

  1. make build

How to Test locally

  1. cp .env.example .env copy the example .env file to use as a base
  2. nano .env update the existing values with your own
  3. make test

How to Use

  1. go get seantcanavan/...

Sample Code


Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBoundaryValueMissing = errors.New("request contained no boundary value in the Content-Type header")
View Source
var ErrContentTypeHeaderMissing = errors.New("request contained no Content-Type header")
View Source
var ErrDownloadingS3File = errors.New("unable to download the given file from S3")
View Source
var ErrEmptyFileDownloaded = errors.New("the provided S3 file to download is empty")
View Source
var ErrNewAWSSession = errors.New("error creating new AWS Session")
View Source
var ErrOpeningMultiPartFile = errors.New("unable to open *multipart.FileHeader")
View Source
var ErrParameterBucketEmpty = errors.New("required parameter bucket is empty")
View Source
var ErrParameterNameEmpty = errors.New("required parameter name is empty")
View Source
var ErrParameterRegionEmpty = errors.New("required parameter region is empty")
View Source
var ErrParsingMediaType = errors.New("error parsing media type from Content-Type header. Make sure your request is formatted correctly")
View Source
var ErrReadingMultiPartFile = errors.New("unable to read *multipart.FileHeader")
View Source
var ErrReadingMultiPartForm = errors.New("reading of multipart form failed. verify input size is <= maxFileSizeBytes")
View Source
var ErrUploadingMultiPartFileToS3 = errors.New("unable to upload *multipart.FileHeader bytes to S3")

Functions

func DownloadFileFromS3

func DownloadFileFromS3(region, bucket, name string) ([]byte, error)

func GetFileHeadersFromLambdaReq

func GetFileHeadersFromLambdaReq(lambdaReq events.APIGatewayProxyRequest, maxFileSizeBytes int64) ([]*multipart.FileHeader, error)

GetFileHeadersFromLambdaReq accepts a lambda request directly from AWS Lambda after it has been proxied through API Gateway. It returns an array of *multipart.FileHeader values. One for each file uploaded to Lambda.

Types

type UploadRes

type UploadRes struct {
	S3Path string
	S3URL  string
}

func UploadFileHeaderToS3

func UploadFileHeaderToS3(fileHeader *multipart.FileHeader, region, bucket, name string) (*UploadRes, error)

UploadFileHeaderToS3 takes a single *multipart.FileHeader from the Lambda request and uploads it to S3. It the upload is successful it returns the full path to the file in S3 as well as the URL for web access.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL