Search code examples
aws-glueaws-step-functions

How to use a parameter


I have a Step Output containing {"hello": "wold"} and my pythonshell had this output as Step Input showing up in the State Machine Graph.

I want to print the value world by using the key hello in a pythonshell job

This is the code I have now and it is not working, I get the error that the argument watisdit is expected:

import sys
from awsglue.utils import getResolvedOptions


def main():
    args = getResolvedOptions(sys.argv, ['JOB_NAME', 'watisdit'])
    print('watisdit: ' + str(args['watisdit']))
    print('Number of arguments:', len(sys.argv), 'arguments.')
    print('Argument List:', str(sys.argv))


if __name__ == "__main__":
    main()

Solution

  • Glue job expects argument keys starting with '--'. See here for reference.

    For your current code your argument must contain: {"--hello": "wold"}

    and the code will be:

    import sys
    from awsglue.utils import getResolvedOptions
    
    args = getResolvedOptions(sys.argv, ['JOB_NAME', 'hello'])
    print("The value for hello is:" , args['hello'])