AttributeError: 'NoneType' object has no attribute 'items' on malformed CloudFormation
On malformed CloudFormation, the CLI gives some pretty undecipherable output.
$ aws --version
aws-cli/1.11.24 Python/2.7.10 Darwin/16.1.0 botocore/1.4.81
In a directory containing:
ServerlessTest.zip (zip of this lambda source)
and
example.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
TestFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs4.3
Environment:
Variables:
S3_BUCKET: _my-bucket_
Note that "TestFunction" should be indented, but isn't.
I ran the following command
$ aws cloudformation package --template-file example.yaml --output-template-file serverless-output.yaml --s3-bucket _my-bucket_
This gives the unfriendly output:
'NoneType' object has no attribute 'items'
With --debug added, this is narrowed down to:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/awscli/clidriver.py", line 197, in main
return command_table[parsed_args.command](remaining, parsed_args)
File "/Library/Python/2.7/site-packages/awscli/clidriver.py", line 333, in __call__
return command_table[parsed_args.operation](remaining, parsed_globals)
File "/Library/Python/2.7/site-packages/awscli/customizations/commands.py", line 187, in __call__
return self._run_main(parsed_args, parsed_globals)
File "/Library/Python/2.7/site-packages/awscli/customizations/cloudformation/package.py", line 125, in _run_main
exported_str = self._export(template_path)
File "/Library/Python/2.7/site-packages/awscli/customizations/cloudformation/package.py", line 141, in _export
exported_template = template.export()
File "/Library/Python/2.7/site-packages/awscli/customizations/cloudformation/artifact_exporter.py", line 399, in export
for resource_id, resource in self.template_dict["Resources"].items():
AttributeError: 'NoneType' object has no attribute 'items'
2016-12-04 16:03:57,035 - MainThread - awscli.clidriver - DEBUG - Exiting with rc 255
'NoneType' object has no attribute 'items'
Makes sense. We will look into improving the error message on malformed cloudformation templates.
Had a similar error message when I left a resource without anything in it.
'NoneType' object has no attribute 'get'
Had the same problem:
'NoneType' object has no attribute 'items'
Resolution was to fix indentation on a resource. Thanks for the help!
Same here, it would be nice with a better error message.
Please fix the error, its very misleading
Just received the same error.
Running sam validate will produce better error messages if the problem is with your template file.
In my case, misspelled "Properties"
Was this fixed?
Still getting the same error. 'NoneType' object has no attribute 'get'
How do I get a better error message?
@OrinaOisera most likely issue in the template (indentation, wrong parameter types) --debug flag may help in finding the issue.
Having nearly the same issue with SAM deploy and SAM validate, just lost 1 hour of development because of this lack of precision in the error message for an indentation (really) AttributeError: 'NoneType' object has no attribute 'get' 👍 :
Traceback (most recent call last):
File "samcli/__main__.py", line 12, in <module>
File "click/core.py", line 829, in __call__
File "click/core.py", line 782, in main
File "click/core.py", line 1259, in invoke
File "click/core.py", line 1066, in invoke
File "click/core.py", line 610, in invoke
File "click/decorators.py", line 73, in new_func
File "click/core.py", line 610, in invoke
File "samcli/lib/telemetry/metric.py", line 166, in wrapped
File "samcli/lib/telemetry/metric.py", line 124, in wrapped
File "samcli/lib/utils/version_checker.py", line 41, in wrapped
File "samcli/cli/main.py", line 87, in wrapper
File "samcli/commands/_utils/cdk_support_decorators.py", line 33, in wrapped
File "samcli/lib/iac/cdk/utils.py", line 25, in is_cdk_project
File "samcli/lib/iac/cdk/utils.py", line 44, in _resource_level_metadata_exists
AttributeError: 'NoneType' object has no attribute 'get'
[8007] Failed to execute script __main__
It would be great for the leader of cloud computing to make this correction on "priority 1" level or solve it this year maybe ?
Please fix the error, its very misleading
Few years later this issue is already there
I would like to work on this and submit the PR later
+1 just ran into this error, should be malformed template with the problematic resource / line number
2024 and the ticket is still open and causing headaches for people