Error running in Lambda: No module named 'slack_bolt'
See original GitHub issueI was advised by Slack API support to use Bolt to wrap my Python Lambda function so that I could provide the 3s response time required by Slack, whilst continuing processing my updates - in this case, performing IP whitelist updates in multiple AWS accounts.
I had a working version of my script (barring the timeout) so I took a look at the examples and then retrofitted Bolt which was very straightforward, at least initially.
When I came to run it though, I got errors saying:
[ERROR] Runtime.ImportModuleError: Unable to import module 'ip-whitelist': No module named 'slack_bolt'
I then downloaded the Lambda example directly from GitHub and tried that without modifications, and got the exact same error.
I do have slack_bolt installed as you can see below, but I can see the requirements.txt doesn’t include it in the sample. Even when I do add it, it doesn’t work.
The Slack API support asked me to raise a query here instead as this is a Bolt-specific issue.
All I’m trying to achieve is to get a 200 OK back from my Lambda to Slack to prevent a timeout message, whilst my script completes.
My final attempt (as listed below) was to skip the local run and just get the example file to run in Lambda. That too failed with the same issue. A colleague had the same problem, so it doesn’t appear to be a problem with my local Python environment.
Reproducible in:
The slack_bolt version
slack-bolt==1.10.0 slack-sdk==3.12.0
Python runtime version
Python 3.9.9
OS info
ProductName: macOS ProductVersion: 12.0.1 BuildVersion: 21A559 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:01 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T6000
(This is my local install, clearly, and I have the same error running it locally using AWS SAM as I do with the example file directly uploaded to Lambda).
Steps to reproduce:
(Share the commands to run, source code, and project settings (e.g., setup.py))
- Downloaded the Bolt Python example for AWS Lambda from here
- Created a new Lambda function with Python 3.9
- Uploaded lazy_aws_lambda.py and requirements.txt (without modifications)
- Set the target as lazy_aws_lambda.handler
- Deployed and tested the Lambda function with a dummy test event
- Got an error during build (see logs)
Expected result:
The app should compile and run.
Actual result:
Test Event Name
test
Response
{
"errorMessage": "Unable to import module 'lazy_aws_lambda': No module named 'slack_bolt'",
"errorType": "Runtime.ImportModuleError",
"requestId": "b4ae96db-450a-46f2-8c14-e2d6238711b1",
"stackTrace": []
}
Function Logs
START RequestId: b4ae96db-450a-46f2-8c14-e2d6238711b1 Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'lazy_aws_lambda': No module named 'slack_bolt'
Traceback (most recent call last):END RequestId: b4ae96db-450a-46f2-8c14-e2d6238711b1
REPORT RequestId: b4ae96db-450a-46f2-8c14-e2d6238711b1 Duration: 1.39 ms Billed Duration: 2 ms Memory Size: 128 MB Max Memory Used: 37 MB Init Duration: 118.91 ms
Requirements
lazy_aws_lambda.py.txt requirements.txt
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Related StackOverflow Question
Hey @christianbacklund,
Thanks for writing in and sorry you’re experiencing this issue!
Just curious, how did you deploy your Lambda? I see that you mentioned you uploaded the
lazy_aws_lambda.pyandrequirements.txtfiles, but there are more files required than those. I would recommend you follow the AWS Lambda example’s README, in particular the “Lazy Lambda Listener Example Bolt App” section steps, which has the necessary steps to follow to deploy the example successfully.My theory on the issue you are having is that, because you only uploaded the lambda code and the requirements.txt file, you are missing the
slack_boltdirectory containing the Bolt Python dependency code. I think a quick way to fix this for you would be to a) ensure you follow all the README steps in the example dir to set up the example and b) make sure you use the example’sdeploy_lazy.shdeployment script, which, if you take at the first line in this script, you’ll see it copies theslack_boltdirectory from this project directly into your example app project structure.For what it is worth, I just now followed the steps in the
examples/aws_lambda/README.mdof this repo and was able to successfully deploy the example and have it working in my Slack workspace.Let us know how it goes, happy to help debug any further issues.
I changed the following line to pull from my local environment to fix this issue.
rm -rf slack_bolt && mkdir slack_bolt && cp -pr ./.venv/lib/python3.9/site-packages/slack_bolt/* slack_bolt/