1

I am importing the lambda service as follows:

import (
    lambdaservice "github.com/aws/aws-sdk-go/service/lambda"
)


and use it as follows:

func InvokeCreateSessionLambda(payload invoketypes.Input) {
    l := &lambdaservice.Lambda{}
    data, _ := json.Marshal(payload)

    input := &lambdaservice.InvokeInput{
        Payload:        data,
        InvocationType: aws.String("RequestResponse"),
        FunctionName:   aws.String("MyValidFunctionARN"),
        ClientContext:  aws.String("{\"service\":\"somedata\"}"),
    }
    err := input.Validate()
    fmt.Println(err) // prints  <nil>
    r, e := l.Invoke(input) <panic>
    fmt.Print(e)
    fmt.Print(r)
}

but l.Invoke(input) panics with the (relevant) stack trace:

runtime error: invalid memory address or nil pointer dereference
<skipped some lines>
panic(0xac91e0, 0x1214ef0)
    /usr/local/go/src/runtime/panic.go:522 +0x1b5
test-lambda-go/vendor/github.com/aws/aws-sdk-go/aws/client.(*Client).NewRequest(...)
    /home/ayush/projects/gojects/src/test-lambda-go/vendor/github.com/aws/aws-sdk-go/aws/client/client.go:84
test-lambda-go/vendor/github.com/aws/aws-sdk-go/service/lambda.(*Lambda).newRequest(0xc000107498, 0xc0001f0680, 0xb22ac0, 0xc0001f0640, 0xb12080, 0xc0001f06c0, 0xc0000e2480)
    /home/ayush/projects/gojects/src/test-lambda-go/vendor/github.com/aws/aws-sdk-go/service/lambda/service.go:87 +0x3e
test-lambda-go/vendor/github.com/aws/aws-sdk-go/service/lambda.(*Lambda).InvokeRequest(0xc000107498, 0xc0001f0640, 0x6, 0xc0001fa000)
    /home/ayush/projects/gojects/src/test-lambda-go/vendor/github.com/aws/aws-sdk-go/service/lambda/api.go:1895 +0x102
test-lambda-go/vendor/github.com/aws/aws-sdk-go/service/lambda.(*Lambda).Invoke(0xc000107498, 0xc0001f0640, 0xc0001074c0, 0x1, 0x1)
    /home/ayush/projects/gojects/src/test-lambda-go/vendor/github.com/aws/aws-sdk-go/service/lambda/api.go:2017 +0x35

Any idea what's causing the error and how to fix this?

1 Answer 1

2

Try using the New function in the lambda package.

sess := session.Must(session.NewSessionWithOptions(session.Options{
    SharedConfigState: session.SharedConfigEnable,
}))

client := lambda.New(sess, &aws.Config{Region: aws.String("us-west-2")})
Sign up to request clarification or add additional context in comments.

Comments

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.