Skip to content

Commit f304652

Browse files
committed
Ensure Model Running
1 parent 4f2754f commit f304652

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

functions/start_model/app.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def lambda_handler(event, context):
2525
rekog_client = boto3.client('rekognition')
2626
projectversionarn = os.environ['rekog_model_project_version_arn']
2727
projectarn = os.environ['rekog_model_project_arn']
28-
running_states = ['STARTING', 'RUNNING']
28+
# running_states = ['STARTING', 'RUNNING']
2929
projectversionname = projectversionarn.split("/")[3]
3030
# Check if already running
31-
# Call Custom Rekog
31+
# Call Custom Rekognition project version
3232
try:
3333
isrunning_response = rekog_client.describe_project_versions(
3434
ProjectArn=projectarn,
@@ -38,17 +38,22 @@ def lambda_handler(event, context):
3838
print(e)
3939

4040
running_status = isrunning_response['ProjectVersionDescriptions'][0]['Status']
41-
if running_status in running_states:
41+
if running_status == 'RUNNING':
4242
# Do nothing
4343
print('Model Start Status: %s' % running_status)
44+
return 'RUNNING'
45+
if running_status == 'STARTING':
46+
# Do nothing
47+
print('Model Start Status: %s' % running_status)
48+
return 'STARTING'
4449
else:
4550
# If not running - Start
4651
try:
4752
running_status = rekog_client.start_project_version(
48-
ProjectVersionArn=projectversionarn,
49-
MinInferenceUnits=1 #Can be increased upto 5 for running multiple inference units
53+
ProjectVersionArn = projectversionarn,
54+
MinInferenceUnits = 1 #Can be increased upto 5 for running multiple inference units
5055
)
5156
except Exception as e:
5257
print(e)
53-
54-
return running_status
58+
return running_status
59+

template.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Parameters:
1212
Mappings:
1313
Solution:
1414
Constants:
15-
Version: 'v0.4'
15+
Version: 'v0.5'
1616

1717
Resources:
1818
SourceS3Bucket:
@@ -100,7 +100,7 @@ Resources:
100100
Wait for the model to start:
101101
Type: Wait
102102
Seconds: 600
103-
Next: Enable SQS Trigger
103+
Next: Start Model
104104
Keep Model running for 1 hr:
105105
Type: Wait
106106
Seconds: 3540

0 commit comments

Comments
 (0)