Skip to content

Commit

Permalink
added lambda function lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Koval committed Dec 27, 2016
1 parent 6557dcd commit 0a078c5
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Below is a table describing the currently supported AWS resource lookups and wha
| :---: | --- | --- | --- | --- | --- |
| ![](icons/cfn_stack.png)CloudFormation | Open stack in AWS console | | | | Quicklook |
| ![](icons/ec2_instance.png)<br/>EC2 | Copies _private_ IP | Open instance in AWS console | Copies _public_ IP (if available) | | Quicklook |
| ![](icons/services/lambda.png)<br/>Lambda | Open lambda in AWS console | | | | Quicklook |
| ![](icons/db_instance.png)![](icons/db_cluster.png)<br/>RDS | Copy endpoint URL | Open cluster or node in AWS Console | | | Quicklook |
| ![](icons/services/redshift.png)<br/>Redshift | Open cluster in AWS console | Copies first node's _private_ IP (if available) | Copies first node's _public_ IP (if available) | | Quicklook |
| ![](icons/s3_bucket.png)<br/>S3 | Open bucket in AWS Console | | | | Quicklook |
Expand Down
17 changes: 17 additions & 0 deletions aws_workflow/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,20 @@ def get_redshift_clusters():
break
return items


def get_lambda_functions():
client = boto3.client('lambda')
next_token = {}
items = []
while True:
log.debug('calling list_functions')
response = client.list_functions(**next_token)
for item in response['Functions']:
item['facets'] = {}
item['facets']['name'] = item['FunctionName']
items.append(item)
if 'NextMarker' in response:
next_token['NextToken'] = response['NextMarker']
else:
break
return items
5 changes: 5 additions & 0 deletions aws_workflow/aws_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ def test_get_sqs_queues():
def test_get_redshift_clusters():
clusters = get_redshift_clusters()
assert clusters


def test_get_lambda_functions():
items = get_lambda_functions()
assert items
25 changes: 25 additions & 0 deletions aws_workflow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,28 @@ def populate_menu_item(self, wf, cluster, title, uid, region_name, quicklookurl)
altmod.setvar('action', 'copy-to-clipboard,post-notification')
altmod.setvar('notification_title', 'Copied Public IP of Redshift Node')
altmod.setvar('notification_text', '%s of %s' % (public_ip, title))


class FunctionFinder(Finder):
item_identifier = 'lambda'
aws_list_function_name = 'get_lambda_functions'

def create_title(self, item):
return item['FunctionName']

def filter_items(self, wf, items, terms):
return wf.filter(' '.join(terms), items, key=lambda item: unicode(item['FunctionName']))

def populate_menu_item(self, wf, function, title, uid, region_name, quicklookurl):
url = 'https://%s.console.aws.amazon.com/lambda/home?region=%s#/functions/%s?tab=code' % (region_name, region_name, title)
item = wf.add_item(
title,
subtitle='open in AWS console (runtime: %s)' % function.get('Runtime', 'N/A'),
arg=url,
valid=True,
uid=uid,
icon='icons/services/lambda.png',
type='default',
quicklookurl=quicklookurl
)
item.setvar('action', 'open-url')
1 change: 1 addition & 0 deletions aws_workflow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ def search(quicklook_port, query, wf, profile, region):
BucketFinder(),
Ec2Finder(),
RedshiftClusterFinder(),
FunctionFinder(),
]
for finder in finders:
finder.find(wf, profile, region, terms, facets, quicklook_baseurl)
Expand Down
5 changes: 5 additions & 0 deletions quicklook_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class RedshiftClusterQuicklookHandler(BaseHandler):
template = 'redshift.html.j2'


class LambdaQuicklookHandler(BaseHandler):
template = 'lambda.html.j2'


def make_app():
return tornado.web.Application([
(r'/static/(.*)', tornado.web.StaticFileHandler, {'path': os.path.join(os.getcwd(), 'static')}),
Expand All @@ -52,6 +56,7 @@ def make_app():
(r'/quicklook/cfn', CfnQuicklookHandler),
(r'/quicklook/sqs', SqsQuicklookHandler),
(r'/quicklook/redshift', RedshiftClusterQuicklookHandler),
(r'/quicklook/lambda', LambdaQuicklookHandler),
])


Expand Down
84 changes: 84 additions & 0 deletions templates/lambda.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<html>
<head>
<title>{{ title }}</title>
<link rel="stylesheet" type="text/css" href="/static/css/main.css">
</head>
<body>
<h1>{{ title }}</h1>
<table>
<tr>
<td>Name:</td>
<td>{{ lambda.FunctionName}}</td>
</tr>
<tr>
<td>Description:</td>
<td>{{ lambda.Description }}</td>
</tr>
<tr>
<td>ARN:</td>
<td>{{ lambda.FunctionArn }}</td>
</tr>
<tr>
<td>Version:</td>
<td>{{ lambda.Version}}</td>
</tr>
<tr>
<td>Last Modified:</td>
<td>{{ lambda.LastModified }}</td>
</tr>
{% if 'Environment' in lambda and 'Error' in lambda.Environment %}
<tr>
<td>Error Status:</td>
<td>{{ lambda.Environment.Error.ErrorCode }} - {{ lambda.Environment.Error.Message }}</td>
</tr>
{% endif %}
<tr>
<td>Runtime:</td>
<td>{{ lambda.Runtime }}</td>
</tr>
<tr>
<td>Role:</td>
<td>{{ lambda.Role }}</td>
</tr>
<tr>
<td>Handler:</td>
<td>{{ lambda.Handler }}</td>
</tr>
<tr>
<td>Timeout:</td>
<td>{{ lambda.Timeout }} seconds</td>
</tr>
<tr>
<td>Memory Size:</td>
<td>{{ lambda.MemorySize }}MB</td>
</tr>
<tr>
<td>Code SHA256:</td>
<td>{{ lambda.CodeSha256 }}</td>
</tr>
<tr>
<td>MKS Key ARN:</td>
<td>{{ lambda.KMSKeyArn | default('N/A') }}</td>
</tr>
{% if 'DeadLetterConfig' in lambda %}
<tr>
<td>Dead Letter Target ARN:</td>
<td>{{ lambda.DeadLetterConfig.TargetArn | default('N/A') }}</td>
</tr>
{% endif %}
{% if 'Environment' in lambda and 'Variables' in lambda.Environment %}
<tr>
<td>Environment:</td>
<td>
<dl>
{% for key, value in lambda.Environment.Variables.items() %}
<dt>{{ key }}</dt>
<dd>{{ value }}</dd>
{% endfor %}
</dl>
</td>
</tr>
{% endif %}
</table>
</body>
</html>

0 comments on commit 0a078c5

Please sign in to comment.