Last time Set to start from the client application by diverting the process executed from the created Lambda.
ʻaws_secret_access_key
Default region
.pyinstaller
with the following command.
pip install pyinstaller
XXXXXXXXXX
part sets the AWS account ID.command
partfrom utils.logger import LoggerObj
import sys
import os
import requests
import tkinter
from datetime import datetime
import boto3
from tkinter import *
from tkinter import messagebox
from tkinter import filedialog
from tkinter import ttk
from tkinter.ttk import *
import threading
from tkinter import messagebox
from tkinter import filedialog
from tkinter import Button,ttk,StringVar
from selenium import webdriver
from functools import partial
root= tkinter.Tk()
EXECUTE_LIST=['Process A','Process B','Process C']
class PythonGui():
def __init__(self):
self.lock = threading.Lock()
self.inputText=StringVar()
self.progressMsg=StringVar()
self.progressBar=None
self.progressMsgBox=None
self.progressStatusBar=None
self.progressValue=None
def init(self):
pass
#Operation after initial setting
def preparation(self,logfilename):
self._executer=partial(self.execute,logfilename)
def progressSequence(self,msg,sequenceValue=0):
self.progressMsg.set(msg)
self.progressValue=self.progressValue+sequenceValue
self.progressStatusBar.configure(value=self.progressValue)
def quite(self):
if messagebox.askokcancel('Confirmation of end','Do you want to end the process?'):
if self.lock.acquire(blocking=FALSE):
pass
else:
messagebox.showinfo('Confirmation of end','Please close the browser while the browser is running.')
self.lock.release()
root.quit()
else:
pass
def execute(self,logfilename):
logObj=LoggerObj()
log=logObj.createLog(logfilename)
log.info('Start processing')
executeType=EXECUTE_LIST.index(self.combo.get())
nowDate=datetime.now().strftime('%Y%m%d%H%M%S')
inputVal=self.inputText.get()
client = boto3.client('batch')
JOB_NAME = 'pandas-envtest'
JOB_QUEUE = "arn:aws:batch:ap-northeast-1:XXXXXXXXXX:job-queue/first-run-job-queue"
JOB_DEFINITION = "arn:aws:batch:ap-northeast-1:XXXXXXXXXX:job-definition/pandas-envtest:1"
response = client.submit_job(
jobName = JOB_NAME,
jobQueue = JOB_QUEUE,
jobDefinition = JOB_DEFINITION,
containerOverrides={
'command': [
inputVal,nowDate,str(executeType)
],
'environment': [
{
'name': 'TEST',
'value': 'abcd'
}
]
}
)
self.progressMsgBox.after(10,self.progressSequence('Processing is in progress',sequenceValue=50))
root.update_idletasks()
self.progressBar.stop()
self.progressMsgBox.after(10,self.progressSequence('Registration process completed',sequenceValue=50))
root.update_idletasks()
log.info('Processing Exit')
self.lock.release()
def doExecute(self):
if self.lock.acquire(blocking=FALSE):
if messagebox.askokcancel('Confirmation before execution','Do you want to perform the process?'):
self.progressValue=0
self.progressStatusBar.configure(value=self.progressValue)
self.progressBar.configure(maximum=10,value=0)
self.progressBar.start(100)
th = threading.Thread(target=self._executer)
th.start()
else:
self.lock.release()
else:
messagebox.showwarning('error','Processing is in progress')
def progressMsgSet(self,msg):
self.progressMsg.set(msg)
def progressStart(self):
self.progressBar.start(100)
def main(self):
root.title("Python GUI")
content = ttk.Frame(root)
frame = ttk.Frame(content, relief="sunken", width=300, height=500)
title = ttk.Label(content, text="Python GUI")
content.grid(column=0, row=0)
title.grid(column=0, row=0, columnspan=4)
fileLabel=ttk.Label(content,text="Processing number")
pulldownLabel=ttk.Label(content,text="Processing content")
fileInput=ttk.Entry(content,textvariable=self.inputText,width=23)
self.inputText.set('A01')
#Creating a combo box(Placed as root,List values cannot be edited(readonly)Set to)
self.combo = ttk.Combobox(content, state='readonly')
#Set the value of the list
self.combo["values"] = tuple(EXECUTE_LIST)
#The default value is food expenses(index=0)Set to
self.combo.current(0)
labelStyle=ttk.Style()
labelStyle.configure('PL.TLabel',font=('Helvetica',10,'bold'),background='white',foreground='red')
self.progressMsgBox=ttk.Label(content,textvariable=self.progressMsg,width=70,style='PL.TLabel')
self.progressMsg.set('Waiting for processing')
self.progressBar=ttk.Progressbar(content,orient=HORIZONTAL,length=140,mode='indeterminate')
self.progressBar.configure(maximum=10,value=0)
self.progressStatusBar=ttk.Progressbar(content,orient=HORIZONTAL,length=140,mode='determinate')
executeButton=ttk.Button(content,text='Run',command=self.doExecute)
quiteButton=ttk.Button(content,text='End',command=self.quite)
fileLabel.grid(column=1, row=1,sticky='w')
fileInput.grid(column=2, row=1)
pulldownLabel.grid(column=1, row=2,sticky='w')
#Combo box placement
self.combo.grid(column=2, row=2)
executeButton.grid(column=1, row=6,columnspan=2,sticky='we')
quiteButton.grid(column=1, row=12,columnspan=2,sticky='we')
root.mainloop()
if __name__ == "__main__":
pythonGui=PythonGui()
pythonGui.preparation('log')
pythonGui.main()
The processing contents are as follows.
A function called at runtime. The process of creating a screen is described here.
The initial value of the text area and the contents of the combo box are also created.
This process is called when the execute button is pressed.
Thread is used to prevent double boot.
This is the process that actually calls AWS Batch.
If you receive ʻaws_access_key_id ʻaws_secret_access_key
Default region
when you call boto3.client, you do not need to install AWS CLI.
You can check it by executing the source, but if you want to use it as a client application, create an exe with the following command. If the source file name is pythonGui.py
, it will be as follows.
When the exe file is executed, it will start as a client application as shown below.
The execution result of AWS Batch will be the same as the last time, so it is omitted.
Recommended Posts