Skip to content

sam validate may break when combined with other transforms #1572

Open
@gdw2

Description

@gdw2

Description

I'm running two transforms on my template, a custom transform and AWS::Serverless. My first transform leverages syntax that breaks sam validation. While I don't necessarily expect sam to validate unordinary syntax, I would expect a way to bypass validation when running sam package. I supposed I may be able to deploy a template with the sam transform, but without using the sam cli.

Steps to reproduce

Run 'sam validate' on the following simplified template. Sam does not like resources composed of lists. This may not be valid sam template now, but it is after transformation.

AWSTemplateFormatVersion: "2010-09-09"
Transform: ['InlineJS-1_0', 'AWS::Serverless-2016-10-31']

Resources:
  'Test':
    - Name: Test1                                                                                                                                                                                                                                                                 - Name: Test2

Observed result

$ sam validate --debug --profile gwarner7 --region us-west-2 --template /home/gwarner/code/bep/modules/lono-inline/examples/greg-loop-js2.yaml
Using SAM Template at /home/gwarner/code/bep/modules/lono-inline/examples/greg-loop-js2.yaml
Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2019-11-21 20:59:27 Found credentials in shared credentials file: ~/.aws/credentials
Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': True, 'debugFlagProvided': True, 'region': 'us-west-2', 'commandName': 'sam validate', 'duration': 1945, 'exitReason': 'AttributeError', 'exitCode': 255, 'requestId': 'b0f95160-41bb-4873-8732-a273b358843b', 'installationId': 'bed69871-b653-4c4f-97b2-27b52db02413', 'sessionId': '47aea76c-e669-4a7b-944e-4f385ea87235', 'executionEnvironment': 'CLI', 'pyversion': '3.7.3', 'samcliVersion': '0.31.1'}}]}
Telemetry response: 200
Traceback (most recent call last):
  File "/home/gwarner/.pyenv/versions/greg-sam/bin/sam", line 10, in <module>
    sys.exit(cli())
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/samcli/lib/telemetry/metrics.py", line 93, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/samcli/lib/telemetry/metrics.py", line 62, in wrapped
    return_value = func(*args, **kwargs)
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/samcli/commands/validate/validate.py", line 25, in cli
    do_cli(ctx, template)  # pragma: no cover
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/samcli/commands/validate/validate.py", line 45, in do_cli
    validator.is_valid()
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/samcli/commands/validate/lib/sam_template_validator.py", line 57, in is_valid
    self._replace_local_codeuri()
  File "/home/gwarner/.pyenv/versions/3.7.3/envs/greg-sam/lib/python3.7/site-packages/samcli/commands/validate/lib/sam_template_validator.py", line 85, in _replace_local_codeuri
    resource_type = resource.get("Type")
AttributeError: 'list' object has no attribute 'get'

Expected result

Template to validate.

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

  1. OS: Linux
  2. sam --version:
    SAM CLI, version 0.31.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions