gr2m / helpdesk

Answering all your GitHub API/automation questions live on Twitch
https://twitch.tv/gregorcodes
Creative Commons Zero v1.0 Universal
22 stars 11 forks source link

Help with Github Probot running on AWS Lambda #39

Closed ganning127 closed 3 years ago

ganning127 commented 3 years ago

I'm currently trying to deploy a Github bot to AWS Lambda. However, when testing the bot, there is a function in my code that causes an error.

The yamlFile() function gets the content of a file from a user's Github repo, and returns it. However, when tested, the function will get to the first trying to get yaml log, but never reach the second we got the yaml log.

There is also no error that is logged out as a result of the try/catch.

Since the AWS Lambda functions receives webhooks from AWS, this function is called multiple times (from multiple webhooks). This function runs correctly for the first call, but gives us the above issue on the second call.

Prior to deploying on AWS Lambda, this exact code was running on Heroku, and worked fine there, without any issue.

AWS Config settings:

const yamlFile = async (context) => {
  try {
    console.log("trying to get yaml")

    var yamlfile = await context.octokit.repos.getContent({
      owner: context.payload.repository.owner.login,
      repo: context.payload.repository.name,
      path: ".bit/config.yml",
    });

    console.log("we got the yaml")
    // console.log(yamlfile)
  } catch (e) {
    console.log("Error with getting content of yaml");
    console.log(e)
    return null
  }
  console.log("got yaml, but no content yet");
  yamlfile = Buffer.from(yamlfile.data.content, 'base64').toString()
  // console.log(yamlfile)
  try {
    let fileContents = yamlfile
    configyml = yaml.load(fileContents);
  } catch (e) {
    const issueBody = context.issue({
      title: "[ERROR] Please read",
      body: `There was an issue parsing the config file of this course. Please contact your counselor and send them the below error.\n${e}`,
    });

    context.octokit.issues.create(issueBody)
    console.log("ERROR: " + e);
    return null
  }
  console.log("returining configyml")
  return configyml;
}
gr2m commented 3 years ago

That's a very specific question, better asked on Stackoverflow, which looks you already did. It looks most likely like an AWS Lambda issue, I cannot help with that, sorry