Simple template for setting up a scheduled lambda function that triggers a discord webhook to send a message.
Meant to be a starting point for someone to set up their own webhook triggered on a schedule.
Use this repository as a starting place to automate discord messages. This package will help you set up the necessary AWS Infratructure to have a lambda triggered on a schedule that will call your code.
- Install the AWS CDK Toolkit
- You will also need Docker installed and running locally
- Make sure to follow the instructions to get credentials set up
- Have your choice of npm/yarn installed
- Create a webhook to call in Discord by following these instructions.
- Fork this repository and pull locally
- To change the schedule edit the
cronRuleinbin/src.ts - To modify the discord message edit the
handlermethod insrc/lambdaHandler.ts
- To change the schedule edit the
- Create a
.envfile (using.env.exampleas an example). Use the URL from the webhook's "Copy Webhook URL" button on discord forDISCORD_WEBHOOK_URL. - Run
npm run buildto ensure everything works - Run
npm run test-localto ensure the webhook is sending messages to the discord channel- Use this whenever you want to test your lambda code without deploying. Make sure to build first
- Run
cdk deployto deploy!- You'll want to re-run this any time you want to deploy new code to the lambda, or you set a new schedule
- If you encounter a timeout issue, try modifying the timeout in
lib/typescript-lambda-stack.ts
This package utilizies AWS CDK, a tool which is used to set up AWS Infrastucture using code.
- Set up an AWS Lambda defined in TypeScript.
- Set up an AWS EventBridge rule that is triggered on a schedule. The schedule is defined in cron but other schedules can be used as well. The target of this rule is the Lambda function.
npm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpm run testperform the jest unit testscdk deploydeploy this stack to your default AWS account/regioncdk diffcompare deployed stack with current statecdk synthemits the synthesized CloudFormation template
