简体   繁体   中英

How to get Account Name using Account Id inside AWS lambda

I'm working on an AWS Lambda function using Node.js 12.x. I have the accountId that I pulled from the event.requestContext . Is there a way how to get the name of the account using the accountId inside the lambda function?

You can actually list the account aliases using api call ListAccountAliases . The corresponding example in from the documentaiton

        // Load the AWS SDK for Node.js
    var AWS = require('aws-sdk');
    // Set the region 
    AWS.config.update({region: 'REGION'});

    // Create the IAM service object
    var iam = new AWS.IAM({apiVersion: '2010-05-08'});

    iam.listAccountAliases({MaxItems: 10}, function(err, data) {
    if (err) {
        console.log("Error", err);
    } else {
        console.log("Success", data);
    }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM