AWS lambda节点JS未启动EC2实例

发布于 2025-01-24 08:02:12 字数 648 浏览 3 评论 0原文

我正在编写EC2调度程序逻辑以开始和停止EC2实例。 Lambda用于停止实例。但是,起始功能不是启动EC2启动。 逻辑是根据EC2的标签和状态过滤,并根据当前状态开始或停止。

以下是启动EC2实例的代码段。但这不是启动实例。 过滤正确进行,并将实例推向“ stopparams”对象。

如果我通过过滤运行状态实例将逻辑更改为eC2。该角色可以开始和停止。

有什么想法为什么它不触发启动?

 if (instances.length > 0){
                var stopParams = { InstanceIds: instances };
                ec2.startInstances(stopParams, function(err,data) {
                    if (err) {
                       console.log(err, err.stack);
                    } else {
                       console.log(data);
                    }
                    context.done(err,data);
                }); 

I am writing a ec2 scheduler logic to start and stop ec2 instances.
The lambda works for stopping instances. However the start function is not initiating ec2 start.
The logic is to filter based on tags and status of ec2 and start or stop based on current status.

Below is the code snippet to start EC2 instances. But this isn't starting the instances.
The filtering happens correctly and pushes the instances to "stopParams" object.

The same code works if I change the logic to ec2.stopInsatnces by filtering the running state instances. The role has permissions to start and stop .

Any ideas why its not triggering start ?

 if (instances.length > 0){
                var stopParams = { InstanceIds: instances };
                ec2.startInstances(stopParams, function(err,data) {
                    if (err) {
                       console.log(err, err.stack);
                    } else {
                       console.log(data);
                    }
                    context.done(err,data);
                }); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难理解 2025-01-31 08:02:12

终于有了这个工作。 Nodejs lambda代码没有问题。即使能够停止实例,但开始实例并未调用开始方法。发现所有卷都是加密的。

要使用API​​调用lambda使用的LAMBDA角色的实例,应允许对用于加密卷的KMS密钥。在在KMS关键政策许可的主要部分中添加了Lambda角色之后,Lambda能够启动实例。但是,关键权限对于停止实例不是必需的。希望这会有所帮助

Finally got this working. There were no issues with the nodejs lambda code. Even though was able to stop instances but start instances were not invoking the start method. Found that all volumes are encrypted.

To start an instance using API call the lambda role used by lambda should have permission to kms key which is used for encrypting the volume. After adding the lambda role arn in the principal section of kms key policy permission the lambda was able to start instances. But key permission is not necessary for stopping the instance. Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文