Allow lambda get function by arn and addded environment configuration
This commit is contained in:
parent
8f3116220c
commit
90a9235f4c
@ -291,6 +291,8 @@ class LambdaFunction(BaseModel):
|
|||||||
self.timeout = value
|
self.timeout = value
|
||||||
elif key == "VpcConfig":
|
elif key == "VpcConfig":
|
||||||
self.vpc_config = value
|
self.vpc_config = value
|
||||||
|
elif key == "Environment":
|
||||||
|
self.environment_vars = value["Variables"]
|
||||||
|
|
||||||
return self.get_configuration()
|
return self.get_configuration()
|
||||||
|
|
||||||
@ -589,7 +591,7 @@ class LambdaStorage(object):
|
|||||||
def _get_alias(self, name, alias):
|
def _get_alias(self, name, alias):
|
||||||
return self._functions[name]['alias'].get(alias, None)
|
return self._functions[name]['alias'].get(alias, None)
|
||||||
|
|
||||||
def get_function(self, name, qualifier=None):
|
def get_function_by_name(self, name, qualifier=None):
|
||||||
if name not in self._functions:
|
if name not in self._functions:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -612,8 +614,8 @@ class LambdaStorage(object):
|
|||||||
def get_arn(self, arn):
|
def get_arn(self, arn):
|
||||||
return self._arns.get(arn, None)
|
return self._arns.get(arn, None)
|
||||||
|
|
||||||
def get_function_by_name_or_arn(self, input):
|
def get_function_by_name_or_arn(self, input, qualifier=None):
|
||||||
return self.get_function(input) or self.get_arn(input)
|
return self.get_function_by_name(input, qualifier) or self.get_arn(input)
|
||||||
|
|
||||||
def put_function(self, fn):
|
def put_function(self, fn):
|
||||||
"""
|
"""
|
||||||
@ -671,7 +673,7 @@ class LambdaStorage(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
fn = self.get_function(name, qualifier)
|
fn = self.get_function_by_name(name, qualifier)
|
||||||
if fn:
|
if fn:
|
||||||
self._functions[name]['versions'].remove(fn)
|
self._functions[name]['versions'].remove(fn)
|
||||||
|
|
||||||
@ -766,8 +768,8 @@ class LambdaBackend(BaseBackend):
|
|||||||
def publish_function(self, function_name):
|
def publish_function(self, function_name):
|
||||||
return self._lambdas.publish_function(function_name)
|
return self._lambdas.publish_function(function_name)
|
||||||
|
|
||||||
def get_function(self, function_name, qualifier=None):
|
def get_function(self, function_name_or_arn, qualifier=None):
|
||||||
return self._lambdas.get_function(function_name, qualifier)
|
return self._lambdas.get_function_by_name_or_arn(function_name_or_arn, qualifier)
|
||||||
|
|
||||||
def list_versions_by_function(self, function_name):
|
def list_versions_by_function(self, function_name):
|
||||||
return self._lambdas.list_versions_by_function(function_name)
|
return self._lambdas.list_versions_by_function(function_name)
|
||||||
@ -877,7 +879,7 @@ class LambdaBackend(BaseBackend):
|
|||||||
]
|
]
|
||||||
|
|
||||||
}
|
}
|
||||||
func = self._lambdas.get_function(function_name, qualifier)
|
func = self._lambdas.get_function_by_name_or_arn(function_name, qualifier)
|
||||||
func.invoke(json.dumps(event), {}, {})
|
func.invoke(json.dumps(event), {}, {})
|
||||||
|
|
||||||
def send_dynamodb_items(self, function_arn, items, source):
|
def send_dynamodb_items(self, function_arn, items, source):
|
||||||
|
@ -276,7 +276,7 @@ class LambdaResponse(BaseResponse):
|
|||||||
return 404, {}, "{}"
|
return 404, {}, "{}"
|
||||||
|
|
||||||
def _get_function(self, request, full_url, headers):
|
def _get_function(self, request, full_url, headers):
|
||||||
function_name = self.path.rsplit('/', 1)[-1]
|
function_name = unquote(self.path.rsplit('/', 1)[-1])
|
||||||
qualifier = self._get_param('Qualifier', None)
|
qualifier = self._get_param('Qualifier', None)
|
||||||
|
|
||||||
fn = self.lambda_backend.get_function(function_name, qualifier)
|
fn = self.lambda_backend.get_function(function_name, qualifier)
|
||||||
|
@ -379,6 +379,7 @@ def test_get_function():
|
|||||||
Timeout=3,
|
Timeout=3,
|
||||||
MemorySize=128,
|
MemorySize=128,
|
||||||
Publish=True,
|
Publish=True,
|
||||||
|
Environment={"Variables": {"test_variable": "test_value"}}
|
||||||
)
|
)
|
||||||
|
|
||||||
result = conn.get_function(FunctionName='testFunction')
|
result = conn.get_function(FunctionName='testFunction')
|
||||||
@ -403,6 +404,9 @@ def test_get_function():
|
|||||||
result['Configuration']['Timeout'].should.equal(3)
|
result['Configuration']['Timeout'].should.equal(3)
|
||||||
result['Configuration']['Version'].should.equal('$LATEST')
|
result['Configuration']['Version'].should.equal('$LATEST')
|
||||||
result['Configuration'].should.contain('VpcConfig')
|
result['Configuration'].should.contain('VpcConfig')
|
||||||
|
result['Configuration'].should.contain('Environment')
|
||||||
|
result['Configuration']['Environment'].should.contain('Variables')
|
||||||
|
result['Configuration']['Environment']["Variables"].should.equal({"test_variable": "test_value"})
|
||||||
|
|
||||||
# Test get function with
|
# Test get function with
|
||||||
result = conn.get_function(FunctionName='testFunction', Qualifier='$LATEST')
|
result = conn.get_function(FunctionName='testFunction', Qualifier='$LATEST')
|
||||||
@ -414,6 +418,27 @@ def test_get_function():
|
|||||||
with assert_raises(ClientError):
|
with assert_raises(ClientError):
|
||||||
conn.get_function(FunctionName='junk', Qualifier='$LATEST')
|
conn.get_function(FunctionName='junk', Qualifier='$LATEST')
|
||||||
|
|
||||||
|
@mock_lambda
|
||||||
|
@mock_s3
|
||||||
|
def test_get_function_by_arn():
|
||||||
|
bucket_name = 'test-bucket'
|
||||||
|
s3_conn = boto3.client('s3', 'us-east-1')
|
||||||
|
s3_conn.create_bucket(Bucket=bucket_name)
|
||||||
|
|
||||||
|
zip_content = get_test_zip_file2()
|
||||||
|
s3_conn.put_object(Bucket=bucket_name, Key='test.zip', Body=zip_content)
|
||||||
|
conn = boto3.client('lambda', 'us-east-1')
|
||||||
|
|
||||||
|
fnc = conn.create_function(FunctionName='testFunction',
|
||||||
|
Runtime='python2.7', Role='test-iam-role',
|
||||||
|
Handler='lambda_function.lambda_handler',
|
||||||
|
Code={'S3Bucket': bucket_name, 'S3Key': 'test.zip'},
|
||||||
|
Description='test lambda function',
|
||||||
|
Timeout=3, MemorySize=128, Publish=True)
|
||||||
|
|
||||||
|
result = conn.get_function(FunctionName=fnc['FunctionArn'])
|
||||||
|
result['Configuration']['FunctionName'].should.equal('testFunction')
|
||||||
|
|
||||||
|
|
||||||
@mock_lambda
|
@mock_lambda
|
||||||
@mock_s3
|
@mock_s3
|
||||||
@ -1346,6 +1371,7 @@ def test_update_configuration():
|
|||||||
Timeout=3,
|
Timeout=3,
|
||||||
MemorySize=128,
|
MemorySize=128,
|
||||||
Publish=True,
|
Publish=True,
|
||||||
|
Environment={'Variables': {"test_old_environment": "test_old_value"}}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert fxn['Description'] == 'test lambda function'
|
assert fxn['Description'] == 'test lambda function'
|
||||||
@ -1359,7 +1385,8 @@ def test_update_configuration():
|
|||||||
Description='updated test lambda function',
|
Description='updated test lambda function',
|
||||||
Handler='lambda_function.new_lambda_handler',
|
Handler='lambda_function.new_lambda_handler',
|
||||||
Runtime='python3.6',
|
Runtime='python3.6',
|
||||||
Timeout=7
|
Timeout=7,
|
||||||
|
Environment={'Variables': {"test_environment": "test_value"}}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert updated_config['ResponseMetadata']['HTTPStatusCode'] == 200
|
assert updated_config['ResponseMetadata']['HTTPStatusCode'] == 200
|
||||||
@ -1368,6 +1395,7 @@ def test_update_configuration():
|
|||||||
assert updated_config['MemorySize'] == 128
|
assert updated_config['MemorySize'] == 128
|
||||||
assert updated_config['Runtime'] == 'python3.6'
|
assert updated_config['Runtime'] == 'python3.6'
|
||||||
assert updated_config['Timeout'] == 7
|
assert updated_config['Timeout'] == 7
|
||||||
|
assert updated_config['Environment']['Variables'] == {"test_environment": "test_value"}
|
||||||
|
|
||||||
|
|
||||||
@mock_lambda
|
@mock_lambda
|
||||||
|
Loading…
Reference in New Issue
Block a user