AWS SDK运行实例和IAM角色

当我添加了AWS IAM角色"AdministratorAccess“时,下面的代码就可以工作了--但它有风险,而且有点夸张……但是,当我在控制台中查看所有可能的角色时,我如何知道并只找到必要的角色...It是非常令人困惑和难以了解的?

try {

            // Load the AWS SDK for Node.js
            var AWS = require('aws-sdk');

            // Set the region
            AWS.config.update({region: 'us-east-2'});

            var instanceParams = {
                ImageId: 'ami-xxxxxxxxxxxx',
                InstanceType: 't2.micro',
                KeyName: 'xxxxxxxxxx',
                SecurityGroups: ['xxxxxxxxxxxxxxx'],
                MinCount: 1,
                MaxCount: 1
            };

            // Create a promise on an EC2 service object
            var instancePromise = new AWS.EC2({apiVersion: '2016-11-15'}).runInstances(instanceParams).promise();

            // Handle promise's fulfilled/rejected states
            instancePromise.then(
                function (data) {
                    console.log(data);
                    var instanceId = data.Instances[0].InstanceId;
                    console.log("Created instance", instanceId);
                    // Add tags to the instance
                    var tagParams = {
                        Resources: [instanceId], Tags: [
                            {
                                Key: 'Name',
                                Value: 'SDK Sample'
                            }
                        ]
                    };

                    // Create a promise on an EC2 service object
                    var tagPromise = new AWS.EC2({apiVersion: '2016-11-15'}).createTags(tagParams).promise();
                    // Handle promise's fulfilled/rejected states
                    tagPromise.then(
                        function (data) {
                            console.log("Instance tagged");
                        }).catch(
                        function (err) {
                            console.error(err, err.stack);
                        });
                }).catch(
                function (err) {
                    console.error(err, err.stack);
                });
        }
        catch(e){
            wl.info('Error: ' + e);
        }

转载请注明出处:http://www.insurance-fj.com/article/20230526/1956943.html