5つのパラメータを取るAWSラムダ関数があります。パラメータの1つは、PHPのバックエンドからgetパラメータとして渡されるUrlです。 URLは渡される間にエンコードされ、パラメータはJSONObjectとして渡されます。私はamazonaws sdk(com.amazonaws.util.json)からJSONObjectを使用しています。AWSラムダ - PHPからJavaラムダへのGETパラメータとしてURLを送信する
入力オブジェクトは、値を取得する前に、ラムダ関数のJSONObjectに変換されます。この問題は、URLのためにJsonへの入力に変換するときに発生します。私はURLの代わりに文字列を渡す場合、ラムダは正常に動作します。ここで
は、関連するコードと出力です:PHPから
@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";
}
コール - >ラムダ:::ラムダためCloudWatchのからhttps://xxx.amazonaws.com/prod/sendsmsapiresource?name=test&number=9618143233&url=http%3A%2F%2Fexample.com%2F&message=testmesage&user_id=1
出力:::
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を渡す?