|
| 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. |
0 commit comments