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 Export Error: Cannot read property 'charAt' of undefined #32

Open
marianina8 opened this issue Dec 11, 2018 · 2 comments

Comments

@marianina8
Copy link

When I run the following command:

serverless sam export --output ./sam-template.yml

I get the following error:

      Type Error ---------------------------------------------

    Cannot read property 'charAt' of undefined

        For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

    Stack Trace --------------------------------------------

    TypeError: Cannot read property 'charAt' of undefined
        at StreamEventConverter.convertEvent (/Users/marian/goop/src/github.com/goop/service-wms/node_modules/serverless-sam/lib/events/StreamEventConverter.js:29:33)
        at Object.keys.forEach (/Users/marian/goop/src/github.com/goop/service-wms/node_modules/serverless-sam/lib/FunctionConverter.js:101:49)
        at Array.forEach (<anonymous>)
        at serverlessFunction.events.forEach (/Users/marian/goop/src/github.com/goop/service-wms/node_modules/serverless-sam/lib/FunctionConverter.js:95:33)
        at Array.forEach (<anonymous>)
        at FunctionConverter.serverlessFunctionToSam (/Users/marian/goop/src/github.com/goop/service-wms/node_modules/serverless-sam/lib/FunctionConverter.js:89:33)
        at allFunctions.forEach (/Users/marian/goop/src/github.com/goop/service-wms/node_modules/serverless-sam/lib/SamGenerator.js:119:32)
        at Array.forEach (<anonymous>)
        at SamGenerator.readFunctions (/Users/marian/goop/src/github.com/goop/service-wms/node_modules/serverless-sam/lib/SamGenerator.js:109:20)
        at SamGenerator.generate (/Users/marian/goop/src/github.com/goop/service-wms/node_modules/serverless-sam/lib/SamGenerator.js:58:10)
        at BbPromise (/Users/marian/goop/src/github.com/goop/service-wms/node_modules/serverless-sam/index.js:206:46)
        at SamPlugin.exportSam (/Users/marian/goop/src/github.com/goop/service-wms/node_modules/serverless-sam/index.js:203:12)
    From previous event:
        at PluginManager.invoke (/Users/marian/.nvm/versions/node/v10.9.0/lib/node_modules/serverless/lib/classes/PluginManager.js:390:22)
        at PluginManager.run (/Users/marian/.nvm/versions/node/v10.9.0/lib/node_modules/serverless/lib/classes/PluginManager.js:421:17)
        at variables.populateService.then.then (/Users/marian/.nvm/versions/node/v10.9.0/lib/node_modules/serverless/lib/Serverless.js:157:33)
        at runCallback (timers.js:693:18)
        at tryOnImmediate (timers.js:664:5)
        at processImmediate (timers.js:646:5)
        at process.topLevelDomainCallback (domain.js:121:23)
    From previous event:
        at Serverless.run (/Users/marian/.nvm/versions/node/v10.9.0/lib/node_modules/serverless/lib/Serverless.js:144:8)
        at serverless.init.then (/Users/marian/.nvm/versions/node/v10.9.0/lib/node_modules/serverless/bin/serverless:43:50)

I'm using serverless v.1.30.3 and node v10.9 I'm not quite sure where to start with this error message as searching online has not yielded any similar issues/fixes. Any pointers would be greatly appreciated!

@marianina8
Copy link
Author

Just a follow up, I was able to get it to work by changing my serverless.yml file's declaration of a stream from:

    events:
      - stream: ${env:arn}

to:

    events:
      - stream:
          arn: ${env:arn}
          type: dynamodb

(* arn is stored as an environment variable). For some reason I didn't see any documentation that suggests that this is how streams should be defined. To your knowledge is this the correct way to define a stream in serverless.yml? It seemed to work deploying to AWS Lambda even the original way. Thanks!

@xevenheaven
Copy link

Just to chime in, I was facing a similar problem:

  Type Error ---------------------------------------------

  Cannot read property 'charAt' of undefined

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           10.11.0
     Serverless Version:     1.36.3

My serverless.yml was:

    events:
      - stream:
          arn: "arn:aws:kinesis:${region}:${account}:stream/${name}"
          batchSize: 100
          startingPosition: LATEST
          enabled: true

Following @marianina8's method, I added the type field:

    events:
      - stream:
          arn: "arn:aws:kinesis:${region}:${account}:stream/${name}"
          batchSize: 100
          startingPosition: LATEST
          enabled: true
          type: kinesis

And that solved the problem.

ℹ️Might wanna add in the docs that the type field is required.

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