As I m using AWS Mobile hub for Cloud Logic integration.
How would i send data to the lambda function?
Code:
public void postCloudLogic(String mName,String mClass) {
// Create components of api request
final String method = "POST";
final String path = "/test_rds_lambda/?name="+mName+"&class="+mClass;
final String body = "";
final byte[] content = body.getBytes(StringUtils.UTF8);
final Map parameters = new HashMap<>();
parameters.put("lang", "en_US");
final Map headers = new HashMap<>();
// Use components to create the api request
ApiRequest localRequest =
new ApiRequest(apiClient.getClass().getSimpleName())
.withPath(path)
.withHttpMethod(HttpMethodName.valueOf(method))
.withHeaders(headers)
.addHeader("Content-Type", "application/json")
.withParameters(parameters);
...
As you can see i used:
final String path = "/test_rds_lambda/?name="+mName+"&class="+mClass;
This is the error i get from it:
{message=No method found matching route test_rds_lambda/%3Fname%3DYoME%26class%3DYoClass for http method POST.}
My Request URL path has
?,=
etc, but they are changed to HEX. i.e
%3Fname%3D
How to prevent that from happening as it is working in "test api" in aws console.
So, i have solved the issue by putting data in JSONObject and then passing it into body parameter of cloud logic.
public void callCloudLogic() throws JSONException {
// Create components of api request
final String method = "POST";
final String path = "/lambda_func";
*--> JSONObject data =new JSONObject();
*--> data.put("mCase","1");
*--> final String body = data.toString();
*--> final byte[] content = body.getBytes(StringUtils.UTF8);
final Map parameters = new HashMap<>();
parameters.put("lang", "en_US");
final Map headers = new HashMap<>();
// Use components to create the api request
ApiRequest localRequest =
new ApiRequest(apiClient.getClass().getSimpleName())
.withPath(path)
.withHttpMethod(HttpMethodName.valueOf(method))
.withHeaders(headers)
.addHeader("Content-Type", "application/json")
;