[英]How do I start an EC2 instance using the latest version of the NodeJS AWS SDK?
I am trying to make a simple Discord bot in Discord.JS that turns on an EC2 instance when a command is run.我正在尝试在 Discord.JS 中创建一个简单的 Discord 机器人,该机器人在运行命令时会打开 EC2 实例。 I've gotten most of it to work, but I cannot seem to get past this one part of code.
我已经完成了大部分工作,但我似乎无法超越这部分代码。 I've noticed that it keeps on telling me that I don't have permissions to start an EC2 instance even though it's running on the root user (bad security I know, I'm planning to move it soon) which is written in the code (taken from the docs), but I'm not sure what could be causing me to not have the permissions.
我注意到它一直告诉我我没有权限启动 EC2 实例,即使它在 root 用户上运行(我知道安全性很差,我打算尽快移动它),它写在代码(取自文档),但我不确定是什么导致我没有权限。
Here is the code I am working with这是我正在使用的代码
if (message.content === ">start") {
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create EC2 service object
var ec2 = new AWS.EC2({apiVersion: '2016-11-15'});
var params = {
InstanceIds: "i-0c5de602d730d1d24",
DryRun: true
};
// Call EC2 to start the selected instances
ec2.startInstances(params, function(err, data) {
if (err && err.code === 'DryRunOperation') {
params.DryRun = false;
ec2.startInstances(params, function(err, data) {
if (err) {
console.log("Error", err);
} else if (data) {
console.log("Success", data.StartingInstances);
}
});
} else {
console.log("You don't have permission to start instances.");
}
});
}
});
} catch (error) {
console.error(error);
}
Thanks for reading and I hope that I can learn from this so that I don't have similar issues in the future!感谢您的阅读,我希望我能从中吸取教训,这样我以后就不会遇到类似的问题了!
Try尝试
InstanceIds: ["i-0c5de602d730d1d24"],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.