Browse Source

output URL; fix relative URL problem; update README

Joe Lafiosca 6 years ago
parent
commit
00a6ac7a7a
5 changed files with 38 additions and 8 deletions
  1. 15 1
      README.md
  2. 1 1
      aws/config.example.sh
  3. 9 0
      aws/deploy.sh
  4. 12 5
      aws/sam-template.json
  5. 1 1
      views/index.jade

+ 15 - 1
README.md

@@ -9,7 +9,7 @@ Inspired by
 [How I hacked Slack into a community platform with Typeform](https://levels.io/slack-typeform-auto-invite-sign-ups/)
 and Socket.io's Slack page.
 
-This project supports Heroku, Azure and Cloud Foundry.
+This project supports Heroku, Azure, Cloud Foundry, and Amazon Web Services (AWS).
 
 [![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
 [![Deploy to Azure](http://azuredeploy.net/deploybutton.png)](https://azuredeploy.net/)
@@ -67,6 +67,20 @@ You can test your token via curl:
 
 Add the application settings that are defined in the environment variables above.
 
+### Amazon Web Services (AWS)
+
+If you have an AWS account and have already installed and configured the AWS CLI tool, you can easily deploy this application to API Gateway and Lambda via CloudFormation in a few minutes.
+
+Instead of editing `config.js`, take these steps:
+
+1. Copy `aws/config.example.sh` to `aws/config.sh`
+2. Edit the values in `aws/config.sh`, which correspond to the variables described above, plus these:
+    * `StackName`: the name of the CloudFormation stack to create
+    * `S3BucketArtifacts`: the name of an existing S3 bucket you have write access to, for storing deployment artifacts
+    * `S3PrefixArtifacts`: the prefix to use within that S3 bucket for all deployment artifacts written
+3. Run `aws/deploy.sh` to create the CloudFormation stack and deploy your application, outputting the URL
+4. (Optional) For a friendlier URL, log into the AWS web console and establish a custom domain pointing to the API Gateway stage deployed in step 3.
+
 ## Run
 [Node.js](http://nodejs.org/) is required.
 

+ 1 - 1
aws/config.example.sh

@@ -1,6 +1,6 @@
 #!/bin/bash
 
-StackName=SlackInviteAutomation
+StackName=SlackInviter
 
 S3BucketArtifacts=your-artifact-bucket
 S3PrefixArtifacts=cloudformation/slack-invite-automation

+ 9 - 0
aws/deploy.sh

@@ -44,3 +44,12 @@ aws cloudformation deploy \
 	RecaptchaSecretKey="${RecaptchaSecretKey}" \
 	Locale="${Locale}"
 
+Url=$(aws cloudformation describe-stacks --stack-name ${StackName} | grep OutputValue | cut -f 4 -d'"')
+
+echo
+echo 'Deployed Slack Inviter!'
+echo
+echo "Account Id: ${AwsAccountId}"
+echo "    Region: ${AwsRegion}"
+echo "Stack Name: ${StackName}"
+echo "       URL: ${Url}"

+ 12 - 5
aws/sam-template.json

@@ -1,7 +1,7 @@
 {
 	"AWSTemplateFormatVersion": "2010-09-09",
 	"Transform": "AWS::Serverless-2016-10-31",
-	"Description": "Slack Invite Automation",
+	"Description": "Slack Inviter",
 	"Parameters": {
 		"CommunityName": {
 			"Type": "String",
@@ -35,11 +35,11 @@
 		}
 	},
 	"Resources": {
-		"SlackInviteApi": {
+		"SlackInviterApi": {
 			"Type": "AWS::Serverless::Api",
 			"Properties": {
 				"DefinitionUri": "api-swagger.json",
-				"StageName": "Api",
+				"StageName": "Express",
 				"Variables": {
 					"ExpressFunction": { "Ref": "ExpressFunction" }
 				}
@@ -72,7 +72,7 @@
 					"ExpressProxyApiRoot": {
 						"Type": "Api",
 						"Properties": {
-							"RestApiId": { "Ref": "SlackInviteApi" },
+							"RestApiId": { "Ref": "SlackInviterApi" },
 							"Path": "/",
 							"Method": "ANY"
 						}
@@ -80,7 +80,7 @@
 					"ExpressProxyApiGreedy": {
 						"Type": "Api",
 						"Properties": {
-							"RestApiId": { "Ref": "SlackInviteApi" },
+							"RestApiId": { "Ref": "SlackInviterApi" },
 							"Path": "/{proxy+}",
 							"Method": "ANY"
 						}
@@ -88,5 +88,12 @@
 				}
 			}
 		}
+	},
+	"Outputs": {
+		"Url": {
+			"Value": {
+				"Fn::Sub": "https://${SlackInviterApi}.execute-api.${AWS::Region}.amazonaws.com/${SlackInviterApi.Stage}/"
+			}
+		}
 	}
 }

+ 1 - 1
views/index.jade

@@ -15,7 +15,7 @@ html
           h2 #{__('HEADER', community)}
         .content
           .information
-            form(method="POST", action="/invite")#join-form.form
+            form(method="POST", action="invite")#join-form.form
               input(type="email", name="email", autofocus, placeholder="#{__('ENTER_EMAIL')}")#slack-email.field
               if tokenRequired
                 input(type="text", name="token", placeholder="#{__('ENTER_TOKEN')}")#slack-token.field