alexa-samples / skill-sample-nodejs-audio-player

An Alexa Skill Sample showing how to play long form audio in 3P-skills
Other
470 stars 319 forks source link

lambda function entry point is not accesible #103

Closed ttruga closed 6 years ago

ttruga commented 6 years ago

Im using the single-stream folder with the sdkv2 branch, followed all the instructions in order to configure all permissions. Tried testing the skill from both the developer console and also executing

ask simulate -l en-US -t 'play my radio'

I always get on cloud watch the following error:

Unable to import module 'dist/index': Error
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18) 

I also changed the handler as mentioned on the README file using the following command:

aws lambda update-function-configuration --function-name ask-custom-myradio-default --handler dist/index.handler --runtime nodejs8.10

I also tried executing the lambda function directly from the lambda dashboard using the pre populated example events and I always get the same response.. it can't find the entry point to the lambda function.

Sadly because the function is too big so is impossible to edit it inline in order to detect which is the actual entry point of the function.

it is always:

{
  "errorMessage": "Cannot find module '/var/task/dist/index'",
  "errorType": "Error",
  "stackTrace": []
}

START RequestId: 27c2d7b9-58b7-11e8-b406-ff652b1c6c13 Version: $LATEST
Unable to import module 'dist/index': Error
    at require (internal/module.js:11:18)
END RequestId: 27c2d7b9-58b7-11e8-b406-ff652b1c6c13
REPORT RequestId: 27c2d7b9-58b7-11e8-b406-ff652b1c6c13  Duration: 0.55 ms   Billed Duration: 100 ms     Memory Size: 128 MB Max Memory Used: 20 MB  

Anybody knows why is this happening or perhaps which one is the actual entry point for the function? or perhaps there is a way of not using TS so it can behave like a typical ES6 JS function?

benappware commented 6 years ago

I'm also getting the exact same CloudWatch error:

Unable to import module 'dist/index': Error
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)

@ttruga did you find a solution?

benappware commented 6 years ago

@sebsto I don't suppose you could help us out here could you please?

benappware commented 6 years ago

By exporting my Lambda function (Actions > Export function) I can see that there is no dist directory in there:

