I just found out about the Global section which seems very useful in cleaning up the template.yaml
for AWS SAM cloud formation templating. After completing the Global section I remove the Runtime from my lambda (since it should inherit Runtime from the Global section now). But once I do that I get an error.
Here is my template.yaml
:
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Global:
Function:
Handler: app.lambda_handler
Runtime: python3.8
Timeout: 900
MemorySize: 10240
VpcConfig:
SecurityGroupIds:
- !Ref SecurityGroupABC
SubnetIds:
- subnet-abc
- subnet-xyz
- subnet-rrr
Environment:
Variables:
ENV_VAR: abc123
Resources:
lambdaName:
Type: AWS::Serverless::Function
Role: 'arn:aws:iam::1234...'
#Runtime: python3.8
Properties:
CodeUri: lambda/lambdaName/
And this is the error I'm seeing after running sam build
:
File "runpy.py", line 194, in _run_module_as_main
File "runpy.py", line 87, in _run_code
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\__main__.py", line 12, in <module>
cli(prog_name="sam")
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 782, in main
rv = self.invoke(ctx)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metric.py", line 153, in wrapped
raise exception # pylint: disable=raising-bad-type
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metric.py", line 122, in wrapped
return_value = func(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\utils\version_checker.py", line 42, in wrapped
actual_result = func(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\cli\main.py", line 90, in wrapper
return func(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\build\command.py", line 210, in cli
do_cli(
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\build\command.py", line 315, in do_cli
artifacts = builder.build()
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\app_builder.py", line 139, in build
build_graph = self._get_build_graph(self._container_env_var, self._container_env_var_file)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\app_builder.py", line 206, in _get_build_graph
build_graph.clean_redundant_definitions_and_update(not self._is_building_specific_resource)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\build_graph.py", line 256, in clean_redundant_definitions_and_update
self._write()
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\build_graph.py", line 296, in _write
build_definition_as_table = _function_build_definition_to_toml_table(function_build_definition)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\build_graph.py", line 53, in _function_build_definition_to_toml_table
toml_table[RUNTIME_FIELD] = function_build_definition.runtime
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\tomlkit\items.py", line 1022, in __setitem__
value = item(value)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\tomlkit\items.py", line 107, in item
raise ValueError("Invalid type {}".format(type(value)))
ValueError: Invalid type <class 'NoneType'>
If I leave the lambda's Runtime in the its section I don't get the error. But leaving that in would defeat the purpose of establishing those global values to reduce redundancy.
In your template, Global should be renamed as Globals
Please refer to the Globals Section link that you already shared.