Skip to content

sam build --debug fails with a Serverless::LayerVersion #2666

@ppena-LiveData

Description

@ppena-LiveData

Description:

When I ran sam build --debug for a template.yaml with a Serverless::LayerVersion, it showed this error (along with other, non-important details) then failed to build:

--- Logging error ---
Traceback (most recent call last):
  File "/var/lang/lib/python3.8/logging/__init__.py", line 1081, in emit
    msg = self.format(record)
  File "/var/lang/lib/python3.8/logging/__init__.py", line 925, in format
    return fmt.format(record)
  File "/var/lang/lib/python3.8/logging/__init__.py", line 664, in format
    record.message = record.getMessage()
  File "/var/lang/lib/python3.8/logging/__init__.py", line 369, in getMessage
    msg = msg % self.args
  File "/var/lang/lib/python3.8/site-packages/samcli/lib/build/build_graph.py", line 353, in __str__
    f"LayerBuildDefinition({self.name}, {self.codeuri}, {self.source_md5}, {self.uuid}, "
AttributeError: 'NoneType' object has no attribute 'name'

Steps to reproduce:

  1. sam init and choose the following:
  • 1 - AWS Quick Start Templates
  • 1 - Zip
  • 2 - python3.8
  • 1 - Hello World Example
  1. Edit template.yaml to add this to the Properties of HelloWorldFunction:
      Layers:
        - !Ref MyLayer
  1. Add this to template.yaml:
  MyLayer:
    Type: AWS::Serverless::LayerVersion
    Properties:
      LayerName: test-layer
      ContentUri: my_layer
      CompatibleRuntimes:
        - python3.8
    Metadata:
      BuildMethod: python3.8

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

  1. OS: Windows 10 and Linux
  2. sam --version: SAM CLI, version 1.18.2 and 1.19.1 and 1.20.0

Proposed fix

It appears the problem is that LayerBuildDefinition.__str__() tries to print self.layer.name, but self.layer is None, so I just changed self.layer.name in the f string to this: self.layer.name if self.layer else None

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions