1

I have created a python Lambda Function in AWS to start some EC2 instances based on a TAG that's being deployed to them. It checks if the instance is stopped and only run on them.

import boto3
import logging
ec2 = boto3.resource('ec2')
def lambda_handler(event, context):
    filters = [{
        'Name': 'tag:STARTUP',
        'Values': ['YES']
    },
    {
        'Name': 'instance-state-name', 
        'Values': ['stopped']
    }]
instances = instances.filter(Filters=filters)
stoppedInstances = [instance.id for instance in instances]
if len(stoppedInstances) > 0:
    startingUp = instances.filter(instances).start()

When I try to run it, I get the following error:

START RequestId: XXX Version: $LATEST
filter() takes 1 positional argument but 2 were given: TypeError
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 17, in lambda_handler
    startingUp = ec2.instances.filter(instances).start()
TypeError: filter() takes 1 positional argument but 2 were given

Although everywhere I look the FILTER variable is able to handle more than one argument but somehow I am only able to use one?

I'm using Python 3.6 runtime and I am using the same role as other function that works correctly to start servers (based only on time).

Can you please advise? Thank you!

Arafat Nalkhande
  • 11,078
  • 9
  • 39
  • 63
FDS
  • 31
  • 1
  • 5
  • This might help you understand the error : https://stackoverflow.com/questions/23944657/typeerror-method-takes-1-positional-argument-but-2-were-given/23944658 – Hakro Aug 02 '17 at 14:22
  • ec2.instances.filter(...) – jarmod Aug 02 '17 at 14:45

1 Answers1

2

This did the trick @ last line! Thank you for your comments that pointed me to the right direction :)

startingUp = ec2.instances.filter(InstanceIds=stoppedInstances).start()
FDS
  • 31
  • 1
  • 5