Lambda demo functions for Server Stop/Start/Status
This commit is contained in:
parent
3436132866
commit
8f62d9bf83
5 changed files with 106 additions and 1 deletions
|
|
@ -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"
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue