Cannot find the correct server path after success deployment to beanstalk

I think I successfully deployed parse server to AWS beanstalk. However, I cannot find the correct server path to send my request.

In the beanstalk environment, I set “NODE_ENV=production” and “PARSE_MOUNT=/parse”
“SERVER_URL=http://ec2-161-189-119-69.cn-northwest-1.compute.amazonaws.com.cn/parse”.

Then, when I typed "curl -X POST -H ‘X-Parse-Application-Id: UcQ8spwcu8gkatSvxp5dLfjQJvg32uUJIQLDgVjf’ -H ‘Content-Type: application/json’ -d ‘{“foo”:“bar3”}’ ec2-161-189-119-69.cn-northwest-1.compute.amazonaws.com.cn/parse/classes/TestObject", nothing comes back.

If I type "wget ec2-161-189-119-69.cn-northwest-1.compute.amazonaws.com.cn/parse", it just returns a standard html page.

So, what is the correct path to send my request? I checked the log files and find nothing concerning.

Thanks

I guess your current url is SERVER_URL=http://ec2-161-189-119-69.cn-northwest-1.compute.amazonaws.com.cn/parse/parse. Maybe you should change SERVER_URL=http://ec2-161-189-119-69.cn-northwest-1.compute.amazonaws.com.cn/parse to SERVER_URL=http://ec2-161-189-119-69.cn-northwest-1.compute.amazonaws.com.cn.

Thanks for pointing this out.

I changed ““SERVER_URL=http://ec2-161-189-119-69.cn-northwest-1.compute.amazonaws.com.cn”.

Now, when I type " `curl -X POST -H ‘X-Parse-Application-Id: UcQ8spwcu8gkatSvxp5dLfjQJvg32uUJIQLDgVjf’ -H ‘Content-Type: application/json’ -d ‘{“foo”:“bar3”}’ ec2-161-189-119-69.cn-northwest-1.compute.amazonaws.com.cn/parse/classes/TestObject", the response is “curl: (52) Empty reply from server”.

If I type "curl -X GET -H “X-Parse-Application-Id: UcQ8spwcu8gkatSvxp5dLfjQJvg32uUJIQLDgVjf” ec2-161-189-119-69.cn-northwest-1.compute.amazonaws.com.cn/parse/classes/TestObject", it still returns a html page.

Moreover, I tested the project locally and everything works fine. This happens after I uploaded the code to beanstalk.

Any ideas?

Thanks

Do I need to provide a port number for the request?

  • Use localhost for server URL, otherwise your requests run over the load balancer and you pay for internal Cloud Code requests like you’d pay for external requests.
  • The PORT env variable is automatically set by the EB environment according to the port of your listener configuration, requests are also automatically routed to that port, so you don’t have to set a port for your curl request

You’d need to share your Parse Server config to tell which env vars are actually used by Parse Server; I suggest you deploy the parse server example repo without modifying anything to get it running, and provide a full list of your env vars, then others will be able to support you easier

Thanks for your reply. I just changed SERVER_URL=localhost, but it still does not work.

I did download the entire code zip from github and uploaded to beanstalk without any changes.
I have also created a beanstalk in the US west region and it has the same problem.

Here are my env variables:

Do you see any problems here? Thanks

Here are my entire configurations. I have also allowed all incoming/outgoing traffic. So, firewall should not be a problem here.

I tried the “curl -X POST” command again. The beanstalk instance in China does not return anything while the beanstalk instance in the US returns “curl: (52) Empty reply from server”. I don’t know what causes the difference and whether it matters.

Just an off-topic observation: you are not using a load balancer, which makes TLS rather difficult to implement.

Also, now that you have apparently exposed your URL and master key, I suggest to change both to prevent unwanted access and costs.

I have changed my master key and URL. Thanks for your reminder.

First off, you want to enable logs for your EB environment and look at the Node.js and nginx logs in your CloudWatch Log Groups. The logs will tell you more about the actual issue, otherwise this is just tapping in the dark.

If you look at the Parse Server Example repo index.js file, there are some notable entries:

const databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
const config = {
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
};
const mountPath = process.env.PARSE_MOUNT || '/parse';
const port = process.env.PORT || 1337;

