examples/aws_lambda/README.md
This directory contains two example apps. Both respond to the Slash Command
/hello-bolt-python-lambda and both respond to app at-mentions.
The "Lazy Lambda Listener" example is the simpler application and it leverages AWS Lambda and AWS Lambda Function URL to execute the Bolt app logic in Lambda and expose the application HTTP routes to the internet via Lambda URL. The "OAuth Lambda Listener" example additionally includes OAuth flow handling routes and uses AWS S3 to store workspace installation credentials and OAuth flow state variables, enabling your app to be installed by anyone.
Instructions on how to set up and deploy each example are provided below.
bolt_python_lambda_invocation as the Role name. You can change this
if you want, but then make sure to update the role name in
lazy_aws_lambda_config.yamlSLACK_BOT_TOKEN and
SLACK_SIGNING_SECRET, respectively, as per the
Building an App guide../deploy_lazy.sh. By default it deploys to the
us-east-1 region in AWS - you can change this at the top of lazy_aws_lambda_config.yaml if you wish.bolt_py_function
Lambda there.bolt_py_function Lambdabolt_py_function Function Overview you should see your Lambda Function URL.lazy_aws_lambda.py function has logic for a
/hello-bolt-python-lambda command. Enter /hello-bolt-python-lambda as
the Command./hello-bolt-python-lambda hello.You need an AWS account and your AWS credentials set up on your machine.
Once you’ve done that you should have access to AWS Console, which is what we’ll use for the rest of this tutorial.
arn:aws:s3:::slack-installations-s3.Now let's create a policy that will allow the holder of the policy to take actions in your S3 buckets.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:Get*",
"s3:Put*",
"s3:Delete*",
"s3-object-lambda:*"
],
"Resource": [
"<your-first-bucket-arn>/*", // don't forget the `/*`
"<your-second-bucket-arn>/*"
]
}
]
}
/*Let’s create a user role that will use the custom policy we created as well as other policies to let us execute our lambda, write output logs to CloudWatch.
AWSLambdaExecuteAWSLambdaBasicExecutionRoleAWSLambdaRole<NameOfS3PolicyYouCreatedEarlier>bolt_python_s3_storage as your role name. To use a different name, make sure to update the role name in aws_lambda_oauth_config.yamlEnsure you have created an app on api.slack.com/apps as per the Building an App guide. You do not need to ensure you have installed it to a workspace, as the OAuth flow will provide your app the ability to be installed by anyone.
SLACK_SIGNING_SECRET= # Signing Secret from Basic Information page
SLACK_CLIENT_ID= # Client ID from Basic Information page
SLACK_CLIENT_SECRET # Client Secret from Basic Information page
SLACK_SCOPES= "app_mentions:read,chat:write"
SLACK_INSTALLATION_S3_BUCKET_NAME: # The name of installations bucket
SLACK_STATE_S3_BUCKET_NAME: # The name of the state store bucket
export
./deploy_oauth.sh. By default it deploys to the us-east-1 region in AWS - you can customize this in aws_lambda_oauth_config.yaml.bolt_py_oauth_function Lambda there.Your Lambda exists, but it is not accessible to the internet, so Slack cannot yet send events happening in your Slack workspace to your Lambda. Let's fix that by adding an AWS Lambda Function URL to your Lambda so that your Lambda can accept HTTP requests
bolt_py_oauth_function LambdaPhew, congrats! Your Slack app is now accessible to the public. On the right side of your bolt_py_oauth_function Function Overview you should see a your Lambda Function URL.
aws_lambda_oauth.py function has logic for a /hello-bolt-python-lambda command. Enter /hello-bolt-python-lambda as the Command.You can now install the app to any workspace!
/hello-bolt-python-lambda hello.