Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fix error with AWS Lambda handler, DynamoDB Put req?

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:    "123@mail.com",
        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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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

Please update your main function with👇

func main() {
    lambda.Start(Put)
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading