How to fix error with AWS Lambda handler DynamoDB Put req

0 votes

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.

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.

Dec 30, 2022 in AWS by Tejashwini
• 3,820 points

edited 5 days ago 4 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP