Skip to content

Commit 093dd30

Browse files
authored
Merge pull request #31 from aws-samples/hb-dev-update
updated sample app ebextensions, updated syntax and conventions
2 parents 4f0f08f + d38133a commit 093dd30

File tree

9 files changed

+1850
-432
lines changed

9 files changed

+1850
-432
lines changed

.ebextensions/options.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ option_settings:
88
NEW_SIGNUP_TOPIC: '`{"Ref" : "NewSignupTopic"}`'
99
aws:elasticbeanstalk:container:nodejs:
1010
ProxyServer: nginx
11-
aws:elasticbeanstalk:container:nodejs:staticfiles:
11+
aws:elasticbeanstalk:environment:proxy:staticfiles:
1212
/static: /static

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
# Elastic Beanstalk CLI Files
44
.elasticbeanstalk/*
5+
node_modules/*

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1-
# AWS Elastic Beanstalk Express Sample App
1+
# AWS Elastic Beanstalk Express Sample App with Dynamo
22
This sample application uses the [Express](https://expressjs.com/) framework and [Bootstrap](http://getbootstrap.com/) to build a simple, scalable customer signup form that is deployed to [AWS Elastic Beanstalk](http://aws.amazon.com/elasticbeanstalk/). The application stores data in [Amazon DynamoDB](http://aws.amazon.com/dynamodb/) and publishes notifications to the [Amazon Simple Notification Service (SNS)](http://aws.amazon.com/sns/) when a customer fills out the form.
33

4-
## Features
5-
### Themes
4+
This example cannot be run locally.
5+
6+
You can get started using the following steps:
7+
1. Install the [AWS Elastic Beanstalk Command Line Interface (CLI)](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html).
8+
2. Add policies to the [default instance profile](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/iam-instanceprofile.html) to grant the EC2 instances in your environment permission to access DynamoDB and Amazon SNS:
9+
- Open the [Roles](https://console.aws.amazon.com/iam/home#roles) page in the IAM console.
10+
- Choose `aws-elasticbeanstalk-ec2-role`.
11+
- On the Permissions tab, choose Attach policies.
12+
- Select the managed policy for the additional services that your application uses. For this specific example, add `AmazonSNSFullAccess` and `AmazonDynamoDBFullAccess`.
13+
- Choose Attach policy.
14+
3. Run `eb init --platform node.js --region <region>` to initialize the folder for use with the CLI. Replace `<region>` with a region identifier such as `us-east-2` (see [Regions and Endpoints](https://docs.amazonaws.cn/en_us/general/latest/gr/rande.html#elasticbeanstalk_region) for a full list of region identifiers).
15+
4. Run `eb create --sample nodejs-example-express-dynamo` to begin the creation of a sample application that contains a load-balanced environment with the default settings for the Node.js platform.
16+
5. Once the environment creation process completes, run `eb open` to load the sample environment in your browser to verify the deployment has succeeded and is accessible.
17+
6. Deploy the source in this bundle using `eb deploy`.
18+
7. Once the deployment of this source bundle completes, run `eb open` to interact with the new webpage.
19+
8. Run `eb terminate --all` to clean up.
20+
21+
22+
## Themes
623
The code includes several Bootstrap themes from [bootswatch.com](http://bootswatch.com/). You can dynamically change the active theme by setting the THEME environment variable in the [Elastic Beanstalk Management Console](https://console.aws.amazon.com/elasticbeanstalk):
724

825
![](misc/theme-flow.png)
@@ -13,20 +30,4 @@ Installed themes include:
1330
* [default](http://bootswatch.com/default)
1431
* [flatly](http://bootswatch.com/flatly)
1532
* [slate](http://bootswatch.com/slate)
16-
* [united](http://bootswatch.com/united)
17-
18-
You can get started using the following steps:
19-
1. [Install the AWS Elastic Beanstalk Command Line Interface (CLI)](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html).
20-
2. Create an IAM Instance Profile named **aws-elasticbeanstalk-sample-role** with the policy in [iam_policy.json](iam_policy.json). For more information on how to create an IAM Instance Profile, see [Create an IAM Instance Profile for Your Amazon EC2 Instances](https://docs.aws.amazon.com/codedeploy/latest/userguide/how-to-create-iam-instance-profile.html).
21-
3. Run `eb init -r <region> -p "Node.js"` to initialize the folder for use with the CLI. Replace `<region>` with a region identifier such as `us-west-2` (see [Regions and Endpoints](https://docs.amazonaws.cn/en_us/general/latest/gr/rande.html#elasticbeanstalk_region) for a full list of region identifiers). For interactive mode, run `eb init` then,
22-
1. Pick a region of your choice.
23-
2. Select the **[ Create New Application ]** option.
24-
3. Enter the application name of your choice.
25-
4. Answer **yes** to *It appears you are using Node.js. Is this correct?*.
26-
7. Choose whether you want SSH access to the Amazon EC2 instances.
27-
*Note: If you choose to enable SSH and do not have an existing SSH key stored on AWS, the EB CLI requires ssh-keygen to be available on the path to generate SSH keys.*
28-
4. Run `eb create --instance_profile aws-elasticbeanstalk-sample-role` to begin the creation of your environment.
29-
1. Enter the environment name of your choice.
30-
2. Enter the CNAME prefix you want to use for this environment.
31-
5. Once the environment creation process completes, run `eb open` to open the application in a browser.
32-
6. Run `eb terminate --all` to clean up.
33+
* [united](http://bootswatch.com/united)

app.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Include the cluster module
2-
var cluster = require('cluster');
2+
const cluster = require('cluster');
33

44
// Code to run if we're in the master process
55
if (cluster.isMaster) {
66

77
// Count the machine's CPUs
8-
var cpuCount = require('os').cpus().length;
8+
const cpuCount = require('os').cpus().length;
99

1010
// Create a worker for each CPU
11-
for (var i = 0; i < cpuCount; i += 1) {
11+
for (let i = 0; i < cpuCount; i += 1) {
1212
cluster.fork();
1313
}
1414

@@ -23,18 +23,18 @@ if (cluster.isMaster) {
2323

2424
// Code to run if we're in a worker process
2525
} else {
26-
var AWS = require('aws-sdk');
27-
var express = require('express');
28-
var bodyParser = require('body-parser');
26+
const AWS = require('aws-sdk');
27+
const express = require('express');
28+
const bodyParser = require('body-parser');
2929

3030
AWS.config.region = process.env.REGION
3131

32-
var sns = new AWS.SNS();
33-
var ddb = new AWS.DynamoDB();
32+
const sns = new AWS.SNS();
33+
const ddb = new AWS.DynamoDB();
3434

35-
var ddbTable = process.env.STARTUP_SIGNUP_TABLE;
36-
var snsTopic = process.env.NEW_SIGNUP_TOPIC;
37-
var app = express();
35+
const ddbTable = process.env.STARTUP_SIGNUP_TABLE;
36+
const snsTopic = process.env.NEW_SIGNUP_TOPIC;
37+
const app = express();
3838

3939
app.set('view engine', 'ejs');
4040
app.set('views', __dirname + '/views');
@@ -49,7 +49,7 @@ if (cluster.isMaster) {
4949
});
5050

5151
app.post('/signup', function(req, res) {
52-
var item = {
52+
const item = {
5353
'email': {'S': req.body.email},
5454
'name': {'S': req.body.name},
5555
'preview': {'S': req.body.previewAccess},
@@ -62,7 +62,7 @@ if (cluster.isMaster) {
6262
'Expected': { email: { Exists: false } }
6363
}, function(err, data) {
6464
if (err) {
65-
var returnStatus = 500;
65+
let returnStatus = 500;
6666

6767
if (err.code === 'ConditionalCheckFailedException') {
6868
returnStatus = 409;
@@ -89,9 +89,9 @@ if (cluster.isMaster) {
8989
});
9090
});
9191

92-
var port = process.env.PORT || 3000;
92+
const port = process.env.PORT || 3000;
9393

94-
var server = app.listen(port, function () {
94+
const server = app.listen(port, function () {
9595
console.log('Server running at http://127.0.0.1:' + port + '/');
9696
});
9797
}

iam_policy.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)