无法以编程方式调用 AWS lambda

我正在导入 lambda 服务,如下所示:


import (

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

)



并按如下方式使用它:


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)

}

但l.Invoke(input)对(相关)堆栈跟踪感到恐慌:


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

知道导致错误的原因以及如何解决此问题吗?


斯蒂芬大帝
浏览 144回答 1
1回答

一只斗牛犬

尝试使用包New中的函数lambda。sess := session.Must(session.NewSessionWithOptions(session.Options{&nbsp; &nbsp; SharedConfigState: session.SharedConfigEnable,}))client := lambda.New(sess, &aws.Config{Region: aws.String("us-west-2")})
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go