Amazon web services Can';t通过lambda在VPC中启动EC2实例

Amazon web services Can';t通过lambda在VPC中启动EC2实例,amazon-web-services,amazon-ec2,aws-lambda,boto3,Amazon Web Services,Amazon Ec2,Aws Lambda,Boto3,我已按照ID启动/停止实例 我没有为stopec2安装或startEC2Instance功能提供专有网络信息 问题:虽然停止实例时工作正常,startEC2Instances功能无法完成其工作 我想知道自从编写教程以来,bot3是否发生了一些变化?我检查了boto3API以确保,但是start\u实例仍然是相同的函数 除了上面链接的文章,我没有修改任何代码 更新: CloudWatch记录了最近一次成功运行startEC2Instances功能的日志(它没有按预期工作,仍然没有启动实例) 更新2

我已按照ID启动/停止实例

我没有为
stopec2安装
startEC2Instance
功能提供专有网络信息

问题:虽然停止实例时工作正常,
startEC2Instances
功能无法完成其工作

我想知道自从编写教程以来,
bot3
是否发生了一些变化?我检查了
boto3
API以确保,但是
start\u实例
仍然是相同的函数

除了上面链接的文章,我没有修改任何代码

更新

CloudWatch记录了最近一次成功运行
startEC2Instances
功能的日志(它没有按预期工作,仍然没有启动实例)

更新2 我正在复制上面文档中的政策文档和代码,我没有做任何更改

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": "arn:aws:logs:*:*:*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:Start*",
        "ec2:Stop*"
      ],
      "Resource": "*"
    }
  ]
}
startEC2Instance
代码:

import boto3
# Enter the region your instances are in. Include only the region without specifying Availability Zone; e.g.; 'us-east-1'
region = 'us-east-1'
# Enter your instances here: ex. ['X-XXXXXXXX', 'X-XXXXXXXX']
instances = ['REDACTED']

def lambda_handler(event, context):
    ec2 = boto3.client('ec2', region_name=region)
    ec2.start_instances(InstanceIds=instances)
    print 'started your instances: ' + str(instances)

问题似乎是连接到我的实例的加密卷。该卷被设置为启动时启动,因此导致了问题。我尝试使用不同的IAM EBS操作,包括
AttachVolume
DetachVolume
descripebolumes
,等等


但最终起作用的操作是KMS操作
CreateGrant
,资源设置为加密卷的密钥的
密钥ID

你需要提供更多关于你遇到的实际问题的信息,而不是“没有做好它的工作”。请编辑您的问题,以包含您收到的实际错误消息。@MarkB没有错误。当我测试这个函数时,它说它成功了。但是我想要启动的EC2实例还没有启动。我总是尝试在实例停止一两分钟后启动它们。检查CloudWatch日志中Lambda函数的日志是否有任何错误。在代码中添加try/catch以确保捕获(并记录)抛出的任何异常。@MarkB请检查更新您可能应该修改代码以显示
ec2.start\u instances()
-它提供任何已启动实例的InstanceId(只需将其放入
print()
语句中)。此外,请确保您正在查看正确的区域,以查看它们是否已启动。文档中始终有一小段缺少的信息未涵盖;-)
import boto3
# Enter the region your instances are in. Include only the region without specifying Availability Zone; e.g.; 'us-east-1'
region = 'us-east-1'
# Enter your instances here: ex. ['X-XXXXXXXX', 'X-XXXXXXXX']
instances = ['REDACTED']

def lambda_handler(event, context):
    ec2 = boto3.client('ec2', region_name=region)
    ec2.start_instances(InstanceIds=instances)
    print 'started your instances: ' + str(instances)