44
44
DOWNLOAD_FILES = False
45
45
else :
46
46
DOWNLOAD_FILES = os .environ ['DOWNLOAD_FILES' ]
47
+ MY_NAME = os .environ ['MY_NAME' ]
47
48
48
49
localIn = '/home/ubuntu/local_input'
49
50
@@ -110,18 +111,19 @@ def runSomething(message):
110
111
111
112
# 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
112
113
# 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 )
117
118
118
119
# 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 )
121
122
122
123
# See if this is a message you've already handled, if you've so chosen
123
124
# First, build a variable called remoteOut that equals your unique prefix of where your output should be
124
125
# Then check if there are too many files
126
+ remoteOut = metadataID
125
127
126
128
if CHECK_IF_DONE_BOOL .upper () == 'TRUE' :
127
129
try :
@@ -143,14 +145,25 @@ def runSomething(message):
143
145
# ie cmd = my-program --my-flag-1 True --my-flag-2 VARIABLE
144
146
# you should assign the variable "localOut" to the output location where you expect your program to put files
145
147
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
+
146
155
print ('Running' , cmd )
147
156
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 )
149
159
monitorAndLog (subp ,logger )
150
160
151
161
# 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
+
152
165
# If done, get the outputs and move them to S3
153
- if [ ENTER DONE CONDITION HERE ] :
166
+ if done :
154
167
time .sleep (30 )
155
168
mvtries = 0
156
169
while mvtries < 3 :
0 commit comments