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.48k stars 1.16k forks source link

Bug: `sam validate` fails to check for required metadata #4198

Open jesusaurus opened 1 year ago

jesusaurus commented 1 year ago

Description:

A template with no AWS::ServerlessRepo::Application Metadata is not a valid template, and will not publish during sam publish, but sam validate will report that the template is valid.

Steps to reproduce:

Remove or rename AWS::ServerlessRepo::Application in the template and run sam validate and sam publish.

Observed result:

Success during sam validate, failure during sam publish.

/Users/jharker/Code/lambda-ebs-cleanup/template.yaml is a valid SAM Template
2022-09-06 11:31:07,926 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '44cdd239-0a95-478e-b395-48a700229648', 'installationId': '14965899-b0af-400e-8381-df4b766b7950', 'sessionId': '9e4ffd7f-47b2-42e7-a429-52a7b036acd7', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.13', 'samcliVersion': '1.53.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam validate', 'metricSpecificAttributes': {'projectType': 'CFN'}, 'duration': 3475, 'exitReason': 'success', 'exitCode': 0}}]}
2022-09-06 11:31:08,075 | Telemetry response: 200
Publish Failed
Error: Application metadata not found in the SAM template: 'missing AWS::ServerlessRepo::Application section in template Metadata'
Please follow the instructions in https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-publishing-applications.html

Expected result:

An error message and a non-zero exit code during sam validate.

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

  1. OS: Mac
  2. sam --version: 1.53.0
  3. AWS region: us-east-1
mndeveci commented 1 year ago

Thanks for reporting this issue @jesusaurus.

This is a tricky one since you can use AWS::ServerlessRepo::Application with an app which was already published, for that case Metadata would not be required. See docs here; https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-application.html#sam-application-location

But we can still add some validation to sam validate if users defines a local path for that property. I will tag this issue as feature and let our PMs know about it.