aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

AttributeError: 'NoneType' object has no attribute 'items' on malformed CloudFormation

Open jghaines opened this issue 9 years ago • 13 comments

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'

jghaines avatar Dec 04 '16 05:12 jghaines

Makes sense. We will look into improving the error message on malformed cloudformation templates.

kyleknap avatar Dec 16 '16 22:12 kyleknap

Had a similar error message when I left a resource without anything in it.

'NoneType' object has no attribute 'get'

Nalha avatar Feb 20 '17 09:02 Nalha

Had the same problem:

'NoneType' object has no attribute 'items'

Resolution was to fix indentation on a resource. Thanks for the help!

concon121 avatar Aug 24 '17 14:08 concon121

Same here, it would be nice with a better error message.

ciryon avatar Apr 02 '19 10:04 ciryon

Please fix the error, its very misleading

suhaibchishti avatar Apr 11 '19 20:04 suhaibchishti

Just received the same error.

devpramod avatar Dec 11 '20 17:12 devpramod

Running sam validate will produce better error messages if the problem is with your template file.

In my case, misspelled "Properties"

bravodavid56 avatar Feb 05 '21 02:02 bravodavid56

Was this fixed? Still getting the same error. 'NoneType' object has no attribute 'get' How do I get a better error message?

OrinaOisera avatar Jan 23 '22 08:01 OrinaOisera

@OrinaOisera most likely issue in the template (indentation, wrong parameter types) --debug flag may help in finding the issue.

ashokpokharel977 avatar Feb 28 '22 08:02 ashokpokharel977

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

idwessough avatar Nov 21 '22 14:11 idwessough

I would like to work on this and submit the PR later

mrkharvi01 avatar Jun 23 '23 06:06 mrkharvi01

+1 just ran into this error, should be malformed template with the problematic resource / line number

jacov avatar Jul 31 '23 14:07 jacov

2024 and the ticket is still open and causing headaches for people

ethanhsnapper avatar Sep 11 '24 05:09 ethanhsnapper