-
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] Null result from API.post() or (put) #5971
Comments
One of my guesses, is that it's linked to this issue : CodeGenieApp/serverless-express#99 |
I think it's definitively linked to this issue, since the body returned by the API is encoded in base64. It seems to me that Axios or the RestClient class (used by amplify) is unable to decode the base64 string |
Hey @shide1989, I tried to recreate your issue, but unfortunately, I wasn't able to reproduce it using the default I added important parts of my project below. Please let me know if there anything I am missing. // aws-exports.js
const awsmobile = {
"aws_project_region": "eu-central-1",
"aws_cognito_identity_pool_id": "eu-central-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"aws_cognito_region": "eu-central-1",
"aws_user_pools_id": "eu-central-1_xxxxxxxxx",
"aws_user_pools_web_client_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"oauth": {},
"aws_cloud_logic_custom": [
{
"name": "apid6e5a88b",
"endpoint": "https://xxxxxxxxxx.execute-api.eu-central-1.amazonaws.com/dev",
"region": "eu-central-1"
}
]
}; API.post('apid6e5a88b', '/conversations', {
body: { username: 'other' },
})
.then(r => console.log({ response: r }));
// console.log output
{
response: {
body: {
username: "other"
},
success: "post call succeed!",
url: "/conversations"
}
} // lambda function: index.js
const awsServerlessExpress = require('aws-serverless-express');
const app = require('./app');
const server = awsServerlessExpress.createServer(app);
exports.handler = (event, context) => {
console.log(`EVENT: ${JSON.stringify(event)}`);
return awsServerlessExpress.proxy(server, event, context, 'PROMISE').promise;
};
// lambda function: app.js
var express = require('express')
var bodyParser = require('body-parser')
var awsServerlessExpressMiddleware = require('aws-serverless-express/middleware')
var app = express()
app.use(bodyParser.json())
app.use(awsServerlessExpressMiddleware.eventContext())
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
next()
});
// ...
app.post('/conversations', function(req, res) {
res.json({success: 'post call succeed!', url: req.url, body: req.body})
});
// ...
app.put('/conversations', function(req, res) {
res.json({success: 'put call succeed!', url: req.url, body: req.body})
});
// ...
app.listen(3000, function() {
console.log("App started")
});
module.exports = app |
This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems. |
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 |
Describe the bug
I'm using
aws-amplify
API to call the Rest API I've setup using Amplify,but the return value is always
null
It used to work fine using the Lambda
Hello World
template, but switching to thelambda express
template made this happen.Inspecting the request shows that the result returned from the API is a correct JSON value , but once received the Amplify SDK seems to mess things up and remove the data.
The same happens for the
.put()
methodI suspect that deploying the new Lambda, some headers might be missing or some parameters might be missing, that makes the data decoding impossible
To Reproduce
Steps to reproduce the behavior:
Expected behavior
We should be able to see the data returned from the request.
Code Snippet
Screenshots
What is Configured?
If applicable, please provide what is configured for Amplify CLI:
const awsmobile = {
"aws_project_region": "eu-west-1",
"aws_appsync_graphqlEndpoint": "https://xxxxxxxxxxxx.appsync-api.eu-west-1.amazonaws.com/graphql",
"aws_appsync_region": "eu-west-x",
"aws_appsync_authenticationType": "API_KEY",
"aws_appsync_apiKey": "xxxxxx-xxxxxxxxxx",
"aws_cloud_logic_custom": [
{
"name": "esportsverify",
"endpoint": "https://xxxxxxx.execute-api.eu-west-1.amazonaws.com/develop",
"region": "eu-west-x"
}
],
"aws_content_delivery_bucket": "xxxxxx-xxxxxx-xxxxxxx-hostingbucket-develop",
"aws_content_delivery_bucket_region": "eu-west-1",
"aws_content_delivery_url": "https://xxxxx.cloudfront.net",
"aws_cognito_identity_pool_id": "eu-west-1:xxxxxx-xxxxx-xxxx-xxxxx-xxxxxx",
"aws_cognito_region": "eu-west-1",
"aws_user_pools_id": "eu-west-xxxxxx",
"aws_user_pools_web_client_id": "xxxxxxxxxx",
"oauth": {},
"aws_dynamodb_all_tables_region": "eu-west-1",
"aws_dynamodb_table_schemas": [
{
"tableName": "xxxxxx-develop",
"region": "eu-west-1"
},
{
"tableName": "xxxxxxxx-develop",
"region": "eu-west-1"
}
]
};
Environment
You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app.
-> Done but it doesn't show anything
The text was updated successfully, but these errors were encountered: