AWS Lambda - 将URL作为GET参数从PHP转换为Java Lambda函数

问题描述:

我有一个AWS lambda函数,它需要5个参数。其中一个参数是从PHP后端传递的Url,作为get参数。 url在传递时被编码,并且参数作为JSONObject传递。请注意,我从amazonaws sdk(com.amazonaws.util.json)使用JSONObject。AWS Lambda - 将URL作为GET参数从PHP转换为Java Lambda函数

在从中获取值之前,输入对象在lambda函数中转换为JSONObject。转换为输入到Json时,问题出现了,因为这个url。如果我通过一个字符串代替url,lambda工作得很好。

下面是相关代码和输出:

@Override 
    public String handleRequest(Object input, Context context) { 

     LambdaLogger logger = context.getLogger(); 

     if (DEBUG) 
      logger.log("Starting LambdaFunction"); 

     TwilioRestClient client = new TwilioRestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN); 

     try { 

      if (DEBUG) 
       logger.log("Input: " + input.toString()); 

      JSONObject object = new JSONObject(input.toString());//Problem here 

      if (DEBUG) 
       logger.log("Object: " + object.toString()); 

      String name = object.getString("name"); 
      String message = object.getString("message"); 
      String survey_url = object.getString("url"); 
      String user_id = object.getString("user_id"); 
      String number = object.getString("number"); 

      if (DEBUG) { 
       logger.log("Name: " + name); 
       logger.log("Message: " + message); 
       logger.log("Survey Url: " + survey_url); 
       logger.log("User ID: " + user_id); 
       logger.log("Number: " + number); 
      } 

      // Other functionality 
     } 

     catch (JSONException e) { 
      logger.log("JSONException"); 
      e.printStackTrace(); 
     } catch (TwilioRestException e) { 
      logger.log("TwilioRestException"); 
      e.printStackTrace(); 
     } 

     catch(Exception e) { 
      e.printStackTrace(); 
     } 

     return "End of SendSMSLambdaFunction"; 
    } 

从PHP调用 - > LAMBDA :::从CloudWatch的https://xxx.amazonaws.com/prod/sendsmsapiresource?name=test&number=9618143233&url=http%3A%2F%2Fexample.com%2F&message=testmesage&user_id=1输出

为LAMBDA :::

Input: {name=test, number=9618143233, message=test, url=http://www.example.com, user_id=1} 
JSONException 
com.amazonaws.util.json.JSONException: Expected a ',' or '}' at 55 [character 56 line 1] 

哪有我将url作为get参数传递给lambda函数?

这个问题得到解决,当我添加了''的URL,在PHP的lambda调用。所以现在调用调用看起来像https://xxx.amazonaws.com/prod/sendsmsapiresource?name=test&number=9618143233&url=%27http%3A%2F%2Fexample.com%2F%27&message=testmesage&user_id=1和我的输入lambda来作为Input: {name=test, number=9618143233, message=test, url='http://www.example.com', user_id=1}