-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API.post returns null #6390
Comments
I was at [email protected] with Expo SDK 35. I used to have the API exports under: "aws_cloud_logic_custom" block and I've updated them to define them as API.endpoints with no change. The lambda code is being executed correctly in AWS and the response as far as I can see in API-gateway logs have the expected response object. Thanks! |
Can you share your redacted aws-exports.js or API.endpoints config? |
Sure thing: const awsmobile = {
"aws_project_region": "xxx",
"aws_content_delivery_bucket": "xxx",
"aws_content_delivery_bucket_region": "xxx",
"aws_content_delivery_url": "xxx",
"aws_cognito_identity_pool_id": "xxx",
"aws_cognito_region": "xxx",
"aws_user_pools_id": "xxx",
"aws_user_pools_web_client_id": "xxx",
/*
"aws_cloud_logic_custom": [
{
"name": "deviceListRest",
"endpoint": "https://xxx.execute-api.xxx.amazonaws.com/Prod",
"region": "xxx"
},
{
"name": "deviceControl",
"endpoint": "https://xxx.execute-api.xxx.amazonaws.com/Prod",
"region": "xxx"
},
{
"name": "sensorData",
"endpoint": "https://xxx.execute-api.xxx.amazonaws.com/Prod",
"region": "xxx"
},
{
"name": "Notifications",
"endpoint": "https://xxx.execute-api.xxx.amazonaws.com/Prod",
"region": "xxx"
},
{
"name": "userPreferences",
"endpoint": "https://xxx.execute-api.xxx.amazonaws.com/Prod",
"region": "xxx"
},
{
"name": "deviceSchedules",
"endpoint": "https://xxx.execute-api.xxx.amazonaws.com/Prod",
"region": "xxx
}
], */
//Get rid of: Unhandled promise rejection: Error: No credentials, applicationId or region
//https://github.com/aws-amplify/amplify-js/issues/5918
Analytics: {
disabled: true
},
API: {
endpoints: [
{
"name": "deviceListRest",
"endpoint": "https://xxx.execute-api.xxx.amazonaws.com/Prod",
"region": "xxx"
},
{
"name": "deviceControl",
"endpoint": "https://xxx.execute-api.xxx.amazonaws.com/Prod",
"region": "xxx"
},
{
"name": "sensorData",
"endpoint": "https://xxx.execute-api.xxx.amazonaws.com/Prod",
"region": "xxx"
},
{
"name": "Notifications",
"endpoint": "https://xxx.execute-api.xxx.amazonaws.com/Prod",
"region": "xxx"
},
{
"name": "userPreferences",
"endpoint": "https://xxx.execute-api.xxx.amazonaws.com/Prod",
"region": "xxx"
},
{
"name": "deviceSchedules",
"endpoint": "https://xxx.execute-api.xxx.amazonaws.com/Prod",
"region": "xxx"
}
]
}
};
export default awsmobile; |
@txnico can you share your package.json and how you are configuring Amplify? |
@elorzafe - here's my package.json. Regarding the configuration, please see aws-exports I posted above. { |
@txnico I mean are you doing something like this? import { Amplify, API } from 'aws-amplify';
import awsconfig from './aws-exports';
Amplify.configure(awsconfig); |
import Amplify from '@aws-amplify/core'; Amplify.configure(awsmobile); |
@txnico where are you importing API? |
@elorzafe - The imports above are in the main app entry-point whereas the API import happens in child components that execute api calls. I'm importing API as: import { API } from 'aws-amplify'; |
Any update or suggestions? |
@txnico Have you tried to import Amplify from "aws-amplify" rather than core?If not could you give that a try, cleaning your node_modules and package lock files? Something like this, import Amplify, {API, Auth} from 'aws-amplify'; Amplify.configure(awsmobile); |
Hi @ashika01 - same behavior unfortunately after clearing out node_modules, package lock files and updating imports. |
@ashika01 - Thanks for the suggestion. The API in question returns plain-text JSON responses and both #5971 and the referred CodeGenieApp/serverless-express#99 discuss mime types and compression. |
I revisited this issue this week and found out that the issue was being caused by the lack of serialization in the body of the response object within my lambda function. It must have been a change in AWS API since previous API.post calls with the unedited lambda functions worked previously for months. |
We need a JSON string for the body in order to access it in our response message. See this comment: aws-amplify/amplify-js#6390 (comment) I had this issue with my own function which was returning null on my JSON.stringify(response). I found the above comment and it made it work! i.e. I could access the return body.
We need a JSON string for the body in order to access it in our response message. See this comment: aws-amplify/amplify-js#6390 (comment) I had this issue with my own function which was returning null on my JSON.stringify(response). I found the above comment and it made it work! i.e. I could access the return body.
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Upon upgrading to "aws-amplify": "3.0.20" any call to API.post REST returns null.
To Reproduce
Running managed Expo app with Expo SDK 37
Any call to AWS lambda via API.post.
POST Response: null
Expected behavior
A response object to be returned once promise is complete.
Code Snippet
The text was updated successfully, but these errors were encountered: