| 1673 | # Cloudfront distribution |
| 1674 | ## |
| 1675 | def update_lambda_function_url_domains(self, function_name, function_url_domains, certificate_arn, cloudfront_config): |
| 1676 | response = self.lambda_client.list_function_url_configs(FunctionName=function_name, MaxItems=50) |
| 1677 | if not response.get("FunctionUrlConfigs", []): |
| 1678 | print("no function url configured on lambda, skip setting custom domains") |
| 1679 | url = response["FunctionUrlConfigs"][0]["FunctionUrl"] |
| 1680 | import urllib |
| 1681 | |
| 1682 | url = urllib.parse.urlparse(url) |
| 1683 | |
| 1684 | NULL_CONFIG = {"Quantity": 0, "Items": []} |
| 1685 | |
| 1686 | config = { |
| 1687 | "CallerReference": "zappa-create-function-url-custom-domain-" + function_name.split(":")[-1], |
| 1688 | "Aliases": {"Quantity": len(function_url_domains), "Items": function_url_domains}, |
| 1689 | "DefaultRootObject": "", |
| 1690 | "Enabled": True, |
| 1691 | "PriceClass": "PriceClass_100", |
| 1692 | "HttpVersion": "http2", |
| 1693 | "Comment": "Lambda FunctionURL {}".format(function_name.split(":")[-1]), |
| 1694 | "Origins": { |
| 1695 | "Quantity": 1, |
| 1696 | "Items": [ |
| 1697 | { |
| 1698 | "Id": "LambdaFunctionURL", |
| 1699 | "DomainName": url.hostname, |
| 1700 | "OriginPath": "", |
| 1701 | "CustomHeaders": { |
| 1702 | "Quantity": 1, |
| 1703 | "Items": [ |
| 1704 | {"HeaderName": "CloudFront", "HeaderValue": "CloudFront"}, |
| 1705 | ], |
| 1706 | }, |
| 1707 | "CustomOriginConfig": { |
| 1708 | "HTTPPort": 80, |
| 1709 | "HTTPSPort": 443, |
| 1710 | "OriginProtocolPolicy": "https-only", |
| 1711 | "OriginSslProtocols": {"Quantity": 1, "Items": ["TLSv1"]}, |
| 1712 | "OriginReadTimeout": 60, |
| 1713 | "OriginKeepaliveTimeout": 60, |
| 1714 | }, |
| 1715 | } |
| 1716 | ], |
| 1717 | }, |
| 1718 | "CacheBehaviors": NULL_CONFIG, |
| 1719 | "CustomErrorResponses": NULL_CONFIG, |
| 1720 | "DefaultCacheBehavior": { |
| 1721 | "TargetOriginId": "LambdaFunctionURL", |
| 1722 | "ViewerProtocolPolicy": "redirect-to-https", |
| 1723 | "Compress": True, |
| 1724 | "SmoothStreaming": True, |
| 1725 | "LambdaFunctionAssociations": NULL_CONFIG, |
| 1726 | "FieldLevelEncryptionId": "", |
| 1727 | "AllowedMethods": { |
| 1728 | "Quantity": 7, |
| 1729 | "Items": ["HEAD", "DELETE", "POST", "GET", "OPTIONS", "PUT", "PATCH"], |
| 1730 | "CachedMethods": {"Quantity": 3, "Items": ["HEAD", "GET", "OPTIONS"]}, |
| 1731 | }, |
| 1732 | "CachePolicyId": "4135ea2d-6df8-44a3-9df3-4b5a84be39ad", # noqa: E501 https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html |