Deploying My Probot App to a Serverless Lambda
Tags: github, aws, tutorial, devops
Published: 2022-02-15 23:06:33


I built a Probot application, but I’m currently using smee.io to test webhooks, and I’m running the application locally. Now that my app is production-ready, I want to deploy it to a lambda. There are multiple platforms you can use to deploy your application to a lambda, but I prefer AWS because I’m most familiar with it.

_AWS Lambda is an event-driven, serverless computing platform provided by Amazon as a part of the Amazon Web Services. AWS Lamba additionally manages the computing resources required for the code and adjusts those resources in conjunction with incoming events._

Below are the steps I took to deploy my Probot app to a Lambda. 

* Login or create an account on [AWS Console](https://aws.amazon.com/console/)
* Run `npm install @probot/adapter-aws-lambda-serverless`.  This npm package is an adapter to run a Probot application function in AWS Lambda using the Serverless Framework.
* Run `npm install serverless -g` to interact with the Serverless Framework CLI
* Create a handler.js file at the root of your project and add the lines below to the file:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/54bmitrsdejesb9jhatl.png)

* In your parameter store, create and store values for your app id, private key, and webhook secret

        
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5dn6zh3ovqmehgmi6vje.png)

* Create a serverless.yml file at the root of your project and add the following lines. Change the values for the service name and runtime to fit your use case. _Please note that the environment variables for the webhook secret, app id, and private key are referenced here_: 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/idaaq88p6sn96q7juba1.png)

* Create an IAM user. You will need to grant the right permissions to this user. Additionally, for the credential type, choose **Access key - Programmatic access**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y551r8piaug21l25hbmc.png)

* Once you create the user, AWS will generate an access key ID and a secret access key. Store those credentials in a place you can remember. 
* Configure your AWS profile with the credentials you received by running this command in your terminal. This [guide](https://www.serverless.com/framework/docs/providers/aws/guide/credentials/) provides alternate methods to use AWS credentials. 

        serverless config credentials \
          --provider aws \
          --key YourAWSKeyIdHere \
          --secret YourAWSSecretAccessKeyHere



* Run `sls deploy`. This command deploys your entire service via CloudFormation. It will return a POST URL endpoint similar to this one:

        https://[random alphanumeric string].execute-api.us-east-1.amazonaws.com/dev/api/github/webhook

* Check that you successfully deployed your lambda


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zqmnkfriaikq8dqa6vvx.png)

* Update your webhook URL and your homepage URL to the lambda’s endpoint URL
        
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc8h6bvycokkos8pt7ba.png)


After following these steps, your app should work without running it locally and you can read the logs for your application in AWS CloudWatch.

Want to learn more about automating with GitHub? Follow GitHub and me (@blackgirlbytes) on DEV for more content. I'll try to post daily!