- Newest
- Most votes
- Most comments
The issue you're experiencing is due to a mismatch between how the Lambda function is returning the response and how your Android code is trying to parse it. Your Lambda function is correctly returning a JSON object with a "body" field, but your Android code is trying to parse the entire response as if it were the body itself.
To fix this, you should modify your Android code to directly use the response body without trying to extract a nested "body" field. Here's how you can adjust your Kotlin code:
-
Remove this line: val bodyString = jsonResponse.getString("body")
-
Replace it with: val bodyJson = jsonResponse
-
Then proceed with extracting the futureObjectKey as you were doing before: if (bodyJson.has("futureObjectKey")) { val futureObjectKey = bodyJson.getString("futureObjectKey") // Use futureObjectKey as needed }
This change should resolve the "No value for body" error you're seeing. The Lambda function is already returning the data you need in the top-level JSON object, so there's no need to look for a nested "body" field.
Also, make sure your OkHttp client is configured to parse the response as a JSON object. If you're using Gson or another JSON parsing library, you might need to adjust how you're converting the response to a JSONObject.
Remember to handle potential exceptions when parsing the JSON, as the response might not always be in the expected format.
Sources
Changing AWS Lambda Function prompt value with an event instead of changing environment variable. | AWS re:Post
Lambda Function not returning all properties in a response via function URL. | AWS re:Post
answered a year ago
Relevant content
asked a year ago
asked a year ago
- AWS OFFICIALUpdated 5 years ago
- AWS OFFICIALUpdated 4 years ago
- AWS OFFICIALUpdated 3 months ago
