in source/cfn-init-clustered-video-stream/cfn-init-clustered-video-stream.py [0:0]
def delete(event, context):
logger.info("Got Delete")
# Delete never returns anything. Should not fail if the underlying resources are already deleted.
# Desired state.
# Check that all the required properties are specified
if "ClusteredVideoStreamName" not in event["ResourceProperties"]:
raise ValueError("Missing property 'ClusteredVideoStreamName'")
if "MasterPlaylistDistributionId" not in event["ResourceProperties"]:
raise ValueError("Missing property 'MasterPlaylistDistributionId'")
if "RegionOneCloudfrontDistributionId" not in event["ResourceProperties"]:
raise ValueError("Missing property 'RegionOneCloudfrontDistributionId'")
if "RegionTwoCloudfrontDistributionId" not in event["ResourceProperties"]:
raise ValueError("Missing property 'RegionTwoCloudfrontDistributionId'")
if "RegionOne" not in event["ResourceProperties"]:
raise ValueError("Missing property 'RegionOne'")
if "RegionTwo" not in event["ResourceProperties"]:
raise ValueError("Missing property 'RegionTwo'")
# Delete the associated the origin group from the master playlist distributionn
try:
# Delete RegionOne domain
response = cloudfront_client.get_distribution(Id=event["ResourceProperties"]["RegionOneCloudfrontDistributionId"])
config = response["Distribution"]
domain = config["DomainName"]
table = dynamodb_resource.Table(event["ResourceProperties"]["ClusteredVideoStreamName"])
response = table.delete_item(Key={'domain': domain})
# Delete RegionTwo domain
response = cloudfront_client.get_distribution(Id=event["ResourceProperties"]["RegionTwoCloudfrontDistributionId"])
config = response["Distribution"]
domain = config["DomainName"]
table = dynamodb_resource.Table(event["ResourceProperties"]["ClusteredVideoStreamName"])
response = table.delete_item(Key={'domain': domain})
# Delete OriginGroup
response = cloudfront_client.get_distribution_config(Id=event["ResourceProperties"]["MasterPlaylistDistributionId"])
config = response["DistributionConfig"]
if "OriginGroups" in config:
config["OriginGroups"]["Quantity"] = 0
config["OriginGroups"]["Items"] = []
response = cloudfront_client.update_distribution(DistributionConfig=config, Id=event["ResourceProperties"]["MasterPlaylistDistributionId"], IfMatch=response["ETag"])
except Exception as e:
raise e