Error running in Lambda: No module named 'slack_bolt'

See original GitHub issue

I 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))

  1. Downloaded the Bolt Python example for AWS Lambda from here
  2. Created a new Lambda function with Python 3.9
  3. Uploaded lazy_aws_lambda.py and requirements.txt (without modifications)
  4. Set the target as lazy_aws_lambda.handler
  5. Deployed and tested the Lambda function with a dummy test event
  6. 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:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
filmajcommented, Dec 2, 2021

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.py and requirements.txt files, 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_bolt directory 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’s deploy_lazy.sh deployment script, which, if you take at the first line in this script, you’ll see it copies the slack_bolt directory 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.md of 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.

0reactions
spridercommented, May 1, 2022

requirements.txt

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/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve "Unable to import module" errors from Python ...
I receive an "Unable to import module" error when I try to run my AWS Lambda code in Python. How do I resolve...
Read more >
Deploying to AWS Lambda - Slack | Bolt for JavaScript
This guide walks you through preparing and deploying a Slack app using Bolt for JavaScript, the Serverless Framework, and AWS Lambda. When you're...
Read more >
AWS error from Python: No module named lambda_function
Error was due to file name of the lambda function. While creating the lambda function it will ask for Lambda function handler.
Read more >
SlackApi Bolt-python App With AWS Lambda And AWS CDK
Not sure about the flow, but the lambda function requires permission to invoke itself, otherwise we will get following error.
Read more >
Unable to import module lambda function No ... - Edureka
But I am getting this below error at the time of running. Unable to import module 'lambda_function': No module named lambda_function.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found