[lambda] Use S3Key to figure out code size and SHA256
This commit is contained in:
parent
b8d8844286
commit
8f586d8637
@ -52,8 +52,8 @@ class LambdaFunction(object):
|
|||||||
"InvalidParameterValueException",
|
"InvalidParameterValueException",
|
||||||
"Error occurred while GetObject. S3 Error Code: NoSuchKey. S3 Error Message: The specified key does not exist.")
|
"Error occurred while GetObject. S3 Error Code: NoSuchKey. S3 Error Message: The specified key does not exist.")
|
||||||
else:
|
else:
|
||||||
self.code_size = 123
|
self.code_size = key.size
|
||||||
self.code_sha_256 = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
|
self.code_sha_256 = hashlib.sha256(key.value).hexdigest()
|
||||||
self.function_arn = 'arn:aws:lambda:123456789012:function:{0}'.format(self.function_name)
|
self.function_arn = 'arn:aws:lambda:123456789012:function:{0}'.format(self.function_name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -63,7 +63,9 @@ def test_create_based_on_s3_with_missing_bucket():
|
|||||||
def test_create_function_from_aws_bucket():
|
def test_create_function_from_aws_bucket():
|
||||||
s3_conn = boto3.client('s3', 'us-west-2')
|
s3_conn = boto3.client('s3', 'us-west-2')
|
||||||
s3_conn.create_bucket(Bucket='test-bucket')
|
s3_conn.create_bucket(Bucket='test-bucket')
|
||||||
s3_conn.put_object(Bucket='test-bucket', Key='test.zip', Body=get_test_zip_file())
|
|
||||||
|
zip_content = get_test_zip_file()
|
||||||
|
s3_conn.put_object(Bucket='test-bucket', Key='test.zip', Body=zip_content)
|
||||||
conn = boto3.client('lambda', 'us-west-2')
|
conn = boto3.client('lambda', 'us-west-2')
|
||||||
|
|
||||||
result = conn.create_function(
|
result = conn.create_function(
|
||||||
@ -90,12 +92,12 @@ def test_create_function_from_aws_bucket():
|
|||||||
'Runtime': 'python2.7',
|
'Runtime': 'python2.7',
|
||||||
'Role': 'test-iam-role',
|
'Role': 'test-iam-role',
|
||||||
'Handler': 'lambda_function.handler',
|
'Handler': 'lambda_function.handler',
|
||||||
'CodeSize': 123,
|
"CodeSha256": hashlib.sha256(zip_content).hexdigest(),
|
||||||
|
"CodeSize": len(zip_content),
|
||||||
'Description': 'test lambda function',
|
'Description': 'test lambda function',
|
||||||
'Timeout': 3,
|
'Timeout': 3,
|
||||||
'MemorySize': 128,
|
'MemorySize': 128,
|
||||||
'LastModified': '2015-01-01 00:00:00',
|
'LastModified': '2015-01-01 00:00:00',
|
||||||
'CodeSha256': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
|
||||||
'Version': '$LATEST',
|
'Version': '$LATEST',
|
||||||
'VpcConfig': {
|
'VpcConfig': {
|
||||||
"SecurityGroupIds": ["sg-123abc"],
|
"SecurityGroupIds": ["sg-123abc"],
|
||||||
@ -154,7 +156,9 @@ def test_create_function_from_zipfile():
|
|||||||
def test_get_function():
|
def test_get_function():
|
||||||
s3_conn = boto3.client('s3', 'us-west-2')
|
s3_conn = boto3.client('s3', 'us-west-2')
|
||||||
s3_conn.create_bucket(Bucket='test-bucket')
|
s3_conn.create_bucket(Bucket='test-bucket')
|
||||||
s3_conn.put_object(Bucket='test-bucket', Key='test.zip', Body=get_test_zip_file())
|
|
||||||
|
zip_content = get_test_zip_file()
|
||||||
|
s3_conn.put_object(Bucket='test-bucket', Key='test.zip', Body=zip_content)
|
||||||
conn = boto3.client('lambda', 'us-west-2')
|
conn = boto3.client('lambda', 'us-west-2')
|
||||||
|
|
||||||
conn.create_function(
|
conn.create_function(
|
||||||
@ -180,8 +184,8 @@ def test_get_function():
|
|||||||
"RepositoryType": "S3"
|
"RepositoryType": "S3"
|
||||||
},
|
},
|
||||||
"Configuration": {
|
"Configuration": {
|
||||||
"CodeSha256": 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
"CodeSha256": hashlib.sha256(zip_content).hexdigest(),
|
||||||
"CodeSize": 123,
|
"CodeSize": len(zip_content),
|
||||||
"Description": "test lambda function",
|
"Description": "test lambda function",
|
||||||
"FunctionArn": "arn:aws:lambda:123456789012:function:testFunction",
|
"FunctionArn": "arn:aws:lambda:123456789012:function:testFunction",
|
||||||
"FunctionName": "testFunction",
|
"FunctionName": "testFunction",
|
||||||
@ -207,7 +211,9 @@ def test_get_function():
|
|||||||
def test_delete_function():
|
def test_delete_function():
|
||||||
s3_conn = boto3.client('s3', 'us-west-2')
|
s3_conn = boto3.client('s3', 'us-west-2')
|
||||||
s3_conn.create_bucket(Bucket='test-bucket')
|
s3_conn.create_bucket(Bucket='test-bucket')
|
||||||
s3_conn.put_object(Bucket='test-bucket', Key='test.zip', Body=get_test_zip_file())
|
|
||||||
|
zip_content = get_test_zip_file()
|
||||||
|
s3_conn.put_object(Bucket='test-bucket', Key='test.zip', Body=zip_content)
|
||||||
conn = boto3.client('lambda', 'us-west-2')
|
conn = boto3.client('lambda', 'us-west-2')
|
||||||
|
|
||||||
conn.create_function(
|
conn.create_function(
|
||||||
@ -241,7 +247,9 @@ def test_list_create_list_get_delete_list():
|
|||||||
"""
|
"""
|
||||||
s3_conn = boto3.client('s3', 'us-west-2')
|
s3_conn = boto3.client('s3', 'us-west-2')
|
||||||
s3_conn.create_bucket(Bucket='test-bucket')
|
s3_conn.create_bucket(Bucket='test-bucket')
|
||||||
s3_conn.put_object(Bucket='test-bucket', Key='test.zip', Body=get_test_zip_file())
|
|
||||||
|
zip_content = get_test_zip_file()
|
||||||
|
s3_conn.put_object(Bucket='test-bucket', Key='test.zip', Body=zip_content)
|
||||||
conn = boto3.client('lambda', 'us-west-2')
|
conn = boto3.client('lambda', 'us-west-2')
|
||||||
|
|
||||||
conn.list_functions()['Functions'].should.have.length_of(0)
|
conn.list_functions()['Functions'].should.have.length_of(0)
|
||||||
@ -266,8 +274,8 @@ def test_list_create_list_get_delete_list():
|
|||||||
"RepositoryType": "S3"
|
"RepositoryType": "S3"
|
||||||
},
|
},
|
||||||
"Configuration": {
|
"Configuration": {
|
||||||
"CodeSha256": 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
"CodeSha256": hashlib.sha256(zip_content).hexdigest(),
|
||||||
"CodeSize": 123,
|
"CodeSize": len(zip_content),
|
||||||
"Description": "test lambda function",
|
"Description": "test lambda function",
|
||||||
"FunctionArn": "arn:aws:lambda:123456789012:function:testFunction",
|
"FunctionArn": "arn:aws:lambda:123456789012:function:testFunction",
|
||||||
"FunctionName": "testFunction",
|
"FunctionName": "testFunction",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user