如何使用AWS lambda中的帐户Id获取帐户名称



我正在使用Node.js 12.x开发AWS Lambda函数。我有从event.requestContext中提取的accountId。有没有一种方法可以使用lambda函数中的accountId来获取帐户的名称?

您实际上可以使用api调用ListAccountAliases列出帐户别名。文档中的相应示例

// 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);
}
});

最新更新