简体   繁体   English

aws lambda node.js 未启动 ec2 实例

[英]aws lambda node js not starting ec2 instance

I am writing a ec2 scheduler logic to start and stop ec2 instances.我正在编写一个 ec2 调度程序逻辑来启动和停止 ec2 实例。 The lambda works for stopping instances. lambda 用于停止实例。 However the start function is not initiating ec2 start.然而,启动 function 并未启动 ec2 启动。 The logic is to filter based on tags and status of ec2 and start or stop based on current status.逻辑是根据 ec2 的标签和状态进行过滤,并根据当前状态启动或停止。

Below is the code snippet to start EC2 instances.下面是启动 EC2 实例的代码片段。 But this isn't starting the instances.但这不是启动实例。 The filtering happens correctly and pushes the instances to "stopParams" object.过滤正确发生并将实例推送到“stopParams”object。

The same code works if I change the logic to ec2.stopInsatnces by filtering the running state instances.如果我通过过滤正在运行的 state 实例将逻辑更改为 ec2.stopInsatnces,则相同的代码会起作用。 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);
                }); 

Finally got this working.终于让这个工作了。 There were no issues with the nodejs lambda code. nodejs lambda 代码没有问题。 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.要使用 API 调用 lambda 角色来启动实例,lambda 应该有权访问用于加密卷的 kms 密钥。 After adding the lambda role arn in the principal section of kms key policy permission the lambda was able to start instances.在 kms 密钥策略权限的主要部分添加 lambda 角色 arn 后,lambda 能够启动实例。 But key permission is not necessary for stopping the instance.但是停止实例不需要密钥权限。 Hope this helps希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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