duanmaduan1848 2019-07-01 11:35
浏览 117

调用AWS Lambda时使用Handler函数和Invoke函数是否有所不同

Is there a difference when using Handler function to invoke AWS Lambda, and when using Invoke(input *InvokeInput) function in Go?

I need my Lambda to be invoked in multiple ways. For example, sometimes I need it to be invoked synchronously (as REST API) and sometimes I need it to be invoked asynchronously. How do I achieve this?

Do I create something like this:

func main(){

svc := lambda.New(session.New())
input := &lambda.InvokeInput{
    ClientContext:  aws.String("MyApp"),
    FunctionName:   aws.String("MyFunction"),
    InvocationType: aws.String("Event"),
    LogType:        aws.String("Tail"),
    Payload:        []byte("fileb://file-path/input.json"),
    Qualifier:      aws.String("1"),
}

result, err := svc.Invoke(input)
if err != nil {
 ....
}

}

Or do I create a Handler function like this:

func main(){
     lambda.Start(Handler)
}

func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error){
   ....
}

How do I handle both cases where sometimes I need to invoke lambda asynchronously and provide input payload as JSON, and sometimes I need to invoke lambda synchronously (REST API) and provide input as HTTP Request? Is there a way to Invoke lambda as a REST API without passing events.APIGatewayProxyRequest as an function argument?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题