如何将webook通知中的参数导入AWS Lambda函数?

时间:2017-05-01 23:16:58

标签: java amazon-web-services http-post aws-lambda braintree

我对如何通过API网关将我的Lambda函数连接到Braintree的Webhooks感到困惑。我知道webhooks通过api gateway via和endpoint URL调用我的lambda函数,但是我不确定如何设置我的lambda函数来正确处理它并使用webhooks在调用函数时将作为参数传递的值。我现在有以下内容:

package com.amazonaws.lambda.submerchantapproved;

import java.util.HashMap;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

import com.amazonaws.services.lambda.runtime.events.DynamodbEvent;
import com.braintreegateway.BraintreeGateway;
import com.braintreegateway.Environment;
import com.braintreegateway.WebhookNotification;
import com.braintreegateway.WebhookNotification.Kind;

public class SubmerchantApproved implements RequestHandler<Object, String> {


    public String handleRequest(Object request, Context context) {

        BraintreeGateway gateway = new BraintreeGateway(
              Environment.SANDBOX,
              "MyValue",
              "MyValue",
              "MyValue"
        );

        WebhookNotification webhookNotification = gateway.webhookNotification().parse(
                request.queryParams("bt_signature"),
                request.queryParams("bt_payload")
       );


        String woofer = "";



        return woofer;
    }

}

但这不起作用或正确。我的意思是如何将这些bt_signature和by_payload值放入我的lambda函数中? webhooks通过相关的http-POST请求传递数据。

1 个答案:

答案 0 :(得分:0)

嗯,您的Object request正是这些请求参数的确切位置。

Java Lambdas有两种主要方案:

  1. 您可以在代理模式下配置API网关,并在Java代码中解析输入流。 AWS员工非常友好地为您编写这个即用型示例:http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html#api-gateway-proxy-integration-lambda-function-java enter image description here
  2. 您可以使用传统的API网关映射,但是您必须实现一个将实现bt_signatureby_payload等参数的请求类。同样,AWS提供了一个很棒的模板/示例:http://docs.aws.amazon.com/lambda/latest/dg/java-handler-io-type-pojo.html