Repository navigation
Unable to run the chalice example locally #162
Description
Activity
I searched for past 48 hours for a complete guide how to use Chalice and Slack bolt together but I failed to find one.
@AymanEG Hi, thanks a lot for trying Bolt for python out!
Just in case, I verified the steps to deploy a Chalice app but I was not able to find any issues with it. Checking the following steps may help. If you have issues specific to AWS services and/or your account settings, consult AWS communities or contact AWS support team.
Example App
This is almost the same with
simple_app.pybut I've simplified some parts.requirements.txt
slack_bolt==1.0.1app.py
The file name must be
app.pyhere. Also, as mentioned in the code, the name ofChaliceinstance in the source file must beapptoo.import logging from chalice import Chalice, Response from slack_bolt import App from slack_bolt.adapter.aws_lambda.chalice_handler import ChaliceSlackRequestHandler ChaliceSlackRequestHandler.clear_all_log_handlers() logging.basicConfig(format="%(asctime)s %(message)s", level=logging.DEBUG) # process_before_response must be True when running on FaaS bolt_app = App(process_before_response=True) @bolt_app.event("app_mention") def handle_app_mentions(body, say, logger): logger.info(body) say("What's up? I'm a Chalice app :wave:") # Don't change this variable name "app" app = Chalice(app_name="bolt-python-chalice") slack_handler = ChaliceSlackRequestHandler(app=bolt_app, chalice=app) @app.route( "/slack/events", methods=["POST"], content_types=["application/x-www-form-urlencoded", "application/json"], ) def events() -> Response: return slack_handler.handle(app.current_request)
.chalice/config.json
{ "version": "2.0", "app_name": "bolt-python-chalice", "stages": { "dev": { "api_gateway_stage": "api", "environment_variables": { "SLACK_BOT_TOKEN": "xoxb-your-own-token", "SLACK_SIGNING_SECRET": "your-own-secret" }, "manage_iam_role": false, "iam_role_arn": "arn:aws:iam::111:role/your-own-role" } } }Steps to deploy the app
Some of the steps may be different with Windows OS but doing this way should work for you:
# create a new virtual env python -m venv .venv source .venv/bin/activate # install dependencies pip install -U pip chalice click boto3 pip install -r requirements.txt # Add Chalice config file mkdir .chalice touch .chalice/config.json # and modify with your values # Run your Chalice app chalice local --port 3000 # In another terminal, start ngrok process # --subdomain is available only for ngrok paid accounts ngrok http 3000 --subdomain your-subdomain # https://api.slack.com/apps # Go to "Event Subscriptions" page # Set the URL https://{your-subdomain}.ngrok.io/slack/events to Request URL # Add app_mention bot event subscription # Verify the behaviors # Deploy the app to AWS chalice deploy # https://api.slack.com/apps # Switch the Request URLs to https://{random}.execute-api.{region}.amazonaws.com/api/slack/events
Reacted by Ayman Magedy and Takumi Ando- addedquestionFurther information is requestedFurther information is requested
on Nov 28, 2020 Hello @seratch
Thanks for the fast response. I followed the steps and it worked great so far. I just skipped
manage_iam_rolepart from config file so Chalice will automatically set it.When I deployed ,it worked fine too ,but when I try to add custom domain I get this error:
Deployed values for resource does not exist: api_gateway_custom_domainHere is a screen shot of the deployment:

My current config file looks like this:
{ "version": "2.0", "app_name": "bolt-python-chalice", "api_gateway_endpoint_type": "REGIONAL", "stages": { "dev": { "api_gateway_custom_domain": { "domain_name": "slack.adaw.at", "certificate_arn": "arn:aws:acm:me-south-1:token" }, "api_gateway_stage": "api", "environment_variables": { "SLACK_BOT_TOKEN": "xoxb-token", "SLACK_SIGNING_SECRET": "token" } } } }I followed up on this article to configure custom domain
Awesome! Thanks a lot for sharing your knowledge here. It should be helpful for others too!
The reason why I went with my own IAM role is that lazy listener function feature invokes async AWS lambda functions from a lambda function. If you use this functionality, you need to add
lambda:InvokeFunctionpermission to your app.Let me close this issue now.
Any idea how to fix the
api_gateway_custom_domainerror ?Nevermind , I guess it is related to AWS settings. I will figure it out.
The reason why I went with my own IAM role is that lazy listener function feature invokes async AWS lambda functions from a lambda function. If you use this functionality, you need to add
lambda:InvokeFunctionpermission to your app.This should be noted in the docs as you cannot test with
chalice localwhen using lazy listeners. Chalice logs a 500 error as boto throws a botocore.errorfactory.ResourceNotFoundException... or worse, it invokes whatever is atfunction:api_handler.@jlujan-invitae Thanks for the feedback! I've created a new issue #267 for it 👍
Hello there,
I am not able to follow the docs to deploy chalice from example folder locally.
To follow local deploy at Windows 10
1- I have ngrok running on port 3000
2- I created new conda env with python 3.8.5
3- Installed chalice & slack bolt
4- Copied simple_app.py and chalice config.json
from https://github.com/slackapi/bolt-python/tree/main/examples/aws_chalice
Now it run successfully and the challenge is accepted in the slack app directory using ngrok link.
But when I tag the app in slack, I got 404 error in ngrok and no response is sen t back to Slack.