Getting Started with AWS
Deploying a Web Application

Step 3: Deploy the App Using AWS Elastic Beanstalk

You can easily deploy the signup app using Elastic Beanstalk. You upload an app version (for example, a ZIP file) to Elastic Beanstalk, and then provide some information about the app. Elastic Beanstalk launches an environment and provisions the AWS resources needed to run your code.

Create an Elastic Beanstalk Environment

Create an environment to run the sample application.

To launch an environment

  1. Open the Elastic Beanstalk console using this preconfigured link:

  2. For Platform, choose Node.js.

  3. For Application code, choose Sample application.

  4. Choose Review and launch.

  5. On the Security card, choose Modify.

  6. For IAM instance profile, choose the role that you created earlier (gsg-signup-role).

  7. Choose Save.

  8. Choose Create app.

In just a few minutes, Elastic Beanstalk provisions the networking, storage, compute, and monitoring infrastructure required to run a scalable web application in AWS. Once the site is up and running, you can deploy a new version of your application code to the environment at any time.

Create the Source Bundle

Elastic Beanstalk requires that your app be bundled as a single ZIP or ZIP file. A bundle can't include a top-level folder, so you must compress the individual app files, rather than compressing the directory that contains them.

To create the source bundle in a file browser

  1. Open the application folder eb-node-express-signup-master.

  2. Select all the items in the folder, including the subfolders. Do not select the top-level folder.


    The signup application includes a hidden folder named .ebextensions that contains a configuration file that configures Node.js platform settings. You may need to configure your file browser to show hidden files to see this folder.

  3. Right-choose the selected items and select the option to compress them, such as Send to > Compressed (zipped) Folder (Windows) or Compress Items (macOS).

For more information about compressing files using a variety of tools, see Creating an Application Source Bundle in the AWS Elastic Beanstalk Developer Guide.

Deploy the Signup Application

Deploy the source bundle to the Elastic Beanstalk environment.

To deploy the application source bundle

  1. Return to the environment that you created in the Elastic Beanstalk console.

  2. Choose Upload and Deploy.

  3. Choose Browse and upload the source bundle that you created in the previous section.

  4. Choose Deploy.

Test the App

When the deployment is finished and the environment health is listed as "Green", open the URL of the app.

You can test the signup app by filling out the form and verifying that you receive the notification.

Troubleshoot Deployment Issues

If you followed all the steps, opened the URL, and got no app, there's a deployment problem. With our sample app, which runs on an nginx server, a deployment problem is likely to result in a "502 Bad Gateway" message. The "502" message is not very informative. To troubleshoot a deployment issue, you may need to use the logs that are provided by Elastic Beanstalk.

For example, let's say that, in the process of updating app_config.json, you accidentally leave off a quotation mark. Then, when you finish the deployment, you see the 502 error. How do you find and fix the problem?

Of course, you'd try to catch such an error in development. But if an error does get through to production, or you just want to update your app, Elastic Beanstalk makes it fast and easy to redeploy.

To troubleshooting a deployment issue

  1. In the Elastic Beanstalk console, in the navigation pane for your environment, choose Logs.

  2. At the Logs page, choose Snapshot Logs. Wait for your environment to update, and then choose View log file. In the log file, you can see just what happened on the server side during deployment and runtime. There's a lot of material to sort through, and we're not going to cover the different sections of the log in this tutorial. But if you did indeed leave out a quotation mark in the config file and you scrolled through the log to /var/log/nodejs/nodejs.log, you'd find an error similar to this:

    SyntaxError: Unexpected token u at Object.parse (native) at Object.<anonymous> (/var/app/current/server.js:23:15) at Module._compile (module.js:449:26) at Object.Module._extensions..js (module.js:467:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.runMain (module.js:492:10) at process.startup.processNextTick.process._tickCallback (node.js:245:9) undefined:2 "AWS_REGION": us-west-2",^

    In this case, the "Unexpected token u" message appears because the parser expected a quotation mark instead of a "u" in the string us-west-2". Now that we've found the problem, we can fix it.

  3. If you were actually troubleshooting this issue, you'd go back to the app code in your local environment and fix the missing quotation mark. Then you'd create a new .zip file to upload.

  4. To redeploy the app, go to the Elastic Beanstalk Dashboard, choose Upload and Deploy, and choose your updated .zip file.

  5. Change the version label to something new. For example, if your first deployment was labeled "Archive", you can label this second deployment "Archive-2."

  6. Choose Deploy. Elastic Beanstalk will update the environment.

  7. When the environment is updated and listed as "Green", use the app URL to test your app.