Installing a Test Application on Amazon EC2

2020-03-04 08:06发布

问题:

I want to use AWS products to build some application on it. For now, i want to test this -

1) Create a webpage hosted at AWS with a simple text box and a submit button, for checking if a number is prime. 2) Compile a C++ program on EC2 to accept a number and reply if it is prime.

Can someone list the steps involved in doing this? (The above example mirrors simplistically the actual application that i have in mind, with a http frontend and a c++ backend)

回答1:

If you use the default Linux AMI, you will gave a standard Apache installation ready to go. It sounds like the invocation style of your app is request-response, so at least to begin with, you could just use CGI to get Apache to run your app.

To achieve this, you would do something like this:

  1. Create a static html page with a form and a submit button which passes the form data to your app via CGI
  2. Install your app into an appropriate directory (see the Apache config for details) to run it via CGI, taking care to ensure the correct permissions are set
  3. Have your app parse the CGI environment variables to gather the input
  4. Perform the processing required
  5. Generate the resulting output as an HTTP response (to get started, just use text/plain).

Please note that there are many security issues to keep in mind here, so it is very important to perform strict validation on all data supplied by the web user for escaping issues, buffer overflows and so on.

If you aren't familiar with the above, you will need to read up on HTML forms, Apache configuration and basic HTTP headers at at minimum. There are plenty of examples out there, and some great books covering the topic.

To this end, various libraries have been developed to facilitate this:

  • Which C++ Library for CGI Programming?

There are also many other options for interfacing your app with Apache, such as FastCGI.