Created
November 2, 2016 20:35
-
-
Save moduspwnens/55dab26aeb528d8901da69ea7670e234 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""S3BucketWebSiteDomainFormatterFunction | |
Used as a CloudFormation custom resource to return the domain of a URL. | |
""" | |
from __future__ import print_function | |
import json | |
import urlparse | |
import cfnresponse | |
handler_object = None | |
def lambda_handler(event, context): | |
print("Event: {}".format(json.dumps(event))) | |
request_type = event.get("RequestType") | |
response_data = {} | |
if request_type in ["Create", "Update"]: | |
response_data["WebsiteDomain"] = get_domain_from_url(event["ResourceProperties"]["WebsiteUrl"]) | |
cfnresponse.send(event, context, cfnresponse.SUCCESS, response_data, None) | |
return {} | |
def get_domain_from_url(website_url): | |
parsed_url = urlparse.urlparse(website_url) | |
return parsed_url.netloc.split(":")[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment