aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

AttributeError in intrinsics_symbol_table.py #1396

Open daveykane opened 5 years ago

daveykane commented 5 years ago

Description

Trying to run the command sam local start-api and get an error.

Observed result

Traceback (most recent call last):
  File "/usr/local/bin/sam", line 11, in <module>
    load_entry_point('aws-sam-cli==0.21.0', 'console_scripts', 'sam')()
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/telemetry/metrics.py", line 51, in wrapped
    return func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/commands/local/start_api/cli.py", line 60, in cli
    parameter_overrides)  # pragma: no cover
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/commands/local/start_api/cli.py", line 90, in do_cli
    aws_profile=ctx.profile) as invoke_context:
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/commands/local/cli_common/invoke_context.py", line 133, in __enter__
    self._function_provider = SamFunctionProvider(self._template_dict, self.parameter_overrides)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/commands/local/lib/sam_function_provider.py", line 46, in __init__
    self.template_dict = SamBaseProvider.get_template(template_dict, parameter_overrides)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/commands/local/lib/sam_base_provider.py", line 53, in get_template
    template_dict = resolver.resolve_template(ignore_errors=True)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 240, in resolve_template
    processed_template["Resources"] = self.resolve_attribute(self._resources, ignore_errors)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 265, in resolve_attribute
    processed_resource = self.intrinsic_property_resolver(val, parent_function=processed_key)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 220, in intrinsic_property_resolver
    sanitized_val = self.intrinsic_property_resolver(val, parent_function=parent_function)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 220, in intrinsic_property_resolver
    sanitized_val = self.intrinsic_property_resolver(val, parent_function=parent_function)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 199, in intrinsic_property_resolver
    return [self.intrinsic_property_resolver(item) for item in intrinsic]
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 199, in <listcomp>
    return [self.intrinsic_property_resolver(item) for item in intrinsic]
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 220, in intrinsic_property_resolver
    sanitized_val = self.intrinsic_property_resolver(val, parent_function=parent_function)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 220, in intrinsic_property_resolver
    sanitized_val = self.intrinsic_property_resolver(val, parent_function=parent_function)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 199, in intrinsic_property_resolver
    return [self.intrinsic_property_resolver(item) for item in intrinsic]
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 199, in <listcomp>
    return [self.intrinsic_property_resolver(item) for item in intrinsic]
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 220, in intrinsic_property_resolver
    sanitized_val = self.intrinsic_property_resolver(val, parent_function=parent_function)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 199, in intrinsic_property_resolver
    return [self.intrinsic_property_resolver(item) for item in intrinsic]
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 199, in <listcomp>
    return [self.intrinsic_property_resolver(item) for item in intrinsic]
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 213, in intrinsic_property_resolver
    return self.conditional_key_function_map.get(key)(intrinsic_value)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 753, in handle_fn_if
    intrinsic_value, parent_function=IntrinsicResolver.FN_IF
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 199, in intrinsic_property_resolver
    return [self.intrinsic_property_resolver(item) for item in intrinsic]
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 199, in <listcomp>
    return [self.intrinsic_property_resolver(item) for item in intrinsic]
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 210, in intrinsic_property_resolver
    return self.intrinsic_key_function_map.get(key)(intrinsic_value)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 659, in handle_fn_ref
    return self._symbol_resolver.resolve_symbols(arguments, IntrinsicResolver.REF)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py", line 217, in resolve_symbols
    translated = self.get_translation(logical_id, resource_attribute)
  File "/usr/local/Cellar/aws-sam-cli/0.21.0/libexec/lib/python3.7/site-packages/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py", line 323, in get_translation
    return logical_id_item.get(resource_attributes)
AttributeError: 'NoneType' object has no attribute 'get'

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: OSX 10.14.6
  2. sam --version: SAM CLI, version 0.21.0
  3. AWS CLI: aws-cli/1.16.230 Python/3.7.4 Darwin/18.7.0 botocore/1.12.220
  4. Node: v10.16.3
daveykane commented 5 years ago

The errors disappear if a rollback to v0.19.0.

It looks like there is a possible clash with cfn-include - if I remove this pre-compiler for the time being the errors disappear.

Now getting "Unable to process properties of ..." on a number of functions.

sriram-mv commented 5 years ago

@daveykane what does your template look like? Looks like a Ref is failing to resolve? from the stack trace?

daveykane commented 5 years ago

@TheSriram It's a very big template so I won't paste it all here but looking at the stack trace I see the handle_fn_ref happens after the handle_fn_if and the only Ref in my template that is part of an Fn::If condition is - Ref: 'AWS::NoValue'

daveykane commented 5 years ago

@TheSriram I've narrowed it down to this one Action on a Role Policy:

- Action:
    - 'cognito-idp:describeResourceServer'
    - 'cognito-idp:UpdateUserPoolClient'
  Effect: Allow
  Resource:
    - 'Fn::If':
      - Debugging
        - 'Fn::GetAtt':
          - AcmeUserPool
          - Arn
        - Ref: 'AWS::NoValue'

If I replace Ref: 'AWS::NoValue' with a Ref to something else the errors disappear.

rlister commented 5 years ago

Can confirm I have the same problem with 0.21.0 on templates with a ref to AWS::NoValue within a Fn::If statement.