Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 228
Wafi Avatar asked Oct 26 '25 10:10

Wafi


2 Answers

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

like image 69
Wafi Avatar answered Oct 29 '25 00:10

Wafi


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

const data = await codebuild.startBuild(params).promise();
like image 45
Suresh Avatar answered Oct 29 '25 00:10

Suresh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!