.
├── node_modules
│   ├── @types
│   │   ├── chai
│   │   ├── mocha
│   │   └── node
│   ├── ansi-styles
│   ├── arrify
│   ├── ask-sdk
│   │   └── dist
│   │       └── skill
│   │           └── factory
│   ├── ask-sdk-core
│   │   └── dist
│   │       ├── attributes
│   │       │   └── persistence
│   │       ├── dispatcher
│   │       │   ├── error
│   │       │   └── request
│   │       │       ├── handler
│   │       │       ├── interceptor
│   │       │       └── mapper
│   │       ├── response
│   │       ├── service
│   │       ├── skill
│   │       │   └── factory
│   │       └── util
│   ├── ask-sdk-dynamodb-persistence-adapter
│   │   └── dist
│   │       ├── attributes
│   │       │   └── persistence
│   │       └── utils
│   ├── ask-sdk-model
│   ├── assertion-error
│   ├── aws-sdk
│   │   ├── apis
│   │   ├── clients
│   │   ├── dist
│   │   ├── dist-tools
│   │   ├── lib
│   │   │   ├── cloudfront
│   │   │   ├── credentials
│   │   │   ├── dynamodb
│   │   │   ├── http
│   │   │   ├── json
│   │   │   ├── model
│   │   │   ├── polly
│   │   │   ├── protocol
│   │   │   ├── query
│   │   │   ├── rds
│   │   │   ├── react-native
│   │   │   ├── s3
│   │   │   ├── services
│   │   │   ├── signers
│   │   │   └── xml
│   │   └── scripts
│   │       ├── changelog
│   │       ├── lib
│   │       └── region-checker
│   ├── balanced-match
│   ├── base64-js
│   │   └── test
│   ├── brace-expansion
│   ├── browser-stdout
│   ├── buffer
│   │   ├── bin
│   │   └── test
│   │       └── node
│   ├── buffer-from
│   ├── chai
│   │   └── lib
│   │       └── chai
│   │           ├── core
│   │           ├── interface
│   │           └── utils
│   ├── chalk
│   │   └── types
│   ├── check-error
│   ├── color-convert
│   ├── color-name
│   ├── commander
│   │   └── typings
│   ├── concat-map
│   │   ├── example
│   │   └── test
│   ├── debug
│   │   └── src
│   ├── deep-eql
│   ├── diff
│   │   ├── dist
│   │   └── lib
│   │       ├── convert
│   │       ├── diff
│   │       ├── patch
│   │       └── util
│   ├── escape-string-regexp
│   ├── events
│   │   └── tests
│   ├── fs.realpath
│   ├── get-func-name
│   ├── glob
│   ├── growl
│   │   └── lib
│   ├── has-flag
│   ├── he
│   │   ├── bin
│   │   └── man
│   ├── ieee754
│   │   └── test
│   ├── inflight
│   ├── inherits
│   ├── isarray
│   ├── jmespath
│   │   ├── artifacts
│   │   └── test
│   │       └── compliance
│   ├── lodash
│   │   └── fp
│   ├── make-error
│   │   └── dist
│   ├── minimatch
│   ├── minimist
│   │   ├── example
│   │   └── test
│   ├── mkdirp
│   │   ├── bin
│   │   ├── examples
│   │   └── test
│   ├── mocha
│   │   ├── bin
│   │   └── lib
│   │       ├── browser
│   │       ├── interfaces
│   │       └── reporters
│   ├── ms
│   ├── once
│   ├── path-is-absolute
│   ├── pathval
│   ├── punycode
│   ├── querystring
│   │   └── test
│   ├── sax
│   │   └── lib
│   ├── source-map
│   │   ├── dist
│   │   └── lib
│   ├── source-map-support
│   ├── supports-color
│   ├── ts-node
│   │   ├── dist
│   │   ├── node_modules
│   │   │   └── minimist
│   │   │       ├── example
│   │   │       └── test
│   │   └── register
│   ├── type-detect
│   ├── typescript
│   │   ├── bin
│   │   └── lib
│   │       ├── cs
│   │       ├── de
│   │       ├── es
│   │       ├── fr
│   │       ├── it
│   │       ├── ja
│   │       ├── ko
│   │       ├── pl
│   │       ├── pt-br
│   │       ├── ru
│   │       ├── tr
│   │       ├── zh-cn
│   │       └── zh-tw
│   ├── url
│   ├── uuid
│   │   ├── bin
│   │   └── lib
│   ├── wrappy
│   ├── xml2js
│   │   └── lib
│   ├── xmlbuilder
│   │   └── lib
│   └── yn
├── src
│   └── utils
└── test
    ├── request
    └── utils

So is the question, in my case at least, what failed to build the dist JavaScript?

benappware commented 6 years ago

OK, so the reason is that because this is a TypeScript project it first needs compiling into JavaScript.

So the missing command just before "ask deploy" is: (cd lambda && tsc)

Then you get a single-stream/lambda/dist/ directory (due to the settings in single-stream/lambda/ts-config.json):

$ ls -al lambda/dist/
total 168
drwxr-xr-x  21 xxx yyy    672  8 Jun 15:37 .
drwxr-xr-x   8 xxx yyy    256  8 Jun 15:37 ..
-rw-r--r--   1 xxx yyy   1502  8 Jun 15:38 AudioAssets.js
-rw-r--r--   1 xxx yyy    938  8 Jun 15:38 AudioAssets.js.map
-rw-r--r--   1 xxx yyy   3599  8 Jun 15:38 AudioController.js
-rw-r--r--   1 xxx yyy   1965  8 Jun 15:38 AudioController.js.map
-rw-r--r--   1 xxx yyy   3541  8 Jun 15:38 AudioHandlers.js
-rw-r--r--   1 xxx yyy   1389  8 Jun 15:38 AudioHandlers.js.map
-rw-r--r--   1 xxx yyy    596  8 Jun 15:38 CanPlayAudioCheck.js
-rw-r--r--   1 xxx yyy    502  8 Jun 15:38 CanPlayAudioCheck.js.map
-rw-r--r--   1 xxx yyy    748  8 Jun 15:38 Constants.js
-rw-r--r--   1 xxx yyy    376  8 Jun 15:38 Constants.js.map
-rw-r--r--   1 xxx yyy  11413  8 Jun 15:38 IntentHandlers.js
-rw-r--r--   1 xxx yyy   5732  8 Jun 15:38 IntentHandlers.js.map
-rw-r--r--   1 xxx yyy   1315  8 Jun 15:38 SkillEventHandler.js
-rw-r--r--   1 xxx yyy    444  8 Jun 15:38 SkillEventHandler.js.map
-rw-r--r--   1 xxx yyy   1711  8 Jun 15:38 Strings.js
-rw-r--r--   1 xxx yyy    802  8 Jun 15:38 Strings.js.map
-rw-r--r--   1 xxx yyy   2788  8 Jun 15:38 index.js
-rw-r--r--   1 xxx yyy   1460  8 Jun 15:38 index.js.map
drwxr-xr-x   8 xxx yyy    256  8 Jun 15:37 utils

