Deployment instructions for AWS Lambda¶
Prerequisites¶
- You will need a Github account
- You will need an AWS account.
Creating the lambda function¶
- Create a function on AWS Lambda and author from scratch. Under
choose or create an execution role
, choosecreate a execution role from a policy template
withAmazon S3 read only permissions
and name your role. Set your runtime toPython 3.7
and choose a name for your function. pressCreate function
- Choose
upload a .zip file
for yourCode entry type
- Set your handler to
labelbot.bot.lambda_handler
- Add an API Gateway as a trigger. Create a new API and set it to Open. Press add, and then save. This will give you a webhook url to add to your github app.
Create the github app¶
- Under
Settings>Developer settings>Github Apps
, press theNew Github App
button. - Give your app a name and enter a homepage url, for example your fork of labelbot.
- Under
Webhook url
enter your API gateway url. - Under
Webhook secret (optional)
, enter a secret token, as described in Githubs documentation. - Under
Permissions
, addread-only
access toRepository contents
and addRead and write
access toIssues
- Under
Subscribe to events
, subscribe to theLabel
event. - Under
Where can this GitHub App be installed?
, setOnly on this account
- Press the
Create Github App
- Generate a private key and save it to an S3 bucket that is not publicly accessible.
Set enviroment variables to hold private data in your Lambda function.¶
APP_ID
: Shall be set to the App ID of your github app.BUCKET_NAME
: The name of your S3 bucket.BUCKET_KEY
: the unique identifier of your key file stored in S3.SECRET_KEY
: Shall be the same value as your secret token, that was set to secure the webhook.
After all enviroment variables have been added, save the changes.
Give your lambda function read access to your s3 bucket.¶
In S3>:your bucket:>Permissions>Bucket Policy
give your lambda role the rights to read from your bucket.
Creating and uploading a deployment package¶
To create a deployment package it is required to build in a linux enviroment with python 3.7 and pip installed, as Lambda runs in a linux enviroment.
Run the package.sh
script from the repository root, which packages the
application iin a zip file, that can be uploaded to AWS to deploy the
application. It will create a file
called labelbot.zip
which should be uploaded to your AWS lambda
function. Save after uploading the file.
You have now created and deployed your own github app with AWS Lambda¶
You can now install it on your own account and use it to label issues by pressing the Install App
button.