Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

840
Views
getSecretValue callback is not working in AWS Lambda

I'm trying to retrieve Secret Value from AWS Secret Manager using aws-sdk for Javascript, I'm using the code snippet provided by Secret Manager, I have included this code in Lambda function, but I can't see any console logs defined inside the callback function. Here's the lambda code:

exports.handler = async (event, context) => {
    const AWS = require('aws-sdk');
    const client = new AWS.SecretsManager({ region: "eu-west-2" });
    let secret;
    let decodedBinarySecret;

    console.log('STARTED');

    client.getSecretValue({ SecretId: "MagellanDev" }, function (err, data) {
        if (err) {
            console.log('Got Error: ', err.code);
            throw err;
        }
        else {
            if ('SecretString' in data) {
                secret = data.SecretString;
            } else {
                let buff = new Buffer(data.SecretBinary, 'base64');
                decodedBinarySecret = buff.toString('ascii');
            }
        }

        console.log("SECRET: ", secret);
        console.log("DECODEBINARYSECRET: ", decodedBinarySecret)
    });

    console.log('ended');

};

Output:

Started

ended

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The problem is that you have specified the function handler as async. If you want to use callbacks, then use the older style function handler:

exports.handler = function(event, context, callback) {
  // ...
}

The code has exited before the getSecretValue() function has completed and had a chance to make the callback. And because your function is async and you did not return a Promise, the Lambda runtime is not waiting.

I would move away from the older callback-style code and move to the newer async/await-style code, for example:

const AWS = require('aws-sdk');
const client = new AWS.SecretsManager({region: 'us-east-1'});

exports.handler = async (event, context) => {
    const params = {SecretId: secretName};
    return client.getSecretValue(params).promise();
};
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!