Wafi
Wafi

Reputation: 71

Creating Lambda Function to Trigger Codebuild Project using Nodejs

I'm creating a lambda function using nodejs to trigger codebuild project, here what I did so far but still with no luck.

exports.handler = async (event) => {
    const AWS = require("aws-sdk");
    const codebuild = new AWS.CodeBuild();
    const build = {
       projectName: "MyCodeBuildProjectName"
    };
    codebuild.startBuild(build,function(err, data){
        if (err) {
            console.log("Inside Error!");
            console.log(err, err.stack);
        }
        else {
            console.log("Outside Error!");
            console.log(data);
        }
    });
};

When I'm running a test on this function I'm not getting neither of the "Inside Erro!" nor "Outside Error!" console log.

Am I missing something?

Upvotes: 4

Views: 4245

Answers (2)

Suresh
Suresh

Reputation: 835

I was able to solve it using await as given below.

const data = await codebuild.startBuild(params).promise();

Upvotes: 2

Wafi
Wafi

Reputation: 71

Solved by taking "async" out from the first line.

Upvotes: 3

Related Questions