Skip to content

NameError - name 'args' is not defined in AWS Glue Data Catalog node

0

Just FYI I'm using visual mode, not the script mode. Therefore, I did not explore any solutions that involve making direct changes to the script, as I prefer to continue using the visual mode.

I selected a runtime parameter for the Table value of my AWS Glue Data Catalog node. But upon doing so, I encounter this exact error: NameError - name 'args' is not defined. Also, this isn't encountered when I manually type the value for the Table.

Here's the screenshot of the error: Enter image description here

Here's the job parameters to ensure that I did have value for the CHARGE_TABLE: Enter image description here

Here's the script I copied from the script tab:

import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job

args = getResolvedOptions(sys.argv, ['JOB_NAME', 'CHARGE_TABLE'])
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args['JOB_NAME'], args)

AWSGlueDataCatalog_node1735831633726 = glueContext.create_dynamic_frame.from_catalog(database="default", table_name=args["CHARGE_TABLE"], transformation_ctx="AWSGlueDataCatalog_node1735831633726")

job.commit()

asked 2 years ago187 views

1 Answer
-1

The error you're encountering is likely due to a mismatch between the visual mode configuration and the underlying script generation. When using runtime parameters in AWS Glue Studio's visual mode, it's important to ensure that these parameters are properly defined and passed to the job.

To resolve this issue, try the following steps:

  1. In the job details panel, go to the "Job details" tab.
  2. Scroll down to the "Job parameters" section.
  3. Add a new job parameter with the key "CHARGE_TABLE" (without quotes) and set its value to the name of your table or the parameter you want to use.

This should define the "CHARGE_TABLE" argument that the script is expecting. The visual editor should then be able to correctly generate the script with the runtime parameter.

If the issue persists, you may need to check if there are any discrepancies between the visual editor's configuration and the generated script. Sometimes, manually editing the script can cause such mismatches. In that case, you might need to recreate the node in the visual editor to ensure everything is properly synchronized.

Remember, when using runtime parameters, it's crucial to define them in the job parameters section for the visual mode to work correctly with parameterized values.
Sources
Adding source and target parameters to the AWS Glue Data Catalog node - AWS Glue
Developing and testing AWS Glue job scripts locally - AWS Glue

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.