Hello everyone! I am new to this forum and to serverless programming as well. I have a GoLang application which consists of many Lambda functions. Currently, I am trying to run a specific function by
- Deploying it to specified cloud storage
- Running: serverless invoke -f function-name -l
Here is my serverless.yml file:
service: LambdaConfigService
provider:
name: aws
runtime: go1.x
stage: test
region: us-east-1
versionFunctions: false
environment:
STAGE: ${self:provider.stage}
MAX_FRAME_NUM_TO_PROCESS: "3000"
MAX_URL_VALID_DURATION: "300"
S3_REGION: ${self:provider.region}
iamRoleStatements:
- Effect: Allow
Action: "s3:*"
Resource: "*"
functions:
Thumbnail:
handler: bin/thumbnail
description: Used in order to generate thumnails given a time range and a source id
timeout: 300
memorySize: 3008
events:
- http:
path: ai/thumbnail
method: post
cors: true
layers:
- {Ref: FfmpegLambdaLayer}
layers:
ffmpeg:
path: ffmpegLayer
And here is how I’ve organized my function code, specifically, its Handler function:
func main() {
glog.Info("Starting Thumbnail Lambda ...")
lambda.StartHandler(lambda.NewHandler(Handler{}))
}
type Handler struct{}
func (handler Handler) Invoke(ctx context.Context, payload []byte) ([]byte, error) {
glog.Info("Thumbnail Lambda Handler function has been Invoked ...")
lambdaConfig := config.Config{}
thumbnailLambdaStatus := status.Initialize()
apiGatewayEvent := new(events.APIGatewayProxyRequest)
if err := json.Unmarshal(payload, apiGatewayEvent); err != nil {
glog.Errorf("Error occurred while trying to unmarshal payload as APIGatewayProxyRequest. Error message - %v", err)
return nil, err
} else {
if err := json.Unmarshal([]byte(apiGatewayEvent.Body), &lambdaConfig); err != nil {
glog.Errorf("Error occurred while trying to unmarshal body of APIGatewayProxyRequest. Error message - %v", err)
return nil, err
}
err := lambdaConfig.Validate()
if err != nil {
glog.Errorf("Error during validation of Config struct. Error message - %v", err)
return nil, err
}
switch strings.ToUpper(apiGatewayEvent.HTTPMethod) {
case "POST":
resp, err := thumbnailLambda(&lambdaConfig, &thumbnailLambdaStatus)
if err != nil {
glog.Errorf("Error occurred while trying to execute Thumbnail Lambda's core logic. Error message - %v", err)
return nil, err
}
glog.Infof("Response: %s", resp.Body)
break
default:
err = fmt.Errorf("Invalid method: %s", apiGatewayEvent.HTTPMethod)
}
}
return nil, nil
}
I do realize that this cannot work since I am not sending any input to it. But, to my knowledge, I should at least get some messages that I’ve put in the code printed. For example, shouldnt I get message from main
function and Handler’s invoke
function printed?
What could be causing this error? I appreciate any sort of help!