in source/controlplaneapi/runtime/app.py [0:0]
def delete_event(name, program):
"""
Delete an event by name and program.
Returns:
None
Raises:
400 - BadRequestError
404 - NotFoundError
500 - ChaliceViewError
"""
try:
name = urllib.parse.unquote(name)
program = urllib.parse.unquote(program)
query_params = app.current_request.query_params
if query_params and query_params.get("force") == "true":
force_delete = True
else:
force_delete = False
event_table = ddb_resource.Table(EVENT_TABLE_NAME)
response = event_table.get_item(
Key={
"Name": name,
"Program": program
},
ConsistentRead=True
)
if "Item" not in response:
raise NotFoundError(f"Event '{name}' in Program '{program}' not found")
elif response["Item"]["Status"] == "In Progress":
raise BadRequestError(f"Cannot delete Event '{name}' in Program '{program}' as it is currently in progress")
channel_id = response["Item"]["Channel"] if "Channel" in response["Item"] else None
profile = response["Item"]["Profile"]
source_auth_secret_arn = response["Item"]["SourceVideoAuthSecretARN"] if "SourceVideoAuthSecretARN" in response[
"Item"] else None
if channel_id:
print(
f"Checking if MRE Destination and OutputGroup need to be deleted in the MediaLive channel '{channel_id}'")
delete_medialive_output_group(name, program, profile, channel_id)
print(
f"Checking if the CloudWatch Alarm for 'InputVideoFrameRate' metric needs to be deleted for the MediaLive channel '{channel_id}'")
response = event_table.query(
IndexName=EVENT_CHANNEL_INDEX,
KeyConditionExpression=Key("Channel").eq(channel_id)
)
events = response["Items"]
while "LastEvaluatedKey" in response:
response = event_table.query(
ExclusiveStartKey=response["LastEvaluatedKey"],
IndexName=EVENT_CHANNEL_INDEX,
KeyConditionExpression=Key("Channel").eq(channel_id)
)
events.extend(response["Items"])
if len(events) < 2:
delete_cloudwatch_alarm_for_channel(channel_id)
if source_auth_secret_arn:
if force_delete:
print(f"Deleting the secret '{source_auth_secret_arn}' immediately")
sm_client.delete_secret(
SecretId=source_auth_secret_arn,
ForceDeleteWithoutRecovery=True
)
else:
print(f"Deleting the secret '{source_auth_secret_arn}' with a recovery window of 7 days")
sm_client.delete_secret(
SecretId=source_auth_secret_arn,
RecoveryWindowInDays=7
)
print(f"Deleting the Event '{name}' in Program '{program}'")
response = event_table.delete_item(
Key={
"Name": name,
"Program": program
}
)
# Send a message to the Event Deletion SQS Queue to trigger the deletion of processing data in DynamoDB for the Event
notify_event_deletion_queue(name, program, profile)
except NotFoundError as e:
print(f"Got chalice NotFoundError: {str(e)}")
raise
except BadRequestError as e:
print(f"Got chalice BadRequestError: {str(e)}")
raise
except Exception as e:
print(f"Unable to delete the Event '{name}' in Program '{program}': {str(e)}")
raise ChaliceViewError(f"Unable to delete the Event '{name}' in Program '{program}': {str(e)}")
else:
print(f"Deletion of Event '{name}' in Program '{program}' successful")
return {}