'Is their a way to pass the output of a Lambda function into another Lambda function to be used as a variable?
I have a Lambda function which returns email addresses into the function log of lambda and i have another lambda function that sends scheduled emails.
I am trying to pass the result from the email addresses function into the second scheduled email function to be used as a variable for the recipients of the scheduled emails.
Here is the code for anyone wondering:
This Function retrieves the email/'s from the database
import pymysql
# RDS config
endpoint = '*******'
username = '*******'
password = '*******'
database_name = '******'
#connection config
connection = pymysql.connect(host=endpoint,user=username,passwd=password,db=database_name)
def handler(event, context):
cursor = connection.cursor()
cursor.execute('SELECT `Presenters`.Email FROM `Main` INNER JOIN `Presenters` ON `Main`.`PresenterID` = `Presenters`.`PresentersID` WHERE `Main`.`Read Day` ="Tuesday"')
rows = cursor.fetchall()
for row in rows:
print("{0}".format(row[0]))
This Second Function sends emails using Python
import os
import smtplib
from email.message import EmailMessage
def lambda_handler(event, context):
EMAIL_ADDRESS = "**********"
EMAIL_PASSWORD = os.environ.get('EMAIL_PASSWORD')
msg = EmailMessage()
msg['Subject'] = "*********"
msg['From'] = EMAIL_ADDRESS
msg['To'] = ['************']
msg.set_content('Hi everyone, a new read timetable has been posted for next week so be sure to check it and keep up to date on your reads, Thank you!')
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
smtp.send_message(msg)
Solution 1:[1]
There is no such way in the lambda service.
If this is something that has to run sequentially, which is most probably has to, I would strongly recommend looking into Step Functions. Step Functions are basically state machines that orchestrate your workflows by calling your lambda functions (also have support for other compute services) sequentially and the output of one function can be passed in the input for the function that is executed after it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
