Search code examples
.netaws-lambdawebhooks

How do I make a webhook with an AWS Lambda function?


I am trying to create a webhook using the .NET framework and AWS Lambda functions. The goal of the webhook is to send a message in a Discord server when an issue on a shared GitHub repository is opened. I have the latest versions of Amazon tools and .NET installed, as well as an IAM user whose credentials were used for the AWS configuration.

Progress already made:

  • dotnet new -n
  • code has been edited to call an env variable from the Lambda function project is in /home/username/Dev

I want to publish it and add a trigger somehow.


Solution

  • You will want to run 'dotnet lambda deploy-function (function name)' first. This publishes the function so you can see it in AWS. Make sure you are in /home/username/Dev/function-name/src/function-name.

    In the AWS Lambda dashboard, click on functions, then your function. Under the configuration tab, set an environment variable to the Discord URL. On the same page, click 'Add Trigger', then 'API gateway'. In the actions drop down, click 'Create Method', select 'post'. In the Lambda function box, type the name of your function (it should autocomplete). Then go to the actions drop down again and deploy to a stage. Copy your API endpoint, you'll use this in the GitHub webhooks section.

    Now that you have an API endpoint to post to, go to your repo in GitHub, and under the 'Settings' tab go to webhooks. Paste your API endpoint and select any relevant settings. In your case, check the Issues box to trigger the API when an issue is raised.