{"id":38839049,"url":"https://github.com/kyhau/slack-command-app-cdk","last_synced_at":"2026-01-17T13:58:51.471Z","repository":{"id":37098241,"uuid":"367565659","full_name":"kyhau/slack-command-app-cdk","owner":"kyhau","description":"A Slack Command App that can handle requests triggered from a Slack Command which will take longer than 3 seconds to process, and posts the details back to the user (deploy with CDK v2 and test with sam-beta-cdk).","archived":false,"fork":false,"pushed_at":"2026-01-11T22:01:37.000Z","size":545,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-12T00:53:26.355Z","etag":null,"topics":["aws","aws-apigateway","aws-cdk","aws-dynamodb","aws-lambda","hacktoberfest","python","sam-beta-cdk","slack-bot","slack-commands"],"latest_commit_sha":null,"homepage":"https://kyhau.github.io/slack-command-app-cdk/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kyhau.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-05-15T07:15:14.000Z","updated_at":"2026-01-11T22:01:39.000Z","dependencies_parsed_at":"2025-12-08T00:07:15.674Z","dependency_job_id":null,"html_url":"https://github.com/kyhau/slack-command-app-cdk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kyhau/slack-command-app-cdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyhau%2Fslack-command-app-cdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyhau%2Fslack-command-app-cdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyhau%2Fslack-command-app-cdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyhau%2Fslack-command-app-cdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kyhau","download_url":"https://codeload.github.com/kyhau/slack-command-app-cdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyhau%2Fslack-command-app-cdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28509766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-apigateway","aws-cdk","aws-dynamodb","aws-lambda","hacktoberfest","python","sam-beta-cdk","slack-bot","slack-commands"],"created_at":"2026-01-17T13:58:51.375Z","updated_at":"2026-01-17T13:58:51.442Z","avatar_url":"https://github.com/kyhau.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# slack-command-app-cdk\n\n[![githubactions](https://github.com/kyhau/slack-command-app-cdk/actions/workflows/slackapp-build.yaml/badge.svg)](https://github.com/kyhau/slack-command-app-cdk/actions/workflows/slackapp-build.yaml)\n[![CodeQL](https://github.com/kyhau/slack-command-app-cdk/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/kyhau/slack-command-app-cdk/actions/workflows/codeql-analysis.yml)\n[![SecretsScan](https://github.com/kyhau/slack-command-app-cdk/actions/workflows/secrets-scan.yml/badge.svg)](https://github.com/kyhau/slack-command-app-cdk/actions/workflows/secrets-scan.yml)\n\nThis repo creates a [Slack Commands](https://api.slack.com/interactivity/slash-commands) App/bot that responds to a command (i.e. `/find`) and sends the response to the same channel.\n\nIf you want to use [Slack Chat](https://api.slack.com/interactivity/slash-commands) that responds to messages when the app is mentioned (i.e. `@\u003capp-name\u003e`) and sends the response to the corresponding thread, see another repo [kyhau/slack-chat-app-cdk](https://github.com/kyhau/slack-chat-app-cdk).\n\nThis SlackApp can handle requests triggered from a Slash Command which will take longer than [3 seconds](https://api.slack.com/events-api) to process, and posts the details back to the user.\n\nAll notable changes to this project will be documented in [CHANGELOG](./CHANGELOG.md).\n\n---\n\n## Overview\n\nThis repo provides the source code for building\n\n1. A [Slack Command](https://api.slack.com/interactivity/slash-commands) App/Bot with AWS API Gateway and Lambda Functions, deploying with [CDK v2](https://docs.aws.amazon.com/cdk/latest/guide/work-with-cdk-v2.html) and testing wth SAM CLI ([sam-beta-cdk](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-cdk-getting-started.html)).\n\n2. An OAuth 2.0 authorization flow service for sharing the Slack App with other Workspaces without registering in the public Slack App Directory. For details see \"Apps distributed to multiple workspaces\" in [Distributing Slack apps](https://api.slack.com/start/distributing#multi_workspace_apps). This stack includes an AWS API Gateway, a Lambda Function, and a DynamoDB table, with AWS WAF (optional).\n\n### Slack App Architecture\n\n![SlackApp-ArchitectureOverview](docs/SlackApp-ArchitectureOverview.png)\n\n1. An API Gateway to provide an endpoint to be invoked from a Slack Command.\n2. A Lambda Function [lambda/ImmediateResponse.py](lambda/ImmediateResponse.py) to perform authentication, some basic checks and send an intermediate response to Slack within 3 seconds (Slack requirement). This function invokes another Lambda function to to the request tasks (synchronously invocation for quick task; asynchronous invocation for long tasks).\n3. A Lambda Function [lambda/AsyncWorker.py](lambda/AsyncWorker.py) to perform actual operation that may take more than 3 seconds to finish.\n4. A Lambda Function [lambda/SyncWorker.py](lambda/SyncWorker.py) to perform actual operation that takes less than 3 seconds to finish.\n6. CloudWatch Loggroup for API Gateway and Lambda Functions.\n\n### OAuth 2.0 API Architecture\n\n![OAuth2API-ArchitectureOverview](docs/OAuth2API-ArchitectureOverview.png)\n\n1. An API Gateway to provide an endpoint as the Sharable URL in Slack.\n2. A Lambda Function [lambda/OAuth.py](lambda/OAuth.py) to perform OAuth 2.0 flow and turn the auth code into access token then store it in a DynamoDB table.\n3. A DynamoDB table for storing the oauth tokens of all app installations.\n4. CloudWatch Loggroup for API Gateway and Lambda Functions.\n\n---\n\n## Prerequisites\n\n### Setup on Slack\n\nTo create a **Slack Command** in Slack (the default command in this repo is **`/testcdk`**)\n1. Navigate to https://api.slack.com/apps.\n2. Select **Create New App** and select **Slash Commands**.\n3. Enter the name **`/testcdk`** for the command and click **Add Slash Command Integration**.\n4. Enter the provided API endpoint URL in the URL field.\n5. Copy the **Verification Token** from **Basic Information**.\n\n### Setup secrets\n\n- Use [scripts/create_ssm_parameters.py](scripts/create_ssm_parameters.py) to set up AWS SSM Parameter SecureString for storing the required secrets.\n\n### Review and update app settings\n\n- [env_dev.json](env_dev.json) and [env_prd.json](env_prd.json)\n- [settings_dev.json](settings_dev.json) and [settings_prd.json](settings_prd.json)\n\n---\n\n## Deployment (without using GitHub Actions/Workflows)\n\nPrerequisites\n1. Install CDK v2: `npm install -g aws-cdk@next`\n2. Install Python 3.8 or above.\n3. Update [env_dev.json](env_dev.json) with you AWS account number and region that the Slack App is being deployed to.\n4. Update [settings_dev.json](settings_dev.json) to include the Slack domains, team IDs and channel IDs that the Slack App serves.\n\n```bash\n# Create and activate virtual env (optional)\n\n# Install requirements\npip install -r requirements.txt\n\n# First time\ncdk bootstrap\n# Or\ncdk ls\n\ncdk synth\n\n# Deploy the stack\ncdk deploy K-CDK-SlackCommandApp\n\n# Clean up\nrm -rf cdk.out package */__pycache__ */*.egg-info */out.json\n```\n\n## Try it on Slack\n\nE.g. if command is `/testcdk`, then\n\n1. Run `/testcdk async`\n2. Run `/testcdk sync`\n\n---\n\n## Protecting the API Gateways with AWS WAF\n\n1. Add `AWS::WAFv2::RuleGroup` to protect the Slack App API Gateway by specifying rules such as\n    1. ByteMatchStatement: SearchString: Slackbot 1.0 (+https://api.slack.com/robots)\n    2. ByteMatchStatement: SearchString: team_id=TODO-slack-team-id\n    3. ByteMatchStatement: SearchString: team_domain=TODO-slack-domain\n\n---\n\n## To Share the Slack App with other Slack Workspaces\n\nIn order to share a Slack App with other Slack Workspaces without registering in the public Slack App Directory, you will need to deploy also the following stack of the OAuth 2.0 authorization flow service.\n\nFor details see \"Apps distributed to multiple workspaces\" in [Distributing Slack apps](https://api.slack.com/start/distributing#multi_workspace_apps).\n\nFor details of Slack OAuth 2.0 v2 see\n- https://api.slack.com/authentication/oauth-v2\n- https://api.slack.com/methods/oauth.v2.access\n\n\n[lambda/OAuth.py](lambda/OAuth.py) also performs further authorization check with `app_id`, `team_id` and `channel_id`.\n\n### Deployment (without using GitHub Actions/Workflows)\n\n1. You will need to deploy also the following stack, which will create another service for for performing the OAuth 2.0 flow and turn the auth code into access token then store the details in a AWS DynamoDB table.\n\n    ```\n    cdk deploy K-CDK-SlackCommandAppSharing\n    ```\n\n2. Go to api.slack.com, select your app, then\n    1. Go to **Settings | OAuth \u0026 Permissions | Redirect URLs**, add the API Gateway URL of the K-CDK-SlackCommandAppSharing stack. For example:\n        ```\n        https://\u003capi-gateway-id\u003e.execute-api.ap-southeast-2.amazonaws.com/v1/oauth2\n        ```\n    2. Go to **Settings | Manage Distribution | Activate Public Distribution**\n\n### Steps to Install\n\n#### From Slack App Owner\n\n1. Ask the potential user to provide\n    1. `team_id` (aka. Workspace ID)\n    2. `channel_id`\n\n2. Add to [settings_dev.json](settings_dev.json)\n\n3. Deploy the stacks again.\n\n4. Provide the users the **Sharable URL**. You can obtain this by going to **Settings | Manage Distribution | Sharable URL**.\n\n#### From Slack App User\n\n1. Log in to your Slack Workspace _**in a browser**_.\n\n2. Open the **Sharable URL** in the browser. You will be asked to allow the access \"Add shortcuts and/or slash commands that people can use\".\n   1. Select the channel where the Slack App will be installed.\n   2. Click **Allow**.\n\n   ![SlackAppInstall-01](docs/SlackAppInstall-01.png)\n\n3. On success of authenticating your request with the `app_id`, `team_id` and `channel_id`, you should see\n   \u003e Installation request accepted and registration completed.\n   ![SlackAppInstall-02](docs/SlackAppInstall-02.png)\n\n4. Then in the channel you specified in previous step, you should see\n   \u003e added an integration to this channel: (you-app-name)\n\n   You should be able to see this Slack App under **App** as well.\n\n5. You can try\n   ```\n   /testcdk\n   ```\n\nNote that your Slack Workspace may have additional restriction and require Approval from Admin on installing new Slack App. In this case, you need to talk to your Slack Workspace Admin.\n\n---\n\n## Local Development, Build, Test and Deploy\n### Run unit tests and flake8 lint tests\n\n```bash\npython lambda/ImmediateResponse.test.py\npython lambda/AsyncWorker.test.py\npython lambda/SyncWorker.test.py\npython lambda/OAuth.test.py\n\nflake8 --ignore E501,F541,W605 lambda/ slack_app_constructs_cdk/ scripts/*.py\n```\n\n### Test Lambda function locally with AWS SAM CLI and AWS CDK\n\nPrerequisites:\n1. Install [sam-beta-cdk](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-cdk-getting-started.html)\n2. Start Docker\n\n```bash\n# Prepare the deployment artifacts\nsam-beta-cdk build\n\n# Invoke the function STACK_NAME/FUNCTION_IDENTIFIER\nsam-beta-cdk local invoke K-CDK-SlackCommandApp/K-CDK-SlackCommandApp-ImmediateResponse -e tests/event_async.json\nsam-beta-cdk local invoke K-CDK-SlackCommandApp/K-CDK-SlackCommandApp-ImmediateResponse -e tests/event_sync.json\n\n# To start the API declared in the AWS CDK application\nsam-beta-cdk local start-api\n\n# To start a local endpoint that emulates AWS Lambda\nsam-beta-cdk local start-lambda\n```\n\nFor details of sam-beta-cdk, see https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-cdk-testing.html.\n\n---\n\n## Notes on known sam-beta-cdk issues\n\n1. KeyError when running `sam-beta-cdk ...`\n   ```bash\n   KeyError: '/home/.../lambda'\n   Failed to execute script __main__\n   ```\n   - Known bug: https://github.com/aws/aws-sam-cli/issues/2849\n   - Workaround:\n       - Add `\"@aws-cdk/core:newStyleStackSynthesis\": false` into cdk.json\n       - Add an empty requirements.txt to [lambda/](lambda/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyhau%2Fslack-command-app-cdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyhau%2Fslack-command-app-cdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyhau%2Fslack-command-app-cdk/lists"}