[英]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.