Created
May 19, 2023 19:19
-
-
Save AngelChaidez/c6433e551ff30b237f2a039bde8b0f2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
#!/usr/bin/env python3.11 | |
# this script will start ec2 instances based off of tags | |
import boto3 | |
import sys | |
import os | |
def lambda_handler(event, context): | |
ec2 = boto3.client('ec2') | |
regions = [region['RegionName'] | |
for region in ec2.describe_regions()['Regions']] | |
# start instances in us-east-1 with Key labeled 'tag' and Value labeled 'swarm_node' | |
filters = [{ | |
'Name': 'tag:swarm_node', | |
'Values': ['true'] | |
} | |
] | |
for region in regions: | |
ec2 = boto3.resource('ec2', region_name=region) | |
instances = ec2.instances.filter(Filters=filters) | |
for instance in instances: | |
instance.start() | |
print(f"started instance: {instance.id} in {region}") | |
return { | |
'statusCode': 200, | |
'body': json.dumps('Hello from Lambda!') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment