1

我正在制作 Alexa 技能,需要包含 nodejs 的其余模块,因此我已从 AWS 控制台更改为云 9。在控制台中,一切正常,但是当我使用完全相同的设置创建项目时(不包括新模块)我收到以下语法错误:

{
    "errorMessage": "Unexpected token )",
    "errorType": "SyntaxError",
    "stackTrace": [
        "    ^",
        "SyntaxError: Unexpected token )",
        "createScript (vm.js:56:10)",
        "Object.runInThisContext (vm.js:97:10)",
        "Module._compile (module.js:542:28)",
        "Object.Module._extensions..js (module.js:579:10)",
        "Module.load (module.js:487:32)",
        "tryModuleLoad (module.js:446:12)",
        "Function.Module._load (module.js:438:3)",
        "Module.require (module.js:497:17)",
        "require (internal/module.js:20:19)"
    ]
}

它没有告诉我语法错误发生在哪一行,并且在控制台中使用完全相同的输入它可以正常工作。

我已经尝试减少我的代码,只在我的 index.js 中包含一个 launchRequestHandler :

const LaunchRequestHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
    },
    handle(handlerInput) {
        var reprompt = '';
        const speakOutput = 'Start';
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(reprompt)
            .withShouldEndSession(false)
            .getResponse();
    },
};
const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
    .addRequestHandlers(
        LaunchRequestHandler,
    )
    .addErrorHandlers(ErrorHandler)
    .lambda();

我还尝试将 package.json 更改为控制台中的内容,并使用 npm init 创建了它,但两者都没有区别。我究竟做错了什么?有什么遗漏吗?

我的 template.yml 看起来像这样:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification template describing your function.
Resources:
  protocollFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: protocollFunction/index.handler
      Runtime: nodejs6.10
      Description: ''
      MemorySize: 128
      Timeout: 15
      Events:
        LambdaMicroservice:
          Type: Api
          Properties:
            Path: /
            Method: ANY
  protocollFunctionPermission:
    Type: 'AWS::Lambda::Permission'
    Properties:
      Action: 'lambda:InvokeFunction'
      FunctionName:
        'Fn::GetAtt':
          - protocollFunction
          - Arn
      Principal: apigateway.amazonaws.com
      SourceArn:
        'Fn::Sub': 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:*/*/*/*'
4

1 回答 1

0

我发现了错误,显然,cloud9编译器比AWS控制台更敏感。export.handler,后面的 LaunchRequestHandler 被解释为错误。删除它后它可以工作。希望这会帮助遇到类似问题的其他人。

于 2019-04-15T10:49:41.473 回答