Skip to content

Commit a91015f

Browse files
committed
Updated the trigger toggle and minor changes to the Readme file
Updated the trigger toggle and minor changes to the Readme file
1 parent 4eca172 commit a91015f

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ The demo application is deployed as an [AWS CloudFormation](https://aws.amazon.c
7777
#### Accessing the Application
7878

7979
After deployment, the application can be used by configuring the following services.
80-
1. The event that triggers the step Machine is defaulted to run every hour and is set to "Enabled" at the start. This event can be modified and set to "Disabled" if the use case does not need to trigger the step machine automatically. The default hourly run schedule can also be modified as per use case. When modifying the run schedule, a key point to bear in mind will be to check the pricing for Amazon Rekognition Custom Labels - which is currently priced per hour.
80+
1. The event that triggers the Step Machine is defaulted to run every hour and is set to "Enabled" at the start. This event can be modified and set to "Disabled" if the use case does not need to trigger the step machine automatically. The default hourly run schedule can also be modified as per use case. When modifying the run schedule, a key point to bear in mind will be to check the pricing for Amazon Rekognition Custom Labels - which is currently priced per hour. The step machine is configured to shut down the model after 1 hour by default.
8181
2. The Source S3 bucket should be used as the destination bucket for all the images to be used for inferencing.
8282
3. The Final S3 bucket holds the images that have been processed along with the inferenced custom label jsons.
8383

8484

8585
### Remove the application
8686

87-
To remove the application open the AWS CloudFormation Console, click the PPE Demo project, right-click and select "_Delete Stack_". Your stack will take some time to be deleted. You can track its progress in the "Events" tab. When it is done, the status will change from "_DELETE_IN_PROGRESS_" to "_DELETE_COMPLETE_". It will then disappear from the list.
87+
To remove the application open the AWS CloudFormation Console, click on the name of the project, right-click and select "_Delete Stack_". Your stack will take some time to be deleted. You can track its progress in the "Events" tab. When it is done, the status will change from "_DELETE_IN_PROGRESS_" to "_DELETE_COMPLETE_". It will then disappear from the list. Please note that the Amazon S3 buckets will only be deleted if they are empty.
8888

8989

9090
## License

functions/toggle_trigger/app.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,28 @@ def lambda_handler(event, context):
4343
print(e)
4444

4545
# State (string) -- The state of the event source mapping. It can be one of the following: Creating , Enabling , Enabled , Disabling , Disabled , Updating , or Deleting .
46-
running_states = ["Enabling", "Enabled"]
46+
running_states = ["Enabling", "Enabled", "Disabled", "Disabling"]
4747
if response['State'] in running_states:
4848
# Disable
49-
try:
50-
response = lambda_client.update_event_source_mapping(
51-
UUID = analyse_lambda_uuid,
52-
Enabled = False
53-
)
54-
except Exception as e:
55-
print(e)
56-
else:
57-
# Enable
58-
try:
59-
response = lambda_client.update_event_source_mapping(
49+
if (event[0]['Action'] == 'disable'):
50+
try:
51+
response = lambda_client.update_event_source_mapping(
6052
UUID = analyse_lambda_uuid,
61-
Enabled = True
62-
)
63-
except Exception as e:
64-
print(e)
53+
Enabled = False
54+
)
55+
except Exception as e:
56+
print(e)
57+
else:
58+
# Enable
59+
if (event[0]['Action'] == 'enable'):
60+
try:
61+
response = lambda_client.update_event_source_mapping(
62+
UUID = analyse_lambda_uuid,
63+
Enabled = True
64+
)
65+
except Exception as e:
66+
print(e)
67+
else:
68+
print("Current state is:", response['State'])
6569

6670
return response['State']
67-
# return {'status': '200'}
68-

template.yaml

Lines changed: 6 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.2'
15+
Version: 'v0.3'
1616

1717
Resources:
1818
SourceS3Bucket:
@@ -107,10 +107,14 @@ Resources:
107107
Next: Disable SQS Trigger
108108
Enable SQS Trigger:
109109
Type: Task
110+
Parameters:
111+
- Action: enable
110112
Resource: !GetAtt ToggleTriggerFunction.Arn
111113
Next: Keep Model running for 1 hr
112114
Disable SQS Trigger:
113115
Type: Task
116+
Parameters:
117+
- Action: disable
114118
Resource: !GetAtt ToggleTriggerFunction.Arn
115119
Next: Stop Model
116120
Stop Model:
@@ -122,7 +126,7 @@ Resources:
122126
Type: Schedule # More info about Schedule Event Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-statemachine-schedule.html
123127
Properties:
124128
Description: Schedule to run the state machine every hour
125-
Enabled: True # This schedule can be disabled based on the use case to avoid incurring charges.
129+
Enabled: False # This schedule can be disabled based on the use case to avoid incurring charges.
126130
Schedule: "rate(1 hour)"
127131
Policies: # Find out more about SAM policy templates: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-templates.html
128132
- LambdaInvokePolicy:

0 commit comments

Comments
 (0)