106106 - A list of layers used by the Lambda function.
107107 type: list
108108 elements: str
109+ log_format:
110+ description:
111+ - The format of the Lambda function logs sent to CloudWatch.
112+ type: str
113+ default: Text
114+ choices:
115+ - JSON
116+ - Text
117+ log_group:
118+ description:
119+ - The CloudWatch log group to send the Lambda function logs to.
120+ - If not set, the default log group named after the function will be used.
121+ type: str
122+ application_log_level:
123+ description:
124+ - The log level filter for Lambda function log messages sent to CloudWatch.
125+ - Only messages at the selected level and lower are logged, with C(fatal) being the lowest level.
126+ - Ignored when log_format is not JSON.
127+ type: str
128+ default: info
129+ choices:
130+ - trace
131+ - debug
132+ - info
133+ - warn
134+ - error
135+ - fatal
136+ system_log_level:
137+ description:
138+ - The log level filter for Lambda system log messages sent to CloudWatch.
139+ - Only messages at the selected level and lower are logged, with C(warn) being the lowest level.
140+ - Ignored when log_format is not JSON.
141+ type: str
142+ default: info
143+ choices:
144+ - debug
145+ - info
146+ - warn
147+
109148extends_documentation_fragment:
110149 - amazon.aws.common.modules
111150 - amazon.aws.region.modules
@@ -176,6 +215,10 @@ def main():
176215 preserve_environment = dict (required = False , default = False , type = 'bool' ),
177216 environment = dict (required = False , default = None , type = 'dict' ),
178217 layers = dict (required = False , default = None , type = 'list' , elements = 'str' ),
218+ log_format = dict (required = False , default = 'Text' , type = 'str' , choices = ['JSON' , 'Text' ]),
219+ log_group = dict (required = False , default = None , type = 'str' ),
220+ application_log_level = dict (required = False , default = 'info' , type = 'str' , choices = ['trace' , 'debug' , 'info' , 'warn' , 'error' , 'fatal' ]),
221+ system_log_level = dict (required = False , default = 'info' , type = 'str' , choices = ['debug' , 'info' , 'warn' ]),
179222 ))
180223
181224 module = AnsibleModule (
@@ -445,8 +488,16 @@ def make_result(self, data):
445488 memory_size = data ['MemorySize' ],
446489 environment = (data .get ('Environment' ) or {}).get ('Variables' ) or {},
447490 layers = data .get ('Layers' ),
491+ log_format = data ['LoggingConfig' ]['LogFormat' ],
492+ log_group = data ['LoggingConfig' ]['LogGroup' ],
448493 )
449494
495+ if data ['LoggingConfig' ]['LogFormat' ] == 'JSON' :
496+ result .update (
497+ application_log_level = data ['LoggingConfig' ]['ApplicationLogLevel' ].lower (),
498+ system_log_level = data ['LoggingConfig' ]['SystemLogLevel' ].lower (),
499+ )
500+
450501 if 'CodeSha256' in data :
451502 more = dict (
452503 function_arn = data ['FunctionArn' ],
@@ -472,9 +523,19 @@ def make_function_configuration(self):
472523 'MemorySize' : self .params ['memory_size' ],
473524 'Environment' : None ,
474525 'Layers' : self .params ['layers' ],
526+ 'LoggingConfig' : {
527+ 'LogFormat' : self .params ['log_format' ],
528+ 'LogGroup' : self .params ['log_group' ] or f'/aws/lambda/{ self .params ["function_name" ]} ' ,
529+ },
475530 # VpcConfig not implemented
476531 }
477532
533+ if self .params ['log_format' ] == 'JSON' :
534+ args ['LoggingConfig' ].update ({
535+ 'ApplicationLogLevel' : self .params ['application_log_level' ].upper (),
536+ 'SystemLogLevel' : self .params ['system_log_level' ].upper (),
537+ })
538+
478539 if self .params ['environment' ]:
479540 args ['Environment' ] = {
480541 'Variables' : self .params ['environment' ],
0 commit comments