...
This commit is contained in:
parent
d056ecfbea
commit
c33ad9eaf7
9 changed files with 89 additions and 36 deletions
43
MyObsidianVault/AWA/01_AWS Access/Lambda functions.md
Normal file
43
MyObsidianVault/AWA/01_AWS Access/Lambda functions.md
Normal 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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue