- Overview
- Prereqs
- Getting Started with Git
- Set up AWS account
- Connecting to your AWS Account to your personal device
- Set up project for AL2 target Mac, Ubuntu (aarch64/x86_64), and Windows (WSL 2 Ubuntu 20.04 LTS)
- After your project is set up use the following to build your code and deploy it to AWS test
- Setting up to test against a personal Slack bot
- Useful CDK commands and their descriptions
- How to Enable API Throttling
- Useful Slack Documentation
- A Rust implementation of a Slack bot that will be used by the CodeDevils Slack workspace.
- All resources are managed using AWS CDK.
- The main driver is AWS API Gateway to provide static endpoints and AWS Lambda for serverless compute/request handling.
- Install Rust: https://rustup.rs/
- Install NodeJS v16 (latest LTS version): https://nodejs.org/en/download/
- Install AWS CLI: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
- Install AWS CDK Toolkit:
npm install -g aws-cdk
- You may get a warning that -g is deprecated and to use --location=global instead
- Create a new local directory for this project.
- Run
git clone https://github.com/ASU-CodeDevils/devil_bot_rust.git
in that new directory.
- Create a new AWS account for free: https://aws.amazon.com
- Go to the IAM console (type "IAM" in search bar on AWS website after logging in).
- Click on "Users" on the left-hand side bar under "Access Management".
- Click "Add Users" to the right.
- For username choose something like "devil-bot-test-user-${your_asu_alias}" (e.g. "devil-bot-test-user-jtmichel").
- Make sure "Access key - Programmatic access" check box is checked.
- Click "Next: Permissions".
- Click "Attach existing policies directly".
- Check "AdministratorAccess" (you can use less permissions if you know what you're doing, but this should work fine as long as you don't give away your credentials).
- Click "Next: Tags".
- Click "Next: Review".
- Click "Create user".
- Copy both your "Access key ID" and your "Secret access key" somewhere locally (only store this temporarily then delete).
- Continue to "Connecting to your AWS Account" steps below.
- Run the following on your personal device's terminal.
aws configure
- For "access key" use your "Access key ID" from the "Set up AWS account" instructions above.
- For "secret access key" use your "Secret access key" from the "Set up AWS account" instructions above.
- For "default region name" use:
us-east-1
- For "defaut output format" use:
None
(just leave blank and press enter)
- If on Windows install and configure Ubuntu 20.04 LTS using WSL2 the following step are to be done wihtin that VM https://docs.microsoft.com/en-us/windows/wsl/install
- Ensure you've installed Rust, NPM, AWS-CDK Toolkit, and AWS-CLI
- Confirm you've setup your AWS account and Connected it!
chmod +x build-function.sh
sh build-function.sh
cdk bootstrap
cdk deploy
sh build-function.sh
cdk diff
(optional, but useful command)cdk deploy
- Do the following after creating the above infrastructure (after successfully running
cdk deploy
to your personal AWS account). - Go to the API Gateway console (type "API Gateway" in search bar on AWS website after logging in).
- Click on "APIs" on the left-hand side bar under "API Gateway".
- Check to make sure you are signed in under us-east-1
- Click on "RustSlackEndpoint".
- Click on "Stages" on the left-hand side bar under "API: RustSlackEndpoint".
- Click on "Prod" under "Stages".
- Copy the "Invoke URL" provided.
- Contact one of our officers and tell them you have your Slack bot API Gateway endpoint ready for a personal Slack bot app.
- Provide the officer with the URL and they will give you a Slack webhook URL which you can then plug in to the
environment
list indevil-bot-rust-cdk-stack.ts
. - This will allow you to test in the
#devil-bot-test Slack
channel while you are developing. - When you have your code ready for review, remove the environment variable before creating your PR. Follow the instructions found in
CONTRIBUTING.md
for more info on creating your PR.
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template
Sometimes you may not want to spam messages into the Slack channels when you want to test. In this case you can POST messages directly to your API Gateway endpoint and view CloudWatch logs to troubleshoot problems with your code.
Postman is a UI alternative to using curl
.
- Download postman for free from https://www.postman.com/downloads/
- Ignore the make an account messages and "workspaces" and just use the "scratchpad" offline feature. This used to be the only way Postman operated, but they are trying to make money so we will forgive them for begging us to use cloud storage on a platform that definitely doesn't need it.
- Under the scratchpad menu "Overview" click on the "Create a request" button.
- Click on the "GET" dropdown and swap to "POST".
- In the "Enter request URL" box insert your API Gateway URL obtained in the Setting up to test against a personal Slack bot section.
- Click on the "Body" tab and enter a modified version of one of the message body from below.
- Click on the "raw" radio button, and select "JSON" from the dropdown to the right of the radio buttons.
- You can now send requests directly to your endpoint.
{
"api_app_id": "XXXXXXXXXXX",
"authorizations": [
{
"enterprise_id": "XXXXXXXXX",
"is_bot": false,
"is_enterprise_install": false,
"team_id": "XXXXXXXXX",
"user_id": "XXXXXXXXX"
}
],
"enterprise_id": "XXXXXXXXX",
"event": {
"blocks": [
{
"block_id": "xXxx",
"elements": [
{
"elements": [
{
"text": "Test message here.",
"type": "text"
}
],
"type": "rich_text_section"
}
],
"type": "rich_text"
}
],
"channel": "XXXXXXXXXXX",
"channel_type": "group",
"client_msg_id": "9173c749-d7b3-4330-9576-590740901793",
"event_ts": "1645903860.916719",
"team": "XXXXXXXXX",
"text": "test",
"ts": "1645903860.916719",
"type": "message",
"user": "XXXXXXXXX"
},
"event_context": "4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMk43NkZaM1EiLCJhaWQiOiJBMDJVOUc4NUI2WiIsImNpZCI6IkMwMzUxR0o2MlEwIn0",
"event_id": "Ev0356A5S917",
"event_time": 1645903860,
"is_ext_shared_channel": false,
"team_id": "XXXXXXXXX",
"token": "oooooooooooooooooo",
"type": "event_callback"
}
{
"token": "Jhj5dZrVaK7ZwHHjRyZWjbDl",
"challenge": "3eZbrw1aBm2rZgRNFdxV2595E9CY3gmdALWMmHkvFXO7tYXAYM8P",
"type": "url_verification"
}
- Sign in to AWS
- In the search bar, search for API Gateway
- Click on RustSlackEndpoint
- In the left menu, click on Usage Plans
- In the Usage Plans menu, create a new usage plan
- This is pretty customizable. Recommended to cap your requests per month at 900,000