0
votes

So im trying to create a lambda function that will trigger when an S3 PUT occurs for now it seems to be executing the code but im getting a problem

import boto3


def lambda_handler(event, context):
    instances = ["i-0b5d926"]
    region = 'ap-south-1a'

    ec2 = boto3.client('ec2',, region_name=region)
    ec2.instances.filter(InstanceIds=instances ).start()

im getting this error

{
  "stackTrace": [
    [
      "/var/task/index.py",
      9,
      "lambda_handler",
      "return ec2.instances.filter(InstanceIds=instaces).start()"
    ],
    [
      "/var/runtime/botocore/client.py",
      509,
      "__getattr__",
      "self.__class__.__name__, item)"
    ]
  ],
  "errorType": "AttributeError",
  "errorMessage": "'EC2' object has no attribute 'instances'"
}

Any help would be appreciated

ON A Side Note THE IAMROLE has full Access (S3,EC2,Lambda) will be configured later for specific purpose

1

1 Answers

0
votes

ok i understood the error

instance was null i changed ec2.instances.filter(InstanceIds=instances ).start() to ec2.start_instances(InstanceIds=instances) and started