0

I'm trying to run a for loop in my AWS Lambda that loops through an array. The array has a length of 11, but the for-loop only runs for 3 iterations before stopping (I can't find an error in the try/catch log).

This code is part of a Github bot, and basically moves files from one place in a repo to another location.

This code worked fine on Heroku, but it does not work when I transferred it over to AWS lambda (using the serverless framework).

const workFlow = async (context) => {
  console.log("Getting files")
  let files = await context.octokit.repos.getContent({
    owner: context.payload.repository.owner.login,
    repo: context.payload.repository.name,
    path: ".bit/workflows"
  });

  console.log(files)
  console.log(files.data.length);
  for (i = 0; i < files.data.length; i++) {
    let body = await data.getFileContent(context, `.bit/workflows/${files.data[i].name}`)
    body = body[0].data.content

    try {
      console.log("Getting file " + i)
      console.log(files.data[i])
      await context.octokit.repos.createOrUpdateFileContents({
        owner: context.payload.repository.owner.login,
        repo: context.payload.repository.name,
        path: `.github/workflows/${files.data[i].name}`,
        message: "Start workflows",
        content: body,
        committer: {
          name: `NAME`,
          email: "EMAIL",
        },
        author: {
          name: `NAME`,
          email: "EMAIL",
        },
      })
      console.log("Got workfow files");
    } catch (e) {
      console.log("Error in getting workflow files")
      console.log(e)
    }
  }
}
Ganning Xu
  • 263
  • 4
  • 13

0 Answers0