aws-sam-cli
aws-sam-cli copied to clipboard
SAM build is failing / panicking
Description
Sam is throwing exceptions for a template
Steps to reproduce
AWSTemplateFormatVersion: '2010-09-09'
Transform: [AWS::Serverless-2016-10-31]
Resources:
ApiGateway:
Type: AWS::Serverless::Api
Properties:
Name: api
StageName: Staging
Poller:
Type: AWS::Serverless::Function
Properties:
Runtime: python3.7
Handler: index.handler
InlineCode: |
def handler(event, context):
return {'body': 'Hello World!', 'statusCode': 200}
Events:
Api:
Type: Api
Properties:
RestApiId: !Ref ApiGateway
Path: /xyz
Method: POST
sam build
Observed result
Please provide command output with --debug flag set.
sam build --debug -t template.cfn.yaml
Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
'build' command is called
No Parameters detected in the template
2020-06-11 08:10:14 Plugin 'ServerlessAppPlugin' raised an exception: 'NoneType' object has no attribute 'get'
Traceback (most recent call last):
File "/home/jbpratt/.local/lib/python3.8/site-packages/samtranslator/plugins/__init__.py", line 133, in act
getattr(plugin, method_name)(*args, **kwargs)
File "/home/jbpratt/.local/lib/python3.8/site-packages/samtranslator/plugins/application/serverless_app_plugin.py", line 85, in on_before_transform_template
for logical_id, app in template.iterate({SamResourceType.Application.value}):
File "/home/jbpratt/.local/lib/python3.8/site-packages/samtranslator/sdk/template.py", line 33, in iterate
resource = SamResource(resource_dict)
File "/home/jbpratt/.local/lib/python3.8/site-packages/samtranslator/sdk/resource.py", line 24, in __init__
self.type = resource_dict.get("Type")
AttributeError: 'NoneType' object has no attribute 'get'
Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 14, 'exitReason': 'AttributeError', 'exitCode': 255, 'requestId': 'edc6a9c1-bfe4-4972-9f7b-7d9cbdc93ad6', 'installationId': '6a175b4b-2582-4383-a90a-915453a15582', 'sessionId': '8d6623cf-ece7-4cbf-9e67-188a04273801', 'executionEnvironment': 'CLI', 'pyversion': '3.8.3', 'samcliVersion': '0.52.0'}}]}
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 "/home/jbpratt/.local/bin/sam", line 8, in <module>
sys.exit(cli())
File "/home/jbpratt/.local/lib/python3.8/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/jbpratt/.local/lib/python3.8/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/jbpratt/.local/lib/python3.8/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/jbpratt/.local/lib/python3.8/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/jbpratt/.local/lib/python3.8/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/jbpratt/.local/lib/python3.8/site-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/jbpratt/.local/lib/python3.8/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/jbpratt/.local/lib/python3.8/site-packages/samcli/lib/telemetry/metrics.py", line 96, in wrapped
raise exception # pylint: disable=raising-bad-type
File "/home/jbpratt/.local/lib/python3.8/site-packages/samcli/lib/telemetry/metrics.py", line 62, in wrapped
return_value = func(*args, **kwargs)
File "/home/jbpratt/.local/lib/python3.8/site-packages/samcli/commands/build/command.py", line 118, in cli
do_cli(
File "/home/jbpratt/.local/lib/python3.8/site-packages/samcli/commands/build/command.py", line 168, in do_cli
with BuildContext(
File "/home/jbpratt/.local/lib/python3.8/site-packages/samcli/commands/build/build_context.py", line 62, in __enter__
self._function_provider = SamFunctionProvider(self._template_dict, self._parameter_overrides)
File "/home/jbpratt/.local/lib/python3.8/site-packages/samcli/lib/providers/sam_function_provider.py", line 40, in __init__
self.template_dict = SamFunctionProvider.get_template(template_dict, parameter_overrides)
File "/home/jbpratt/.local/lib/python3.8/site-packages/samcli/lib/providers/sam_base_provider.py", line 126, in get_template
template_dict = SamTranslatorWrapper(template_dict, parameter_values=parameters_values).run_plugins()
File "/home/jbpratt/.local/lib/python3.8/site-packages/samcli/lib/samlib/wrapper.py", line 76, in run_plugins
parser.parse(template_copy, all_plugins) # parse() will run all configured plugins
File "/home/jbpratt/.local/lib/python3.8/site-packages/samcli/lib/samlib/wrapper.py", line 131, in parse
sam_plugins.act(LifeCycleEvents.before_transform_template, sam_template)
File "/home/jbpratt/.local/lib/python3.8/site-packages/samtranslator/plugins/__init__.py", line 139, in act
raise ex
File "/home/jbpratt/.local/lib/python3.8/site-packages/samtranslator/plugins/__init__.py", line 133, in act
getattr(plugin, method_name)(*args, **kwargs)
File "/home/jbpratt/.local/lib/python3.8/site-packages/samtranslator/plugins/application/serverless_app_plugin.py", line 85, in on_before_transform_template
for logical_id, app in template.iterate({SamResourceType.Application.value}):
File "/home/jbpratt/.local/lib/python3.8/site-packages/samtranslator/sdk/template.py", line 33, in iterate
resource = SamResource(resource_dict)
File "/home/jbpratt/.local/lib/python3.8/site-packages/samtranslator/sdk/resource.py", line 24, in __init__
self.type = resource_dict.get("Type")
AttributeError: 'NoneType' object has no attribute 'get'
Expected result
Successful build
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Linux
sam --version: SAM CLI, version 0.52.0
Add --debug flag to command you are running
ApiGateway:
Type: AWS::Serverless::Api
Properties:
Name: api
StageName: Staging
Your Type and Properties are not indented - they should be a level deeper than ApiGateway.
ApiGateway: Type: AWS::Serverless::Api Properties: Name: api StageName: StagingYour
TypeandPropertiesare not indented - they should be a level deeper thanApiGateway.
whoops! thanks!