diff --git a/moto/awslambda/models.py b/moto/awslambda/models.py index 523393ba3..b34e3e9d4 100644 --- a/moto/awslambda/models.py +++ b/moto/awslambda/models.py @@ -111,13 +111,18 @@ class LambdaFunction(BaseModel): } def get_code(self): - return { - "Code": { - "Location": "s3://lambda-functions.aws.amazon.com/{0}".format(self.code['S3Key']), - "RepositoryType": "S3" - }, - "Configuration": self.get_configuration(), - } + if 'S3Key' in self.code: + return { + "Code": { + "Location": "s3://lambda-functions.aws.amazon.com/{0}".format(self.code['S3Key']), + "RepositoryType": "S3" + }, + "Configuration": self.get_configuration(), + } + else: + return { + "Configuration": self.get_configuration(), + } def convert(self, s): try: diff --git a/tests/test_awslambda/test_lambda.py b/tests/test_awslambda/test_lambda.py index db75cfd44..b1de685b8 100644 --- a/tests/test_awslambda/test_lambda.py +++ b/tests/test_awslambda/test_lambda.py @@ -579,3 +579,49 @@ def test_invoke_async_function(): ) success_result['Status'].should.equal(202) + +@mock_lambda +@freeze_time('2015-01-01 00:00:00') +def test_get_function_created_with_zipfile(): + conn = boto3.client('lambda', 'us-west-2') + zip_content = get_test_zip_file1() + result = conn.create_function( + FunctionName='testFunction', + Runtime='python2.7', + Role='test-iam-role', + Handler='lambda_function.handler', + Code={ + 'ZipFile': zip_content, + }, + Description='test lambda function', + Timeout=3, + MemorySize=128, + Publish=True, + ) + + response = conn.get_function( + FunctionName='testFunction' + ) + response['Configuration'].pop('LastModified') + + response['ResponseMetadata']['HTTPStatusCode'].should.equal(200) + assert 'Code' not in response + response['Configuration'].should.equal( + { + "CodeSha256": hashlib.sha256(zip_content).hexdigest(), + "CodeSize": len(zip_content), + "Description": "test lambda function", + "FunctionArn": "arn:aws:lambda:123456789012:function:testFunction", + "FunctionName": "testFunction", + "Handler": "lambda_function.handler", + "MemorySize": 128, + "Role": "test-iam-role", + "Runtime": "python2.7", + "Timeout": 3, + "Version": '$LATEST', + "VpcConfig": { + "SecurityGroupIds": [], + "SubnetIds": [], + } + }, + ) \ No newline at end of file