Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate does not return useful messages #4

Closed
ranman opened this issue Aug 9, 2017 · 4 comments
Closed

validate does not return useful messages #4

ranman opened this issue Aug 9, 2017 · 4 comments

Comments

@ranman
Copy link
Contributor

ranman commented Aug 9, 2017

Given a template:

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  VoteSpacesTabs:
    Type: "AWS::Serverless::Function"
    Properties:
      Runtime: python3.6
      Handler: lambda_function.lambda_handler
      Policies: AmazonDynamoDBFullAccess
      Environment:
        Variables:
          TABLE_NAME: !Ref VotesTable
      Events:
        Vote:
          Type: Api
          Properties:
            Path: /vote
            Method: post

Invoking:
sam validate
returns:
Valid!

Should it return valid given that we have no code-uri or other required attributes? What exactly is it validating?

Given this template:

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  VotesTable:
    Type: "AWS::Serverless::SimpleTable"
  VoteSpacesTabs:
    Type: "AWS::Serverless::Function"
    Properties:
      Runtime: python3.6
      Handler: lambda_function.lambda_handler
      Policies: AmazonDynamoDBFullAccess
      Environment:
        Variables:
          TABLE_NAME: !Ref VotesTable
      Events:
        Vote:
          Type: Api
          Properties:
            Path: /vote
            Method: post

Invoking
sam validate
Returns:
ERROR: Failed to read the resources line numbers. This usually means that the template contains invalid indentation. Please check it and try again

This error message isn't helpful in determining what's wrong. I still haven't figured out what's wrong.

However both templates are valid from the point of view of cloudformation:
aws cloudformation validate-template --template-body file://template.yaml

@PaulMaddox
Copy link
Contributor

Should it return valid given that we have no code-uri or other required attributes? What exactly is it validating?

Currently it validates against the SAM language specification - you can see this is you put Runtime: blah for example, you'll get the following validation error:

ERROR: Resource "VoteSpacesTabs", property "Runtime": Invalid value Blah. Valid values are "nodejs", "nodejs4.3", "nodejs6.10", "java8", "python2.7", "python3.6", "dotnetcore1.0", "nodejs4.3-edge" (line: 9; col: 6)

CodeUri specifically is a required parameter, but only for packaged templates. As such, it doesn't make much sense to highlight this as a hard error in a template that might still be in progress (sam validate is designed to be integrated into IDE's as a linting tool too).

ERROR: Failed to read the resources line numbers. This usually means that the template contains invalid indentation. Please check it and try again
This error message isn't helpful in determining what's wrong. I still haven't figured out what's wrong.

I dug into this and it's two problems:

  • Our SAM parser (wrongly) assumes there won't be a resource without a Properties section defined.
  • Instead of giving you a useful error, its masked by a really generic error that doesn't help.

I'm working on a fix for both.

@PaulMaddox
Copy link
Contributor

Fixed in b673757

@ranman
Copy link
Contributor Author

ranman commented Aug 10, 2017

I don't think that's the right commit.

@badfun
Copy link

badfun commented Aug 16, 2017

I'm getting the same error with a template created by CodeStar. The template works fine, but running validate returns the error.

heitorlessa added a commit to heitorlessa/aws-sam-cli that referenced this issue Jun 19, 2018
fix: emphasize OSes and adds link to Docker file sharing opts

fix merge conflict - formatting commit

fix: adds Path adjustment procedure along with installation

fix merge conflict aws#4

fix: Add explicit command on update preferred shell configuration

fix merge conflict aws#5

fix: Emphasis on ``sam init`` under Usage

fix: Formatting issues under Package and Deploy section

fix: removes get started section as it's outdated

fix merge conflict aws#6

fix merge conflict aws#7

fix: RST doesn't support bold+code, falling back to code only

improv: Brings sam init to first command in Usage for instant gratification

fix: adds a note on Path for OSX users
moelasmar referenced this issue in moelasmar/aws-sam-cli Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants