This commit is contained in:
Torsten 2024-12-23 15:46:37 +01:00
parent 35bd66f21f
commit 8ab76adbe6
146 changed files with 101 additions and 40 deletions

View file

@ -0,0 +1,51 @@
https://aws.amazon.com
awsuser@zauberturm.de => $Mehrwert!...
AccountID: 990489675026
Azimandius
IMPORTANT:
When creating the security group, UDP 8000-8100 should be added as allowed
```
ssh -i my_private_key.pem ec2-user@public-ipv4
```
Key Permissions must be set to 600
Create user:
```
sudo useradd -m -U awa-admin
sudo passwd awa-admin
sudo su
mkdir /opt/awa
cd /opt/awa
wget https://www.zauberturm.de/downloads/
sudo chown -R awa-admin:awa-admin /opt/awa
sudo yum install p7zip
```
GetAwaServerIp
```
GET https://7l7x7zpr7ybfjrugwg5hybrd7i0ptqmc.lambda-url.eu-central-1.on.aws/
```
GetAwaUptime
```
GET https://5f7rkcljorwmzo4mnsjpl5bdde0frkcb.lambda-url.eu-central-1.on.aws/
```
StartAwaServer
```
GET https://xqip7wowsd6shind4q3t6hqafa0axudp.lambda-url.eu-central-1.on.aws/
```
StopAWAServer
```
GET https://5ps72qu3uclwnawce5cziv7a6a0niulv.lambda-url.eu-central-1.on.aws/
```

View file

@ -0,0 +1,19 @@
````bash
$ crontab -e
@reboot /home/ec2-user/start_cloud_host.sh
````
Contents of start_cloud_host:
````bash
#!/bin/bash
kill -9 `ps -ef|grep master_server|grep headless|awk '{print $2}'`
kill -9 `ps -ef|grep scene_server|grep headless|awk '{print $2}'`
~/awa/master_server.x86_64 --headless > master_log.txt &
sleep 2
~/awa/scene_server.x86_64 --headless > scene_log.txt & # TODO: Set unique log name
`````
![[Pasted image 20240121135842.png]]

View file

@ -0,0 +1 @@
`sudo yum install cronie`

View file

@ -0,0 +1,43 @@
import boto3
import time
import datetime
#ec2 = boto3.resource('ec2')
ec2 = boto3.client('ec2')
awa_server_instance_id = "i-0de7cce6fcdf8c0e6"
def lambda_handler(event, context):
#return "1.2.3.4"
#filters = [
# {
# 'Name': 'instance-state-name',
# 'Values': ['running']
# }
#]
#
#instances = ec2.instances.filter(Filters=filters)
#
#for instance in instances:
# print(instance)
response = ec2.describe_instances()
for reservation in response['Reservations']:
for instance in reservation['Instances']:
instance_id = instance.get('InstanceId', 'NONE')
ip = instance.get('PublicIpAddress', '127.0.0.1')
if instance_id == awa_server_instance_id:
#return {
# 'statusCode': 200,
# 'ip': ip
#}
return ip
#return {
# 'statusCode': 200,
# 'ip': "127.0.0.1"
#}
return "127.0.0.1"

View file

@ -0,0 +1 @@
1.) https://www.youtube.com/watch?v=T7cny-uyCuA

View file

@ -0,0 +1,15 @@
```python
#StopServer
import boto3
region = 'eu-central-1'
#instances = ['i-0de7cce6fcdf8c0e6']
ec2 = boto3.client('ec2', region_name=region)
def lambda_handler(event, context):
ec2.stop_instances(InstanceIds=["i-0de7cce6fcdf8c0e6"])
return {
'message' : 'stopped'
}
```
`

View file

@ -0,0 +1,13 @@
```python
#StartServer
import boto3
region = 'eu-central-1'
#instances = ['i-0de7cce6fcdf8c0e6']
ec2 = boto3.client('ec2', region_name=region)
def lambda_handler(event, context):
ec2.start_instances(InstanceIds=["i-0de7cce6fcdf8c0e6"])
return {
'message' : 'server started'
}
```

View file

@ -0,0 +1,45 @@
```python
import boto3
import time
import datetime
#ec2 = boto3.resource('ec2')
ec2 = boto3.client('ec2')
awa_server_instance_id = "i-0de7cce6fcdf8c0e6"
def lambda_handler(event, context):
#return "1.2.3.4"
#filters = [
# {
# 'Name': 'instance-state-name',
# 'Values': ['running']
# }
#]
#
#instances = ec2.instances.filter(Filters=filters)
#
#for instance in instances:
# print(instance)
response = ec2.describe_instances()
for reservation in response['Reservations']:
for instance in reservation['Instances']:
instance_id = instance.get('InstanceId', 'NONE')
ip = instance.get('PublicIpAddress', 'DOWN')
if instance_id == awa_server_instance_id:
#return {
# 'statusCode': 200,
# 'ip': ip
#}
return ip+'\n'
#return {
# 'statusCode': 200,
# 'ip': "DOWN"
#}
return "DOWN\n"
```

View file

@ -0,0 +1,31 @@
```python
#Get Uptime
import boto3
import time
import datetime
region = 'eu-central-1'
instances = ['i-0de7cce6fcdf8c0e6']
ec2 = boto3.resource('ec2')
print("Executing script")
def lambda_handler(event, context):
for instance in ec2.instances.all():
if instance.id =="i-0de7cce6fcdf8c0e6":
state = instance.state["Name"]
if state != "running":
return {
'state' : state,
'uptime': '-'
}
else:
launch_time = (instance.launch_time).strftime("%Y-%m-%d %H:%M:%S")
launch_time = datetime.datetime.strptime(launch_time, "%Y-%m-%d %H:%M:%S")
current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
current_time = datetime.datetime.strptime(current_time, "%Y-%m-%d %H:%M:%S")
uptime = (current_time - launch_time)
threshold = datetime.timedelta(minutes = 2)
return {
'state' : state,
'uptime': str(uptime)
}
```