Skip to content

Release 1.38.1 breaks sam validate of template files that use CF function in Fn::Transform #3676

@fsmed

Description

@fsmed

Description:

Recently upgraded to 1.38.1 from 1.37.0, after that our sam validate stopped working on our template file.

Steps to reproduce:

Define a serverless api that uses transform on an openapi file with a CF function to define the Location of the file. Using "!Ref parameter" also fails, only thing that works is a String.

  RestApiGw:
    Type: AWS::Serverless::Api
    Properties:
      DefinitionBody: # Workaround to pass CF variables to openapi.yaml; need to upload file to S3 first
        Fn::Transform:
          Name: "AWS::Include"
          Parameters:
            Location: !Join ["", ["s3://", !Ref ArtifactsPath, "/openapi.yaml"]]

This syntax is taken from this link: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/create-reusable-transform-function-snippets-and-add-to-your-template-with-aws-include-transform.html
Under "Syntax when the transform is embedded within a section of a template".

Observed result:

$ sam validate --template template.yaml --debug
2022-02-22 16:19:11,960 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-02-22 16:19:11,960 | Using config file: samconfig.toml, config environment: default
2022-02-22 16:19:11,960 | Expand command line arguments to:
2022-02-22 16:19:11,961 | --template_file=template.yaml
2022-02-22 16:19:12 Loading policies from IAM...
2022-02-22 16:19:16 Finished loading policies from IAM.
2022-02-22 16:19:16,061 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'cd8cddfa-c1c2-48c3-904f-99e99682cdf0', 'installationId': '187e0294-1f4f-495f-ae97-c06d2e6ed5e1', 'sessionId': '2ba23f04-954d-4764-af4d-3c8c2b5b50eb', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.12', 'samcliVersion': '1.38.1', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam validate', 'metricSpecificAttributes': {'projectType': 'CFN'}, 'duration': 4100, 'exitReason': 'TypeError', 'exitCode': 255}}]}
2022-02-22 16:19:16,702 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Traceback (most recent call last):
  File "/usr/local/bin/sam", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 166, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 124, in wrapped
    return_value = func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py", line 41, in wrapped
    actual_result = func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 87, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/samcli/commands/_utils/cdk_support_decorators.py", line 38, in wrapped
    return func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/samcli/commands/validate/validate.py", line 39, in cli
    do_cli(ctx, template_file)  # pragma: no cover
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/samcli/commands/validate/validate.py", line 61, in do_cli
    validator.is_valid()
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/samcli/commands/validate/lib/sam_template_validator.py", line 69, in is_valid
    self._replace_local_openapi()
  File "/usr/local/Cellar/aws-sam-cli/1.38.1/libexec/lib/python3.8/site-packages/samcli/commands/validate/lib/sam_template_validator.py", line 165, in _replace_local_openapi
    if not Path(location_prop).is_file():
  File "/usr/local/Cellar/python@3.8/3.8.12_1/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pathlib.py", line 1042, in __new__
    self = cls._from_parts(args, init=False)
  File "/usr/local/Cellar/python@3.8/3.8.12_1/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pathlib.py", line 683, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/usr/local/Cellar/python@3.8/3.8.12_1/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pathlib.py", line 667, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not dict
2022-02-22 16:19:16 There are unpublished metrics. Please make sure you call publish after you record all metrics.

Expected result:

That it validates the file without issues as the file validate successfully in previous release.

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

  1. OS: MacOS 12.1
  2. sam --version: 1.38.1
  3. AWS region: eu-west-1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions