mirror of
https://github.com/status-im/libp2p-test-plans.git
synced 2025-02-21 11:08:07 +00:00
This project includes the following components: - `terraform/`: a Terraform scripts to provision infrastructure - `impl/`: implementations of the [libp2p perf protocol](https://github.com/libp2p/specs/blob/master/perf/perf.md) running on top of e.g. go-libp2p, rust-libp2p or Go's std-library https stack - `runner/`: a set of scripts building and running the above implementations on the above infrastructure, reporting the results in `benchmark-results.json` Benchmark results can be visualized with https://observablehq.com/@mxinden-workspace/libp2p-performance-dashboard. Co-authored-by: Marco Munizaga <git@marcopolo.io> Co-authored-by: Marten Seemann <martenseemann@gmail.com> Co-authored-by: Piotr Galar <piotr.galar@gmail.com>
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
import boto3
|
|
import os
|
|
import json
|
|
import datetime
|
|
|
|
regions = json.loads(os.environ['REGIONS']) # Assuming this is a JSON array
|
|
tags = json.loads(os.environ['TAGS']) # Assuming this is a JSON object
|
|
max_age_minutes = int(os.environ['MAX_AGE_MINUTES']) # Assuming this is an integer
|
|
|
|
# TODO: Find and delete unused key pairs
|
|
def lambda_handler(event, context):
|
|
# iterate over all regions
|
|
for region in regions:
|
|
ec2 = boto3.client('ec2', region_name=region)
|
|
|
|
now = datetime.datetime.now(datetime.timezone.utc)
|
|
|
|
filters = [{'Name': 'instance-state-name', 'Values': ['running']}]
|
|
filters = filters + [{
|
|
'Name': 'tag:' + k,
|
|
'Values': [v]
|
|
} for k, v in tags.items()]
|
|
|
|
response = ec2.describe_instances(Filters=filters)
|
|
|
|
instances = []
|
|
|
|
for reservation in response['Reservations']:
|
|
for instance in reservation['Instances']:
|
|
launch_time = instance['LaunchTime']
|
|
instance_id = instance['InstanceId']
|
|
|
|
print(
|
|
f'Instance ID: {instance_id} has been running since {launch_time}.')
|
|
|
|
if launch_time < now - datetime.timedelta(minutes=max_age_minutes):
|
|
print(
|
|
f'Instance ID: {instance_id} has been running for more than {max_age_minutes} minutes.')
|
|
instances.append(instance_id)
|
|
|
|
if instances:
|
|
ec2.terminate_instances(InstanceIds=instances)
|
|
print(f'Terminating instances: {instances}')
|
|
|
|
ec2.describe_
|