The following parameters are currently not set correctly:

  • databaseURI: this is not set in your environment, because you have set DATABASE_URIDATABASE_URI instead of just DATABASE_URI; this means Parse Server most likely cannot connect to a database
  • serverURL: this is not set correct in your environment, and unless the exposed port in EB environment is exactly 1337, I think this cannot be set via an environment variable. Because parse server is mounted on the port assigned by EB (process.env.PORT), but you do not know which port that is when you set the environment variable.

It’s important to understand that Parse Server has 2 URL parameters:

  • serverURL: used by Parse Server when it needs to call itself
  • publicServerURL: used by Parse Server when it needs to tell external parties how it can be reached, from outside of your EB environment

The internal serverURL usually looks like http://localhost:1337/parse, but in your case you do not know whether the port is 1337. The EB environment tells Node.js to which port it routes incoming requests via the process.env.PORT variable. So you would need to compose the serverURL in index.js (that means modifying the example repo) to make it look like this:

const serverURL = `http://localhost${process.env.PORT}/parse`;

The same goes for the publicServerURL, which would look like this:

const publicServerURL = `http://ec2-161-189-119-69.cn-northwest-1.compute.amazonaws.com.cn/parse`;

Note that you do not have to include the port in the publicServerURL, because EB is automatically routing any request to that URL to the assigned port that is the port in process.env.PORT, on which Parse Server is mounted. Also note that this is not using TLS (https protocol), so all traffic is transferred unencrypted, which you may not want, thinking about login passwords, etc.

I think we really need to update the AWS instructions in the parse-server-example repo, to make this easier.

@hkblue You may want to follow Check Validity of Instructions / Buttons · Issue #387 · parse-community/parse-server-example · GitHub for an update on AWS deployment.

Thanks. I will definitely have a look. I agree that the AWS beanstalk instruction is not clear.

I just searched the parse-server-example folder, there is no “publicServerURL”. Is this really necessary?

Also, I suspect whether the parse server really is running in Beanstalk. In AWS document, it requires Add a configuration file that sets the Node Command to “npm start”:

**`node-express/.ebextensions/nodecommand.config`**

```
option_settings:
  aws:elasticbeanstalk:container:nodejs:
    NodeCommand: "npm start"

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs_express.html

In parse server sample configuration file, there is no such configuration.

I am just surprised that the beanstalk deployment instruction is so out-of-date and nobody even corrected those mistakes.

I have also hard coded the environmental variables in index.js. But it still does not work. This makes me wonder whether my code is really running. Is there a way to check for this in Beanstalk?

No, it’s not necessary. If you just want to try things out, you can set the serverURL to be your EB domain.

Not needed, see the docs:

There are several options to start your application. You can add a Procfile to your source bundle to specify the command that starts your application. When you don’t provide a Procfile , Elastic Beanstalk runs npm start if you provide a package.json file. If you don’t provide that either, Elastic Beanstalk looks for the file app.js orserver.js , in this order, and runs it.

There is a 1-click deploy button that seems to have ceased to work. There are existing tutorials if you search online. There is already an open issue for this, as I have posted earlier.

I think one reason why there was no urge to update this was that AWS EB is a cloud service that requires some more knowledge that is not Parse Server related. AWS is not really an easy platform if you start developing, there are simpler ones like Heroku, that you may want to try out.

Without sharing your code and logs it will be difficult to help you, especially since your questions are also about AWS EB basics. You can connect to the instance using eb ssh to see what’s going on or look at the CloudWatch log files, as I suggested previously.

In any case, here is what you can try:

  • look at the CloudWatch logs, there you will also see whether Parse Server is running and if now, what the error is
  • start with a simple nodejs express app where you just return a ‘hello’, without using Parse Server, to make sure the EB configs are fine
  • once you got the simple app working and you understand EB a bit more, deploy Parse Server and share your index.js code

Thanks. I will give it a try.

Do you have a timeline when you will fix the AWS EB deploy button?

I think if the button works, it will help a lot of people.

I know Heroku is much easier and I have used Heroku. But Heroku is not available in China. So, AWS EB is my only choice. Another reason is the cost. Heroku is several times more expensive than AWS EB for the same hardware configuration.

What I mean is because serverURL variable is not in the code, even if we set this variable, the code cannot use this variable.

Or, do I miss something here? Even if serverURL is not in the code, the code can still use this variable?