And that needs running every time you change a .ts file, unless you have a watcher or such like running I guess.

sebsto commented 6 years ago

Looks like you nailed it down. I forgot to add Typescript compilation instructions. I will update the readme over the weekend. Thanks for helping !

--Seb

Sent from a smartphone. Please, accept apologies for brevity and typos.

On 8 Jun 2018, at 16:43, benappware notifications@github.com wrote:

OK, so the reason is that because this is a TypeScript project it first needs compiling into JavaScript.

So the missing command just before "ask deploy" is: (cd lambda && tsc)

Then you get a single-stream/lambda/dist/ directory (due to the settings in single-stream/lambda/ts-config.json):

$ ls -al lambda/dist/ total 168 drwxr-xr-x 21 xxx yyy 672 8 Jun 15:37 . drwxr-xr-x 8 xxx yyy 256 8 Jun 15:37 .. -rw-r--r-- 1 xxx yyy 1502 8 Jun 15:38 AudioAssets.js -rw-r--r-- 1 xxx yyy 938 8 Jun 15:38 AudioAssets.js.map -rw-r--r-- 1 xxx yyy 3599 8 Jun 15:38 AudioController.js -rw-r--r-- 1 xxx yyy 1965 8 Jun 15:38 AudioController.js.map -rw-r--r-- 1 xxx yyy 3541 8 Jun 15:38 AudioHandlers.js -rw-r--r-- 1 xxx yyy 1389 8 Jun 15:38 AudioHandlers.js.map -rw-r--r-- 1 xxx yyy 596 8 Jun 15:38 CanPlayAudioCheck.js -rw-r--r-- 1 xxx yyy 502 8 Jun 15:38 CanPlayAudioCheck.js.map -rw-r--r-- 1 xxx yyy 748 8 Jun 15:38 Constants.js -rw-r--r-- 1 xxx yyy 376 8 Jun 15:38 Constants.js.map -rw-r--r-- 1 xxx yyy 11413 8 Jun 15:38 IntentHandlers.js -rw-r--r-- 1 xxx yyy 5732 8 Jun 15:38 IntentHandlers.js.map -rw-r--r-- 1 xxx yyy 1315 8 Jun 15:38 SkillEventHandler.js -rw-r--r-- 1 xxx yyy 444 8 Jun 15:38 SkillEventHandler.js.map -rw-r--r-- 1 xxx yyy 1711 8 Jun 15:38 Strings.js -rw-r--r-- 1 xxx yyy 802 8 Jun 15:38 Strings.js.map -rw-r--r-- 1 xxx yyy 2788 8 Jun 15:38 index.js -rw-r--r-- 1 xxx yyy 1460 8 Jun 15:38 index.js.map drwxr-xr-x 8 xxx yyy 256 8 Jun 15:37 utils And that needs running every time you change a .ts file, unless you have a watcher or such like running I guess.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

sebsto commented 6 years ago

Doc is fixed, apologies for the churn. https://github.com/alexa/skill-sample-nodejs-audio-player/commit/b055da71fdcd535491fb50fcffeb5539513ea78d