Skip to content

Commit df43450

Browse files
authored
Added basic lazy lambda exmaple setup and deploy instructions. Fixed vendor module import issues. (#442)
1 parent ac8b698 commit df43450

File tree

4 files changed

+75
-5
lines changed

4 files changed

+75
-5
lines changed

examples/aws_lambda/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
vendor/
2-
.env
1+
slack-bolt/
2+
.env

examples/aws_lambda/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Lazy Lambda Listener Example Bolt App
2+
3+
1. You need an AWS account and your AWS credentials set up on your machine.
4+
2. Make sure you have an AWS IAM Role defined with the needed permissions for
5+
your Lambda function powering your Slack app:
6+
- Head to the AWS IAM section of AWS Console
7+
- Click Roles from the menu
8+
- Click the Create Role button
9+
- Under "Select type of trusted entity", choose "AWS service"
10+
- Under "Choose a use case", select "Common use cases: Lambda"
11+
- Click "Next: Permissions"
12+
- Under "Attach permission policies", enter "lambda" in the Filter input
13+
- Check the "AWSLambdaBasicExecutionRole" and "AWSLambdaExecute" policies
14+
- Click "Next: tags"
15+
- Click "Next: review"
16+
- Enter `bolt_python_lambda_invocation` as the Role name. You can change this
17+
if you want, but then make sure to update the role name in
18+
`lazy_aws_lambda_config.yaml`
19+
- Optionally enter a description for the role, such as "Bolt Python basic
20+
role"
21+
3. Ensure you have created an app on api.slack.com/apps as per the [Getting
22+
Started Guide](https://slack.dev/bolt-python/tutorial/getting-started).
23+
Ensure you have installed it to a workspace.
24+
4. Ensure you have exported your Slack Bot Token and Slack Signing Secret for your
25+
apps as the environment variables `SLACK_BOT_TOKEN` and
26+
`SLACK_SIGNING_SECRET`, respectively, as per the [Getting
27+
Started Guide](https://slack.dev/bolt-python/tutorial/getting-started).
28+
5. You may want to create a dedicated virtual environment for this example app, as
29+
per the "Setting up your project" section of the [Getting
30+
Started Guide](https://slack.dev/bolt-python/tutorial/getting-started).
31+
6. Let's deploy the Lambda! Run `./deploy_lazy.sh`. By default it deploys to the
32+
us-east-1 region in AWS - you can change this at the top of `lazy_aws_lambda_config.yaml` if you wish.
33+
7. Load up AWS Lambda inside the AWS Console - make sure you are in the correct
34+
region that you deployed your app to. You should see a `bolt_py_function`
35+
Lambda there.
36+
8. While your Lambda exists, it is not accessible to the internet, so Slack
37+
cannot send events happening in your Slack workspace to your Lambda. Let's
38+
fix that by adding an AWS API Gateway in front of your Lambda so that your
39+
Lambda can accept HTTP requests:
40+
- Click on your `bolt_py_function` Lambda
41+
- In the Function Overview, on the left side, click "+ Add Trigger"
42+
- Select API Gateway from the trigger list
43+
- Make sure "Create an API" is selected in the dropdown, and choose "HTTP API"
44+
as the API Type
45+
- Under Security, select "Open"
46+
- Click "Add"
47+
9. Congrats! Your Slack app is now accessible to the public. On the left side of
48+
your `bolt_py_function` Function Overview you should see a purple API Gateway
49+
icon. Click it.
50+
10. Click Details to expand the details section.
51+
11. Copy the API Endpoint - this is the URL your Lambda function is accessible
52+
at publicly.
53+
12. We will now inform Slack that this example app can accept Slash Commands.
54+
- Back on api.slack.com/apps, select your app and choose Slash Commands from the left menu.
55+
- Click Create New Command
56+
- By default, the `lazy_aws_lambda.py` function has logic for a
57+
`/hello-bolt-python-lambda` command. Enter `/hello-bolt-python-lambda` as
58+
the Command.
59+
- Under Request URL, paste in the previously-copied API Endpoint from API
60+
Gateway.
61+
- Click Save
62+
13. Test it out! Back in your Slack workspace, try typing
63+
`/hello-bolt-python-lambda hello`.
64+
14. If you have issues, here are some debugging options:
65+
- Check the Monitor tab under your Lambda. Did the Lambda get invoked? Did it
66+
respond with an error? Investigate the graphs to see how your Lambda is
67+
behaving.
68+
- From this same Monitor tab, you can also click "View Logs in CloudWatch" to
69+
see the execution logs for your Lambda. This can be helpful to see what
70+
errors are being raised.

examples/aws_lambda/deploy_lazy.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
2-
rm -rf vendor && mkdir -p vendor/slack_bolt && cp -pr ../../slack_bolt/* vendor/slack_bolt/
2+
rm -rf slack_bolt && mkdir slack_bolt && cp -pr ../../slack_bolt/* slack_bolt/
33
pip install python-lambda -U
44
lambda deploy \
55
--config-file lazy_aws_lambda_config.yaml \
6-
--requirements requirements.txt
6+
--requirements requirements.txt

examples/aws_lambda/lazy_aws_lambda_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ environment_variables:
3838

3939
# Build options
4040
build:
41-
source_directories: vendor # a comma delimited list of directories in your project root that contains source to package.
41+
source_directories: slack_bolt # a comma delimited list of directories in your project root that contains source to package.

0 commit comments

Comments
 (0)