Home > Software engineering >  Creating lambda function to invoke glue job
Creating lambda function to invoke glue job

Time:11-14

Through Terraform I created a lambda function to invoke glue job. I am running terraform apply job using jenkins and I am getting syntax error when I test the lambda function after creating.

If I run terraform apply from local terminal it's working good.

Lambda test also executed, but through jenkins terraform apply i am getting syntax error.

invoke-glue-job.py:

from __future__ import print_function
import boto3
import urllib

print ('Loading function')

glue = boto3.client('glue')

def lambda_handler(event, context)
    gluejobname = "job1"

    try: 
        runId = glue.start_job_run(JobName=gluejobname)
        status = glue.get_job_run(JobName=gluejobname, RunId=runid['JobRunId'])
        print("Job Status : ", status['JobRun']['JobRunState'], "runId",runId)
    except Exception as e:
        raise e

I am getting below error when I run through jenkins job:

{
  "errorMessage": "Syntax error in module 'invoke-glue-job': invalid syntax (invoke-glue-job.py, line 9)",
  "errorType": "Runtime.UserCodeSyntaxError",
  "requestId": "46a194e6-410b-45ed-927e-3e752f5836cb",
  "stackTrace": [
    "  File \"/var/task/invoke-glue-job.py\" Line 9\n    def lambda_handler(event, context)\n"
  ]
}

I used handler = "invoke-glue-job.lambda_handler" in terraform configuration. I am not sure what the error here. Any suggestions?

CodePudding user response:

You forgot about :. So it should be:

def lambda_handler(event, context):
  • Related