Skip to content

Serverless slack sign-up with AWS Lambda, using "raw" AWS for now.

Notifications You must be signed in to change notification settings

dzimine/slack-signup-lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Slack Signup with AWS Lambda

Serverless slack sign-up with AWS Lambda, in Python. Inspired by Serverless Slack Invite Service.

Consider doing it with serverless framework, see https://github.com/dzimine/slack-signup-serverless/

This creates a serverless service for users to sign up for invitations to your Slack. Similar to slackin, but serverless, that is, no need to run (and pay for) a [virtual] server. The invitation function will run on demand and you only pay per use.

As a learning exercise for AWS Lambda and serverless, this project is a take one: it uses AWS "raw", with AWS all configurations done with aws CLI and some console, to understanding the fundamentals of Lambda and API Gateway, and to appreciate the need for a good framework, like serverless.com.

Disclaimer: The README.md are not (yet) full blown instructions but more "the notes to myself", PG rated, read on your risk.

Lambda

AWS Lambda cheat sheet:

  • Check what we get so far:

    aws --region=us-east-1 lambda list-functions
    
  • Zip up the file:

    zip -X -r ../deploy/invite.zip * 
    
  • Create a lambda function

    aws lambda create-function \
    --region us-east-1 \
    --function-name SlackInviteAWS \
    --zip-file fileb:https://../deploy/invite.zip \ 
    --handler invite.lambda_handler \ 
    --runtime python2.7 \
    --role arn:aws:iam::053075847820:role/lambda_basic_execution
    

    Note that the role need to exist there and have a policy to create and access CloudWatch log streams. You may find it easier to use AWS console to create one. If your function works but you can't see the logs, blame it on the role.

  • Sure enough I've messed up something so fix the code, re-zip the zip, and update a function:

    aws lambda update-function-code \
    --region us-east-1 \
    --function-name SlackInviteAWS \
    --zip-file fileb:https://../deploy/invite.zip
    
  • To update the function settings, (e.g., environment variables)

    aws lambda update-function-configuration \
    --region us-east-1 \
    --function-name SlackInviteAWS \
    --environment '{"Variables":{"SLACK_TEAM":"dz-test", "SLACK_TOKEN":"xxxx-111111100111-111111111111-111000111000-111eeeaa11"}}'
    

API Gateway

Follow the step by step instructions in the Step-by-step guide. At this point I said Fuck it I go serverless.com and re-implemented it, see https://github.com/dzimine/slack-signup-serverless/

The notes on this section are ways too long to post here and generally repeat the Step-by-step guide. There are few traps I got into, so I may still post it later.

  • CURL to test:

    $ curl -X POST -d '{ "email": "[email protected]", "first_name": "Donald" }' --url https://c27hhqorea.execute-api.us-east-1.amazonaws.com/prod/slack_invite/
    [true, "Invite sent"]
    
  • The Lambda function logs are in CloudWatch logs (update URL with your Lambda function name:
    https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logStream:group=/aws/lambda/SlackInviteAWS;streamFilter=typeLogStreamPrefix

Deploy web UI

About

Serverless slack sign-up with AWS Lambda, using "raw" AWS for now.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published