dpba63888 2019-06-15 14:40
浏览 221
已采纳

无法以编程方式调用AWS Lambda

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条回答 默认 最新

  • doushou8730 2019-06-15 16:06
    关注

    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")})
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 qt中connect两个signal
  • ¥20 pix2pixHD运行测试命令时出现数据类型错误无法反向传播的问题
  • ¥15 python处理Excel符合条件的行自动填写数据分类
  • ¥15 汇编hook举例并讲解(通俗易懂,学习用)
  • ¥20 用c++语言模拟键盘电子琴设计
  • ¥15 STM32cubemx生成keil工程,有问题与正常的情况不同,求解!
  • ¥15 如何自动点击银行app的安全键盘,实现密码自动输入
  • ¥15 关于四边形重叠的问题
  • ¥15 用verilog语言设计一个简易的八音符电子琴,可通过按键输入来控制音响。演奏时可以选择是手演奏(由键盘输入)或自动演奏已存入的乐曲。能够自动演奏多首乐曲,且每首乐曲可重复演奏
  • ¥15 sap gui脚本每次到导出Excel的时候就停住不动。不会另存为。