Skip to content

Commit

Permalink
add lambda versions to status
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Jones committed Jul 28, 2016
1 parent b90c43d commit d6a06f2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
20 changes: 15 additions & 5 deletions zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,21 @@ def status(self):
Describe the status of the current deployment.
"""

print("Status for %s:" % self.lambda_name)

lambda_versions = self.zappa.get_lambda_function_versions(self.lambda_name)
if not lambda_versions:
print("\tNo Lambda detected - have you deployed yet?")
else:
print('\tLambda Versions:\t\t' + str(len(lambda_versions)))

api_url = self.zappa.get_api_url(
self.lambda_name,
self.api_stage)
print('\tAPI Gateway URL:\t' + str(api_url))

domain_url = self.zappa_settings[self.api_stage].get('domain', None)

print("Status for %s:" % self.lambda_name)
print('\tAPI Gateway URL:\t' + str(api_url))
print('\tDomain URL:\t\t' + str(domain_url))
print('\tDomain URL:\t\t' + str(domain_url))

def print_version(self):
"""
Expand All @@ -433,6 +439,10 @@ def print_version(self):
def init(self, settings_file="zappa_settings.json"):
"""
Initialize a new Zappa project by creating a new zappa_settings.json in a guided process.
This should probably be broken up into few separate componants once it's stable.
Testing these raw_inputs requires monkeypatching with mock, which isn't pretty.
"""

# Ensure that we don't already have a zappa_settings file.
Expand Down Expand Up @@ -571,7 +581,7 @@ def detect_django_settings():
print("\t$ zappa update %s" % env)

print("\nTo learn more, check out the Zappa project page on GitHub: https://github.com/Miserlou/Zappa")
print("or stop by our Slack channel: https://slackautoinviter.herokuapp.com/")
print("or stop by our Slack channel: http://bit.do/zappa")
print("\nEnjoy!")

return
Expand Down
44 changes: 28 additions & 16 deletions zappa/zappa.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,17 @@ def rollback_lambda_function_version(self, function_name, versions_back=1, publi

return response['FunctionArn']

def get_lambda_function_versions(self, function_name):
"""
Simply returns the versions available for a Lambda function, given a function name.
"""
try:
response = self.lambda_client.list_versions_by_function(FunctionName=function_name)
return response
except Exception as e:
return []

def delete_lambda_function(self, function_name):
"""
Given a function name, delete it from AWS Lambda.
Expand Down Expand Up @@ -739,22 +750,6 @@ def create_and_setup_methods(self, api_id, resource_id, lambda_arn, report_progr

return resource_id

@staticmethod
def selection_pattern(status_code):
"""
Generate a regex to match a given status code in a response.
"""

pattern = ''

if status_code in ['301', '302']:
pattern = 'https://.*|/.*'
elif status_code != '200':
pattern = base64.b64encode("<!DOCTYPE html>" + str(status_code)) + '.*'
pattern = pattern.replace('+', r"\+")

return pattern

def deploy_api_gateway(self, api_id, stage_name, stage_description="", description="", cache_cluster_enabled=False, cache_cluster_size='0.5', variables=None):
"""
Deploy the API Gateway!
Expand Down Expand Up @@ -1106,6 +1101,23 @@ def load_credentials(self, boto_session=None, profile_name=None):
if self.boto_session.region_name not in API_GATEWAY_REGIONS:
print("Warning! AWS API Gateway may not be available in this AWS Region!")


@staticmethod
def selection_pattern(status_code):
"""
Generate a regex to match a given status code in a response.
"""

pattern = ''

if status_code in ['301', '302']:
pattern = 'https://.*|/.*'
elif status_code != '200':
pattern = base64.b64encode("<!DOCTYPE html>" + str(status_code)) + '.*'
pattern = pattern.replace('+', r"\+")

return pattern

def human_size(self, num, suffix='B'):
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
if abs(num) < 1024.0:
Expand Down

0 comments on commit d6a06f2

Please sign in to comment.