==람다를 활용한 instance 주소를 이메일로 전송 받기
import json
import boto3
import smtplib
from datetime import date
from email.mime.text import MIMEText
def lambda_handler(event, context):
instance_id = '==instance_id==' # This is the instance ID from the event
ec2 = boto3.client('ec2')
instances_info = ec2.describe_instances(InstanceIds=[instance_id])
current_ip = instances_info['Reservations'][0]['Instances'][0]['PublicIpAddress']str_today = str(date.today())str_ip_address = current_ipstr_mail_title = str_today + " IP address"str_mail_contents = "IP address is " + str_ip_address
s = smtplib.SMTP('smtp.gmail.com', 587)s.starttls()# 로그인 인증s.login('==login address==', '==key==')msg = MIMEText(str_mail_contents) #메일 내용msg['Subject'] = str_mail_title #메일 제목s.sendmail("==sending_address==", "==receive email==", msg.as_string()) #보내기s.quit() # 세션 종료
======================
result
=======================
ip address data - list type data
=delete all data for security
댓글 없음:
댓글 쓰기