Lambda at provided.al2023 using golang not invoking handler function

0

I have a simple Lambda which is configured to be triggered on s3:ObjectCreated:* event. So when I add an object to s3 bucket my lambda is triggered but lambda handler registered is not invoked. Code:

package main

import (
	"context"
	"fmt"
	"github.com/aws/aws-lambda-go/lambda"
)

func HandlerS3(ctx context.Context, s3Event events.S3Event) error {
	fmt.Println("Handler is called")
	fmt.Println("Handler exiting")
	return nil
}

func main() {
	fmt.Println("Starting Main")
	lambda.Start(HandlerS3)
	fmt.Println("Ending Main")
}

I get following logs

2024-03-13T16:27:58.889+05:30	INIT_START Runtime Version: provided:al2023.v14 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2024-03-13T16:27:58.922+05:30	Starting Main
2024-03-13T16:28:08.899+05:30	INIT_REPORT Init Duration: 10009.62 ms Phase: init Status: timeout
2024-03-13T16:28:08.954+05:30	Starting Main
2024-03-13T16:28:14.921+05:30	INIT_REPORT Init Duration: 6006.23 ms Phase: invoke Status: timeout

It looks like there's an issue with initialization or perhaps a missing component or misconfiguration causing the handler not to trigger. Has anyone encountered a similar situation or can offer insights into why HandlerS3 isn't being invoked as expected?

  • Could you Verify that all necessary dependencies are included in your Lambda deployment package. If you're using external libraries or packages, make sure they are properly imported and included in the deployment package

  • This is how code is compiled and there are no errors

    Compiling code for linux/arm64

    env GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -tags lambda.norpc -o ./bin/bootstrap ./cmd

  • Is the Lambda function configured for the arm64 instruction set architecture? See https://docs.aws.amazon.com/lambda/latest/dg/foundation-arch.html#foundation-arch-config

  • Runtime: Amazon Linux 2023 HandlerInfo: bootstrap ArchitectureInfo: arm64

  • The only error I got while reproducing this was the following missing import in the code. I was not able to build the binary without it. "github.com/aws/aws-lambda-go/events"

    GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o bootstrap -tags lambda.norpc main.go

    have you checked that?

nbitto
asked 2 months ago164 views
1 Answer
0

I added a service ticket in AWS and got a solution

Why Lambda was failing: Lambda functions calls init() of modules and a hard coded timeout of 10ms is kept by AWS. For my function AWS sdk is not able to complete init() in 10ms. Cause: I was using golang on M1 Mac and was compiling for GOOS=linux GOARCH=arm64. Issue was with code compiled with m1 Mac. After compiling same code using Cloud9 or Docker with x68_64 emulated this issue is not seen.

nbitto
answered a month ago
profile picture
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions