4444 DOWNLOAD_FILES = False
4545else :
4646 DOWNLOAD_FILES = os .environ ['DOWNLOAD_FILES' ]
47+ MY_NAME = os .environ ['MY_NAME' ]
4748
4849localIn = '/home/ubuntu/local_input'
4950
@@ -110,18 +111,19 @@ def runSomething(message):
110111
111112 # Parse your message somehow to pull out a name variable that's going to make sense to you when you want to look at the logs later
112113 # What's commented out below will work, otherwise, create your own
113- # group_to_run = message["group"]
114- # groupkeys = list(group_to_run.keys())
115- # groupkeys.sort()
116- # metadataID = '-'.join(groupkeys)
114+ group_to_run = message ["group" ]
115+ groupkeys = list (group_to_run .keys ())
116+ groupkeys .sort ()
117+ metadataID = '-' .join (groupkeys )
117118
118119 # Add a handler with
119- # watchtowerlogger=watchtower.CloudWatchLogHandler(log_group=LOG_GROUP_NAME, stream_name=str(metadataID),create_log_group=False)
120- # logger.addHandler(watchtowerlogger)
120+ watchtowerlogger = watchtower .CloudWatchLogHandler (log_group = LOG_GROUP_NAME , stream_name = str (metadataID ),create_log_group = False )
121+ logger .addHandler (watchtowerlogger )
121122
122123 # See if this is a message you've already handled, if you've so chosen
123124 # First, build a variable called remoteOut that equals your unique prefix of where your output should be
124125 # Then check if there are too many files
126+ remoteOut = metadataID
125127
126128 if CHECK_IF_DONE_BOOL .upper () == 'TRUE' :
127129 try :
@@ -143,14 +145,25 @@ def runSomething(message):
143145 # ie cmd = my-program --my-flag-1 True --my-flag-2 VARIABLE
144146 # you should assign the variable "localOut" to the output location where you expect your program to put files
145147
148+ localOut = metadataID
149+ local_file_name = os .path .join (localOut ,'HelloWorld.txt' )
150+ if not os .path .exists (localOut ):
151+ os .makedirs (localOut ,exist_ok = True )
152+
153+ cmd = f'printf "Hi, my name is { MY_NAME } , and my favorite { groupkeys [0 ]} is { group_to_run [groupkeys [0 ]]} , and my favorite { groupkeys [1 ]} is { group_to_run [groupkeys [1 ]]} " > { local_file_name } '
154+
146155 print ('Running' , cmd )
147156 logger .info (cmd )
148- subp = subprocess .Popen (cmd .split (), stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
157+ #typically, changes to the subprocess command aren't needed at all
158+ subp = subprocess .Popen (cmd , shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
149159 monitorAndLog (subp ,logger )
150160
151161 # Figure out a done condition - a number of files being created, a particular file being created, an exit code, etc.
162+
163+ done = True
164+
152165 # If done, get the outputs and move them to S3
153- if [ ENTER DONE CONDITION HERE ] :
166+ if done :
154167 time .sleep (30 )
155168 mvtries = 0
156169 while mvtries < 3 :
0 commit comments