ibratoev/aws-slackin

Missing files?

Opened this issue · 1 comments

Unless I'm confused the slack.template HTML file references some JavaScript files that you have left out of this repo due to some rules in the .gitignore. Is there a reason those are not included or another place that I can get them? Currently getting this when clicking "invite" button:

Uncaught ReferenceError: apigClientFactory is not defined

FWIW, there are a ton of steps missing from the documentation, the files that you are missing are created after you setup the API Gateway, you can then generate the SDK package from the deployment.

Deployment steps

  1. Build the lambda package with the appropriate information
  2. Create the lambda function in your AWS account. I'd recommend creating a zip file (see below for help on that), and remember to set the Handler to run.lambda_handler
  3. Create a new API Gateway API
  4. After API has been created, click the Actions button and create a POST handler, and tell it to execute the lambda function you created before. It will ask you to confirm that the API Gateway will be allowed to execute your lambda, this is required so say yes.
  5. Once you've created the POST method, click it, then click on the Actions button again, and click Enable CORS (if you get errors from the website about missing authentication you forgot this step). This creates a handler for the OPTIONS method automatically, which is required for CORS to work
  6. Click Actions button, and then click Deploy API. On the screen that comes up, you'll need to provide a name for the endpoint, for example prod or staging depending on the type of deployment you want to do
  7. Once the API has been deployed it brings you to a page for the newly deployed API, that should contain a tab called SDK Generation, go there and select Javascript from the dropdown menu and then click Generate SDK. This will generate and start the download of a zip file that contains all the extra files missing from the web folder.
  8. Unzip the SDK files to a new folder, and copy the lib folder and the apigClient.js file into the web folder
  9. Upload the contents of the web folder to your web-server / S3 bucket for hosting
  10. ???
  11. Profit

Lambda zip file generation

To create the zip-file for the Lambda you'd need to run the following commands:

cd lambda
cp slack-invite/run.template slack-invite/run.py
sed -i '' 's/"token": ".*"/"token": "YOUR_SLACK_API_TOKEN_HERE"/' slack-invite/run.py
pip install -Ur slack-invite/requirements.txt -t slack-invite
(cd slack-invite; zip -r ../slack-invite.zip request* run.py)

This will create a zip file in the lambda folder that you can upload to the Lambda service, already configured for your Slack workspace.

If you are running OSX with Python installed from homebrew, you'll need to create a new file, setup.cfg in the lambda folder with the following content

[install]
prefix=

Makefile

I also played around a bit, and wrote a small Makefile that will let you easily configure and create the zip file.

UNAME := $(shell uname -s)
PYDIR := slack-invite
ZIP := slack-invite.zip
PIP ?= $(shell which pip)

all: | silent
	@echo $(PIP)
	$(info Available targets: build, clean)

build:
# Ensure that we have pip in our path, or prompt the user to tell us where pip is located
ifeq ($(PIP),)
	@echo PIP: $(PIP)
	$(error Couldnt find pip in your path. You can tell make where it is with: make build PIP=/path/to/pip)
endif

# Required for Python installed from homebrew on OSX, so creating the file just in case if we are running
# on OSX
ifeq ($(UNAME),Darwin)
	@echo "[install]\nprefix=" > setup.cfg
endif

# Make sure that the SLACK API token is defined in the environment
ifeq ($(TOKEN),)
	$(error You must pass TOKEN as an argument, ex; make build TOKEN="SLACK_API_TOKEN")
endif
	@if [ ! -f slack-invite/run.py ]; then cp $(PYDIR)/run.template $(PYDIR)/run.py; fi
	@sed -i '' 's/"token": ".*"/"token": "$(TOKEN)"/' $(PYDIR)/run.py
	@$(PIP) install -Ur $(PYDIR)/requirements.txt -t $(PYDIR) > /dev/null
	@(cd $(PYDIR); zip -r ../$(ZIP) request* run.py > /dev/null)

clean:
	$(info Cleaning up temp files created during build)
	@rm -rf setup.cfg

silent:
	@:

,PHONY: all build clean silent

I've done some quick testing, works for my environment on OSX, but YMMV, but worst case, you can just run the following commands