1

Trying to create a Lambda to interact with my DynamoDB. This specific Lambda is to put/write an item to the DB:

package main

import (
    "fmt"

    "github.com/aws/aws-lambda-go/lambda"
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/dynamodb"
    "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
)

type Item struct {
    Email    string `json:"email"`
    Password string `json:"password"`
    Rname    string `json:"rname"`
}

func Put() error {

    // Create a session - London Region
    session, err := session.NewSession(&aws.Config{
        Region: aws.String("eu-west-2")},
    )
    if err != nil {
        fmt.Println(err)
    }

    svc := dynamodb.New(session)

    // Create instance of Item Struct
    item := Item{
        Email:    "[email protected]",
        Password: "12345678",
        Rname:    "abcde",
    }

    // Marshall Item
    av, err := dynamodbattribute.MarshalMap(item)

    if err != nil {
        fmt.Println("Got error marshalling map:")
        fmt.Println(err)
    }

    // Create Item
    input := &dynamodb.PutItemInput{
        Item:      av,
        TableName: aws.String("accountsTable"),
    }

    _, err = svc.PutItem(input)

    if err != nil {
        fmt.Println("Got error calling PutItem:")
        fmt.Println(err)
    }
    return err
}

func main() {
    lambda.Start(Put())
}

However getting the error:

{
  "errorMessage": "handler is nil",
  "errorType": "errorString"
}

I have changed the handler in run time settings to main too so don't think that would be the issue.

Building with:

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a main.go

and putting the zip of the executable into AWS via console (no IAC's)

Any help would be greatly appreciated to resolve this error! Thanks.

4
  • Have you tried to execute an empty Lambda function without the logic? Commented Dec 29, 2022 at 19:34
  • I'm not sure what you mean, just like a simple hello world to print? Commented Dec 29, 2022 at 19:34
  • Exactly, just to rule out if the error is from the function setup or from custom logic. Commented Dec 29, 2022 at 19:42
  • just tried and got a failure just trying to print out hello, the function that main calls returning the same hello string. Fails on "handler kind string is not func" Commented Dec 29, 2022 at 19:45

1 Answer 1

1

You need to pass function handle not function result to lambda.Start

Please update your main function with👇

func main() {
    lambda.Start(Put)
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - just realised this before I came back to here! Silly one to be stuck on for so long haha

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.