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

Serverless-sam exports template with invalid function names and incomplete template #35

Open
apsnaidu opened this issue Jul 18, 2019 · 2 comments

Comments

@apsnaidu
Copy link

apsnaidu commented Jul 18, 2019

Hi,
When using serverless-sam to generate SAM template from serverless template which has multiple templates included I'm getting an invalid template with incorrect function names and incomplete template with no handlers.

Here is the log:

serverless sam export --output ./sam-template-generated.yml --profile admin --stage=sit1 --region=ap-southeast-2
Serverless: Working folder: /Users/apsn/Documents/Work/node_modules/serverless-sam
Serverless: Validate
Serverless: Preparing original CloudFormation template
Serverless: Packaging functions
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Export:
Serverless: Exporting resources
Serverless: Exporting outputs
Serverless: Exporting parameters
Serverless: Exporting conditions
Serverless: Exporting functions
Serverless: Exporting function: 0 as 0
Serverless: Exporting function: 1 as 1
Serverless: Exporting function: 2 as 2
Serverless: Exporting function: 3 as 3
Serverless: SAM template written to: /Users/apsn/Documents/Work/sam-template-generated.yml

Here is the sample generated template.

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: 'SAM template for Serverless framework service: '
Resources:
  '0':
    Type: 'AWS::Serverless::Function'
    Properties:
      Runtime: nodejs8.10
      CodeUri: >-
        /Users/apsn/Documents/Work/.serverless/operate-media.zip
      MemorySize: 128
      Timeout: 3
      Environment:
        Variables:
          DYNAMODB_TABLE_NAME: metadata
          AWS_ENVIRONMENT: sit1
          ELASTIC_SEARCH_LOG_LEVEL: trace
          ELASTIC_SEARCH_PORT: 443
          ELASTIC_SEARCH_PROTOCOL: https
          ELASTIC_SEARCH_HOST: >-
            vpc-metadata-sit1-bvtzr43p6vacju.ap-southeast-2.es.amazonaws.com

The function names are exported as 0, 1, 2, 3 etc and there are no handlers generated!

Attached the serverless and generated sam templates.
files.zip

Cheers

@apsnaidu
Copy link
Author

Looks like the issue is happening only when the serverless.yml file contains references to files containing functions definitions under functions section. When the functions are directly defined under functions section of serverless.yml the plugin works fine.

@pjbjr
Copy link

pjbjr commented Jul 24, 2019

+1

Same thing happens to me. Also happens for my env.yml file:

provider:
  environment: ${file(env.yml):${self:provider.stage}}

functions:
  - ${file(src/services/reports/functions.yml)}

resources:
  - ${file(resources/cognito-app-identitypool.yml)}
  - ${file(resources/cognito-app-userpool.yml)}
  - ${file(resources/s3-photo-bucket.yml)}
  - ${file(resources/sqs-send-queue.yml)}

turn to:

      Environment:
        Variables:
          '0': $
          '1': '{'
          '2': f
          '3': i
          '4': l
          '5': e
          '6': (
          '7': e
          '8': 'n'
          '9': v
          '10': .
          '11': 'y'
          '12': m
          '13': l
          '14': )
          '15': ':'
          '16': $
          '17': '{'
          '18': s
          '19': e
          '20': l
          '21': f
          '22': ':'
          '23': p
          '24': r
          '25': o
          '26': v
          '27': i
          '28': d
          '29': e
          '30': r
          '31': .
          '32': s
          '33': t
          '34': a
          '35': g
          '36': e
          '37': '}'
          '38': '}'

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

2 participants