简体   繁体   English

Lambda函数可在AWS控制台中使用,但不适用于Cloud9

[英]Lambda function works in AWS console but not on Cloud9

I'm making an Alexa skill and need to include the rest module for nodejs so I've changed from the AWS Console to cloud 9. In the console, everything works fine but when I create the project with the exact same setup (Not including the new module) I get following syntax error: 我正在掌握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)"
    ]
}

It doesn't tell me in which line the syntax error occurs and in the console with the exact same input it works fine. 它不会告诉我语法错误发生在哪一行,并且在具有完全相同的输入的控制台中也可以正常工作。

I've already tried reducing my code to only include a launchRequestHandler in my index.js as such: 我已经尝试过将代码减少为仅在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();

I've also tried changing the package.json to what it was in the console and have created it new with npm init but neither makes a difference. 我还尝试将package.json更改为控制台中的内容,并使用npm init对其进行了新创建,但两者均没有任何区别。 What am I doing wrong? 我究竟做错了什么? Is there something missing? 缺少什么吗?

My template.yml looks like this: 我的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}:*/*/*/*'

I found the error, apparently, the cloud9 compiler is more sensitive than the AWS console. 我发现了这个错误,显然,cloud9编译器比AWS控制台更敏感。 The , behind LaunchRequestHandler in the exports.handler was interpreted as an error. ,背后LaunchRequestHandler在exports.handler被解释为错误。 After removing this it works. 删除后,它可以工作。 Hope this will help others that come across a problem like this. 希望这将对遇到类似问题的其他人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以使用AWS Lambda Web控制台中的Cloud9代码编辑器访问Customer Profile API? 如果是这样,怎么办? - Is accessing the Customer Profile API possible using the Cloud9 code editor in the AWS Lambda web console? If so, how? AWS Cloud9 Lambda安装node.js模块 - AWS Cloud9 Lambda installing node.js modules 将 pathParameters 正确发送到 AWS Lambda NodeJS function - 从 AWS 控制台调用有效,但不能从浏览器/邮递员调用 - Sending pathParameters correctly to AWS Lambda NodeJS function - calling from AWS console works but not from browser/Postman 在控制台上进行测试时,AWS Lambda Function可以工作,但在CloudWatch事件触发它时则无法工作 - AWS Lambda Function works when tested on console, but not when CloudWatch event triggers it Cloud9的终端运行缓慢 - Cloud9`s terminal works slowly MongoDB 使用 AWS Cloud9 失败 - MongoDB failure using AWS Cloud9 AWS控制台中的AWS Node.js Lambda POST函数 - AWS Node.js Lambda POST Function in AWS Console Cloud9不会在Node.js Lambda中公开bash_profile导出 - Cloud9 does not expose bash_profile exports in nodejs lambda 尝试创建一个可公开访问的 AWS Cloud9 URL - Trying to make a publicly accessible AWS Cloud9 URL AWS Cloud9`process.versions.node`未定义? - AWS Cloud9 `process.versions.node` undefined?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM