Skip to content

Commit

Permalink
Add lambda ZipFile property
Browse files Browse the repository at this point in the history
  • Loading branch information
benbridts committed Aug 25, 2015
1 parent c48dd96 commit 35d6666
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
26 changes: 25 additions & 1 deletion tests/test_awslambda.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from troposphere import GetAtt, Template
from troposphere import GetAtt, Template, Join
from troposphere.awslambda import Code, Function


Expand All @@ -20,5 +20,29 @@ def test_exclusive(self):
t.add_resource(lambda_func)
t.to_json()

def test_zip_file(self):
lambda_func = Function(
"AMIIDLookup",
Handler="index.handler",
Role=GetAtt("LambdaExecutionRole", "Arn"),
Code=Code(
ZipFile=Join("", [
"var response = require('cfn-response');",
"exports.handler = function(event, context) {",
" var input = parseInt(event.ResourceProperties.Input);",
" var responseData = {Value: input * 5};",
" response.send("
" event, context, response.SUCCESS, responseData"
" );",
"};"
]),
),
Runtime="nodejs",
Timeout="25",
)
t = Template()
t.add_resource(lambda_func)
t.to_json()

if __name__ == '__main__':
unittest.main()
28 changes: 26 additions & 2 deletions troposphere/awslambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,35 @@

class Code(AWSProperty):
props = {
'S3Bucket': (basestring, True),
'S3Key': (basestring, True),
'S3Bucket': (basestring, False),
'S3Key': (basestring, False),
'S3ObjectVersion': (basestring, False),
'ZipFile': (basestring, False)
}

def __init__(self, title=None, **kwargs):
super(Code, self).__init__(title, **kwargs)

if 'ZipFile' in kwargs:
if 'S3Bucket' in kwargs:
raise ValueError(
"You can't specify both 'S3Bucket' and 'ZipFile'"
)
elif 'S3Key' in kwargs:
raise ValueError(
"You can't specify both 'S3Key' and 'ZipFile'"
)
elif 'S3ObjectVersion' in kwargs:
raise ValueError(
"You can't specify both 'S3ObjectVersion' and 'ZipFile'"
)
else: # ZipFile not specified
if 'S3Bucket' not in kwargs or 'S3Key' not in kwargs:
raise ValueError(
'You must specify a bucket location (both the S3Bucket '
'and S3Key properties) or the ZipFile property'
)


class Function(AWSObject):
resource_type = "AWS::Lambda::Function"
Expand Down

0 comments on commit 35d6666

Please sign in to comment.