Search code examples
pythonaws-lambdaboto3aws-glue

Passing Lambda Variable to Glue Script AWS


I have a lambda function that looks like this:

client = boto3.client('glue')

glueJobName = "Python Glue Script"
inputtedData = "A1B2C3D4E5"
school = "testing"

def lambda_handler(event, context):
    response = client.start_job_run(JobName = glueJobName, Arguments = {'==inputtedData': inputtedData, '--school': school})
    return response

This starts running my glue job which contains a script. However, I want to pass the Arguments 'inputtedData' and 'school' to this script, so that when the script starts, these variables will be inputted into my syncData function like this:

def syncAttendance(inputtedData, school):

   schoolName = school
   Data = inputtedData
   print(schoolName, Data)


syncData(inputtedData, school)

How do I receive these variables in the glue script?


Solution

  • You need to use getResolvedOptions function as follows:

    import sys
    from awsglue.utils import getResolvedOptions
    
    options = ['inputtedData', 'school']
    args = getResolvedOptions(sys.argv, options)
    
    syncData(args['inputtedData'], args['school'])