lambda correct documentation of return output

The returns are actually nested under `configuration` keys, so the docs
need to reflect that. Also add the automatic return of the function
version, so it can be used to feed the `lambda_alias` module.
This commit is contained in:
Ryan S. Brown 2016-10-07 14:50:07 -04:00 committed by Matt Clay
parent b7ca9d6567
commit 001cf5cfc5

View file

@ -139,19 +139,25 @@ output:
returned: success returned: success
type: dict type: dict
sample: sample:
'code':
{ {
'FunctionName': 'string', 'location': 'an S3 URL',
'FunctionArn': 'string', 'repository_type': 'S3',
'Runtime': 'nodejs', }
'Role': 'string', 'configuration':
'Handler': 'string', {
'CodeSize': 123, 'function_name': 'string',
'Description': 'string', 'function_arn': 'string',
'Timeout': 123, 'runtime': 'nodejs',
'MemorySize': 123, 'role': 'string',
'LastModified': 'string', 'handler': 'string',
'CodeSha256': 'string', 'code_size': 123,
'Version': 'string', 'description': 'string',
'timeout': 123,
'memory_size': 123,
'last_modified': 'string',
'code_sha256': 'string',
'version': 'string',
} }
''' '''
@ -172,11 +178,14 @@ except ImportError:
HAS_BOTO3 = False HAS_BOTO3 = False
def get_current_function(connection, function_name): def get_current_function(connection, function_name, qualifier=None):
try: try:
if qualifier is not None:
return connection.get_function(FunctionName=function_name,
Qualifier=qualifier)
return connection.get_function(FunctionName=function_name) return connection.get_function(FunctionName=function_name)
except botocore.exceptions.ClientError as e: except botocore.exceptions.ClientError:
return False return None
def sha256sum(filename): def sha256sum(filename):
@ -277,9 +286,10 @@ def main():
# Get current state # Get current state
current_config = current_function['Configuration'] current_config = current_function['Configuration']
current_version = None
# Update function configuration # Update function configuration
func_kwargs = {'FunctionName': name} func_kwargs = {'FunctionName': name, 'Publish': True}
# Update configuration if needed # Update configuration if needed
if role_arn and current_config['Role'] != role_arn: if role_arn and current_config['Role'] != role_arn:
@ -324,16 +334,17 @@ def main():
func_kwargs.update({'VpcConfig':{'SubnetIds': [], 'SecurityGroupIds': []}}) func_kwargs.update({'VpcConfig':{'SubnetIds': [], 'SecurityGroupIds': []}})
# Upload new configuration if configuration has changed # Upload new configuration if configuration has changed
if len(func_kwargs) > 1: if len(func_kwargs) > 2:
try: try:
if not check_mode: if not check_mode:
client.update_function_configuration(**func_kwargs) response = client.update_function_configuration(**func_kwargs)
current_version = response['Version']
changed = True changed = True
except (botocore.exceptions.ParamValidationError, botocore.exceptions.ClientError) as e: except (botocore.exceptions.ParamValidationError, botocore.exceptions.ClientError) as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
# Update code configuration # Update code configuration
code_kwargs = {'FunctionName': name} code_kwargs = {'FunctionName': name, 'Publish': True}
# Update S3 location # Update S3 location
if s3_bucket and s3_key: if s3_bucket and s3_key:
@ -359,21 +370,22 @@ def main():
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
# Upload new code if needed (e.g. code checksum has changed) # Upload new code if needed (e.g. code checksum has changed)
if len(code_kwargs) > 1: if len(code_kwargs) > 2:
try: try:
if not check_mode: if not check_mode:
client.update_function_code(**code_kwargs) response = client.update_function_code(**code_kwargs)
current_version = response['Version']
changed = True changed = True
except (botocore.exceptions.ParamValidationError, botocore.exceptions.ClientError) as e: except (botocore.exceptions.ParamValidationError, botocore.exceptions.ClientError) as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
# Describe function code and configuration # Describe function code and configuration
response = get_current_function(client, name) response = get_current_function(client, name, qualifier=current_version)
if not response: if not response:
module.fail_json(msg='Unable to get function information after updating') module.fail_json(msg='Unable to get function information after updating')
# We're done # We're done
module.exit_json(changed=changed, result=camel_dict_to_snake_dict(response)) module.exit_json(changed=changed, **camel_dict_to_snake_dict(response))
# Function doesn't exists, create new Lambda function # Function doesn't exists, create new Lambda function
elif state == 'present': elif state == 'present':
@ -398,6 +410,7 @@ def main():
func_kwargs = {'FunctionName': name, func_kwargs = {'FunctionName': name,
'Description': description, 'Description': description,
'Publish': True,
'Runtime': runtime, 'Runtime': runtime,
'Role': role_arn, 'Role': role_arn,
'Handler': handler, 'Handler': handler,
@ -421,11 +434,15 @@ def main():
try: try:
if not check_mode: if not check_mode:
response = client.create_function(**func_kwargs) response = client.create_function(**func_kwargs)
current_version = response['Version']
changed = True changed = True
except (botocore.exceptions.ParamValidationError, botocore.exceptions.ClientError) as e: except (botocore.exceptions.ParamValidationError, botocore.exceptions.ClientError) as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
module.exit_json(changed=changed, result=camel_dict_to_snake_dict(response)) response = get_current_function(client, name, qualifier=current_version)
if not response:
module.fail_json(msg='Unable to get function information after creating')
module.exit_json(changed=changed, **camel_dict_to_snake_dict(response))
# Delete existing Lambda function # Delete existing Lambda function
if state == 'absent' and current_function: if state == 'absent' and current_function:
@ -446,4 +463,5 @@ def main():
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import * from ansible.module_utils.ec2 import *
main() if __name__ == '__main__':
main()