Describe the status of the current deployment.
(self, return_json=False)
| 1685 | return string |
| 1686 | |
| 1687 | def status(self, return_json=False): |
| 1688 | """ |
| 1689 | Describe the status of the current deployment. |
| 1690 | """ |
| 1691 | |
| 1692 | def tabular_print(title, value): |
| 1693 | """ |
| 1694 | Convenience function for priting formatted table items. |
| 1695 | """ |
| 1696 | click.echo("%-*s%s" % (32, click.style("\t" + title, fg="green") + ":", str(value))) |
| 1697 | return |
| 1698 | |
| 1699 | # Lambda Env Details |
| 1700 | lambda_versions = self.zappa.get_lambda_function_versions(self.lambda_name) |
| 1701 | |
| 1702 | if not lambda_versions: |
| 1703 | raise ClickException( |
| 1704 | click.style( |
| 1705 | "No Lambda %s detected in %s - have you deployed yet?" % (self.lambda_name, self.zappa.aws_region), |
| 1706 | fg="red", |
| 1707 | ) |
| 1708 | ) |
| 1709 | |
| 1710 | status_dict = collections.OrderedDict() |
| 1711 | status_dict["Lambda Versions"] = len(lambda_versions) |
| 1712 | function_response = self.zappa.lambda_client.get_function(FunctionName=self.lambda_name) |
| 1713 | conf = function_response["Configuration"] |
| 1714 | self.lambda_arn = conf["FunctionArn"] |
| 1715 | status_dict["Lambda Name"] = self.lambda_name |
| 1716 | status_dict["Lambda ARN"] = self.lambda_arn |
| 1717 | status_dict["Lambda Role ARN"] = conf["Role"] |
| 1718 | status_dict["Lambda Code Size"] = conf["CodeSize"] |
| 1719 | status_dict["Lambda Version"] = conf["Version"] |
| 1720 | status_dict["Lambda Last Modified"] = conf["LastModified"] |
| 1721 | status_dict["Lambda Memory Size"] = conf["MemorySize"] |
| 1722 | status_dict["Lambda Timeout"] = conf["Timeout"] |
| 1723 | # Handler & Runtime won't be present for lambda Docker deployments |
| 1724 | # https://github.com/Miserlou/Zappa/issues/2188 |
| 1725 | status_dict["Lambda Handler"] = conf.get("Handler", "") |
| 1726 | status_dict["Lambda Runtime"] = conf.get("Runtime", "") |
| 1727 | if "VpcConfig" in conf.keys(): |
| 1728 | status_dict["Lambda VPC ID"] = conf.get("VpcConfig", {}).get("VpcId", "Not assigned") |
| 1729 | else: |
| 1730 | status_dict["Lambda VPC ID"] = None |
| 1731 | |
| 1732 | # Calculated statistics |
| 1733 | try: |
| 1734 | function_invocations = self.zappa.cloudwatch.get_metric_statistics( |
| 1735 | Namespace="AWS/Lambda", |
| 1736 | MetricName="Invocations", |
| 1737 | StartTime=datetime.now(timezone.utc) - timedelta(days=1), |
| 1738 | EndTime=datetime.now(timezone.utc), |
| 1739 | Period=1440, |
| 1740 | Statistics=["Sum"], |
| 1741 | Dimensions=[{"Name": "FunctionName", "Value": "{}".format(self.lambda_name)}], |
| 1742 | )["Datapoints"][0]["Sum"] |
| 1743 | except Exception: |
| 1744 | function_invocations = 0 |